Having issue in sending Graphql request to localhost

I am having error “ERROR 4495 — [-8080-exec-1395] g.k.servlet.AbstractGraphQLHttpServlet : Error executing GraphQL request!” while i am running a robot framework script. Here is the simple script for API test to send a request and print the content of the response:

*** Settings ***
Library RequestsLibrary
Library Collections
Library OperatingSystem

*** Variables ***
${API_Base_Endpoint} http://localhost:8080
${Token}= “Bearer ADMIN”
${Body}= query": " mutation{\n create (realm: “test”, owner: “hero”)\n {\n id\n token\n realm\n }

*** Test Cases ***
TC_001_Status_Code
create session API_Testing ${API_Base_Endpoint}
${headers} create dictionary Authorization=${Token} Content-Type=application/json
${response}= post request API_Testing /graphql data=${Body}
headers=${headers}
log to console ${response.status_code}
log to console ${response.content}
log to console ${response.headers}

Please let me know what should i do to resolve the issue.

I would say the query / body is incorrect. Is what you posted the exact same as your source code? Note that in Robot Framework syntax, you don’t need to quote strings. In the ${Body} I see some quotes that probably do not belong there. Also, the header indicates that you’re sending json, but you post ‘data’, not ‘json’…and the ${Body} is not a dictionary / json string.

I am trying to send graphql query to the server. Server cannot read this query. However, when I send this using POSTMAN, it returns me a response. Should I send json or graphql query. ${Body} is just a variable where i am trying to store the query. Please let me know if I am wrong or what should do?

${Body} mutation { create(realm: “test”, owner: “hero”) { id token realm } }

If you have a working JSON body that you can send using Postman or similar tool, you should create a dictionary in Robot Framework with the same content and send that. You might be able to check the exact http request being send in Postman. What you send from RF should be the same.

It only accepts POST requests with a query string in the request body. With this type of setup, we are seeing problems of caching GraphQL requests with service.

prepaidcardstatus

Hi There,

I also facing 400 Bad Request in response while sending request using Graphql.
Below is our code:

Blockquote*** Settings ***
Library SeleniumLibrary
Library RequestsLibrary
Library JSONLibrary
Library Collections
Library OperatingSystem

*** Variables ***
*** Test Cases ***
Do a POST Request and validate the response code, response body, and response headers

Create Session      mysession   http://127.0.0.1:8000
${file_name}=  Get Binary File   ${CURDIR}\\test.json
&{body}=    create dictionary  query= query { places { name } }
&{header}=  create dictionary   Content-Type=application/json
log to console  ${file_name}
${response}=  POST On Session   mysession   /  data=${file_name}   headers=${header}
log to console  ${response}
Status Should Be  200  ${response}

Data file: test.json
query {
places {
name
}
}

The error occurred:
HTTPError: 400 Client Error: Bad Request for url: http://127.0.0.1:8000/
Do you guys have any idea on it please let me know.
Many thanks

You should inspect the body of the 400 response, that may provide a hint as to what exactly is wrong with the request you’ve constructed. If there’s no more information in the response, talk to your developers since you may have to look at backend logs to figure out what’s wrong.