1

I am trying to make a simple rest call to graphql endpoint but getting a 400 error from the server. Have been struck in this for a while.

Payload

query = "{\n" +
            "   lookup(dob: \"01/01\", preSsn : { ssn: \"{actualvalue}\"})\n" +
            "   {\n" +
            "       items {\n" +
            "           individualCrdNumber\n" +
            "           firstName\n" +
            "           middleName\n" +
            "           lastName\n" +
            "           suffixName\n" +
            "       }\n" +
            "   }\n" +
            "}";

Error message: {"statusCode":400,"statusDescription":"Bad Request","message":"","messageDetails":[]}

Code:

    HttpClient client = getHttpsClient();
    HttpPost httpPost = new HttpPost(URL);
    StringEntity input = new StringEntity(query, ContentType.APPLICATION_JSON);
    httpPost.setEntity(input);
    final String plainCred = "userName"+":"+"password";
    final String base64Creds = Base64.getEncoder().encodeToString(plainCred.getBytes());


    httpPost.addHeader("Authorization", "Basic " + base64Creds);
    httpPost.addHeader("Content-Type", "application/json");
    httpPost.addHeader("Accept", "application/json");
    httpPost.addHeader("Cache-Control", "no-cache");

    HttpResponse response = client.execute(httpPost);

1 Answer 1

0

The query needs to be wrapped in an object assigned to a query element. This object can also contain a variables element for value binding:

{
  "query": "...",
  "operationName": "...",
  "variables": { "myVariable": "someValue", ... }
}

See the spec regarding GraphQL over HTTP using POST.

Try

String query = 
        "{" +
          "\"query\" : \"query {"+ 
            "lookup(dob: \"01/01\", preSsn : { ssn: \"{actualvalue}\"})" +
            "{items{individualCrdNumber firstName middleName lastName suffixName}}" +
          "}" +
        "}";
Sign up to request clarification or add additional context in comments.

1 Comment

I tried the option you suggested, and it worked. thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.