Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

GraphQL Query Fails When Run as JSON

Solved

GraphQL Query Fails When Run as JSON

gcb0323
Visitor
3 1 0

This query runs fine in the GraphiQL editor but when I run it as a JSON request I get a 400 response. 

 

The json provided is not formatted correctly

 

 

If I remove the pagination request "after: ..." it runs as expected.

 

Is there something about my formatting of the "after" request that isn't JSON friendly?

 

 

{
  "query": "query{ orders(first: 3, after: "eyJsYXN0X2lkIjo0MzU5OTgzMjY3ODkzLCJsYXN0X3ZhbHVlIjoiMjAyMi0wNS0yMyAxMDozNzoyMy4wMDAwMDAifQ==") { edges { cursor node { id name legacyResourceId email createdAt processedAt totalPriceSet { shopMoney { amount currencyCode } } totalDiscountsSet { shopMoney { amount currencyCode } } totalRefundedSet { shopMoney { amount currencyCode } } subtotalLineItemsQuantity test } } }}"
}

 

 

Accepted Solution (1)

gcb0323
Visitor
3 1 0

This is an accepted solution.

Solved my own question. I needed to escape the quotes within my query.

 

{
  "query": "query{ orders(first: 3, after: \"eyJsYXN0X2lkIjo0MzU5OTgzMjY3ODkzLCJsYXN0X3ZhbHVlIjoiMjAyMi0wNS0yMyAxMDozNzoyMy4wMDAwMDAifQ==\") { edges { cursor node { id name legacyResourceId email createdAt processedAt totalPriceSet { shopMoney { amount currencyCode } } totalDiscountsSet { shopMoney { amount currencyCode } } totalRefundedSet { shopMoney { amount currencyCode } } subtotalLineItemsQuantity test } } }}"
}

View solution in original post

Reply 1 (1)

gcb0323
Visitor
3 1 0

This is an accepted solution.

Solved my own question. I needed to escape the quotes within my query.

 

{
  "query": "query{ orders(first: 3, after: \"eyJsYXN0X2lkIjo0MzU5OTgzMjY3ODkzLCJsYXN0X3ZhbHVlIjoiMjAyMi0wNS0yMyAxMDozNzoyMy4wMDAwMDAifQ==\") { edges { cursor node { id name legacyResourceId email createdAt processedAt totalPriceSet { shopMoney { amount currencyCode } } totalDiscountsSet { shopMoney { amount currencyCode } } totalRefundedSet { shopMoney { amount currencyCode } } subtotalLineItemsQuantity test } } }}"
}