Having trouble with Query Via HTTP

I am having trouble with a query, when I run this as a curl it works just fine, however when trying to implement this in java in the response body I simply get"

Invalid parameter(s) specified: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
When I try to access the body of the response ( I am using OKTTP3)

Here is how the query is structured. I use Java block quotes and then pass it as ‘query into’

            String query = """
                        "filter": { "serverID": "ABC123" },
                        "projection": { "messages": 1 }
body = RequestBody.create(query, mediaType);

Then that is passed into

// OKHTTP Stuff

.method("POST", body)


Any help would be appreciated.

Hi Nathaniel - did you try pasting the code snippet from Postman/our snippet generator into your code and confirm to see if that works? My guess is that it is likely a character escaping/formatting issue.

If the following works, you may have to do something to cast the JSON to a string so you can configure the body in a readable format like this post suggests


OkHttpClient client = new OkHttpClient().newBuilder()
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n    \"collection\":\"Jars\",\n    \"database\":\"TikoJarTest\",\n    \"dataSource\":\"PositivityJar\",\n    \"filter\": { \"serverID\": \"ABC123\" },\n    \"projection\": { \"messages\": 1 }\n\n}\n\n");
Request request = new Request.Builder()
  .method("POST", body)
  .addHeader("Content-Type", "application/json")
  .addHeader("Access-Control-Request-Headers", "*")
  .addHeader("api-key", "<API KEY>")
  .addHeader("Accept", "application/json")
Response response = client.newCall(request).execute();

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.