How to resolve the curl data-raw JSON, Unexpected character error?

304    Asked by ElizabethJordan in Salesforce , Asked on May 22, 2023

 I need to send JSON format through the CURL command but I am getting an error.

curl --request POST "https://app.io/api/graphql?accountId=Xzg" --header "x-api-key: WHpnV=" --header "Content-Type: application/json" --data-raw "{applications(limit: 2) {nodes {name}}}"
So the problematic part is data-raw, although I have checked it online it's Valid JSON.
--data-raw "{applications(limit: 2) {nodes {name}}}"
Response:
{"metaData":null,"resource":null,"responseMessages":[{"code":"DEFAULT_ERROR_CODE","level":"ERROR", "message":"Unable to process JSON Unexpected character ('a' (code 97)): was expecting double-quote to start field name","exception":null,"failureTypes":[]}]}

I tried different ways how I could change this request data but without success. Can someone please assist me how I should change this query which was definitely generated as the proper one from some app.

Answered by Dipesh Bhardwaj
To resolve the curl data-raw JSON, Unexpected character error, I believe your attempting to send the query via JSON (https://www.contentful.com/developers/docs/references/graphql/#/introduction/http-methods) and so you need to wrap it as a query?
--data-raw '{"query": "{applications(limit: 2) {nodes {name}}}" }'


Your Answer

Interviews

Parent Categories