Using GraphQL in Data Action

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

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

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

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