Felice_Vittoria | 2021-03-23 03:13:59 UTC | #1
Hello all,
Has anyone been able to use GraphQL syntax in a data action? I am attempting to do so but get an error.
This is the error: 7. Resolve request body template: Processing the Request Body Template resulted in invalid JSON.
- Unexpected character ('i' (code 105)): was expecting comma to separate Object entries at [Source: (String)"{ "query": "mutation CreateCustomer(VPCIMap:[providerContextPrefix: input ], map: {orgid=268a1671-cd4a-4f36-9442-5d2e1a023f01, item1=9qtkrgj3mkfq2mrv, integrationid=788ec842-49b6-4bb8-ad45-bc681151d52d, rawrequest={"item1":"9qtkrgj3mkfq2mrv","item2":"76d863090cd7bfd470627426af305ad5"}, item2=76d863090cd7bfd470627426af305ad5} ]: CreateCustomerInput!) { createCustomer(input: VPCIMap:[providerContextPrefix: input ], map: {orgid=268a1671-cd4a-4f36-9442-5d2e1a023f01, item1=9qtkrgj3mkfq2mrv, integr"[truncated 468 chars]; line: 2, column: 217]
This is the request body template: { "query": "mutation CreateCustomer($input: CreateCustomerInput!) { createCustomer(input: $input) { clientMutationId customer { id legacyId company firstName lastName } } }", "variables": { "input": { "clientMutationId": "FeliceTest12345", "customer": { "company": "FeliceTest-12345", "firstName": "Felice", "lastName": "Test" } } } }
In the contracts I configured item1 and item2 as strings.
Thank you, Felice
Jason_Mathison | 2021-03-24 02:23:03 UTC | #2
Hi Felice,
I found a couple of things that were probably tripping you up.
The first issue is that the request body template you provided isn't valid JSON. When I get JSON errors I use https://jsonlint.com/ to figure out what is going on. In this case the issue is the value of "query" includes actual tabs and newline characters , instead of \n or \t characters.
Removing all tabs and newlines produced valid JSON: "query": "mutation CreateCustomer($input: CreateCustomerInput!) { createCustomer(input: $input) { clientMutationId customer { id legacyId company firstName lastName}}}",
At this point it still failed due to the velocity template processing. Velocity interprets things like $input as variables that should be replaced. Adding a \ in front of the $s that you want to send to your endpoint will get velocity to ignore the $ and pass it along to your endpoint.
--Jason
Felice_Vittoria | 2021-03-24 02:24:28 UTC | #3
Felice_Vittoria, post:1, topic:10362
"variables": { "input": { "clientMutationId": "FeliceTest12345", "customer": { "company": "FeliceTest-12345", "firstName": "Felice", "lastName": "Test" } } }
Jason,
Thank you so much! That resolved the issue. I also added the link you noted as a bookmark so that I can use it in case I get JSON errors.
Felice
system | 2021-04-24 02:26:28 UTC | #4
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
This post was migrated from the old Developer Forum.
ref: 10362