Sending GraphQL mutations and variables on URLConnection

Hello,

I am trying to send GraphQL mutations and variables on a URLConnection with a Json format but
keep on getting “Bad Request” responses.

An example looks like this:
sQuery = “mutation fulfillmentCreateV2($fulfillment: FulfillmentV2Input!){”
sQuery = sQuery + “fulfillmentCreateV2(fulfillment: $fulfillment){fulfillment{id}userErrors{”
sQuery = sQuery + “field message}}}”

sVars is:
{“variables”:“{“fulfillment”: {“lineItemsByFulfillmentOrder”:[{“fulfillmentOrderId”: “gid://shopify/FulfillmentOrder/nnnn”,“fulfillmentOrderLineItems”: {“id”: “gid://shopify/FulfillmentOrderLineItem/mmmm”,“quantity”: 1}}],“notifyCustomer”: true,“originAddress”: {“address1”: 123 Main Street”“,“address2”: Box 225"”,“city”: Escondido"“,“countryCode”: “USA”,“provinceCode”: Orange”“,“zip”: 95111"”},“trackingInfo”: {“company”: “abc company”,“number”: “2223333”,“numbers”: [“4445555”],“url”: “https://blahblah.com”,“urls”: [“https://blahblah.com”]}},“message”: “Hello world”}"}
myURLConnection.SetRequestContent(sQuery + sVars, “application/json”)
sResult = myURLConnection.SendSync(“POST”, “https://{mystore}.myshopify.com/admin/api/2022-07/graphql.json?access_token=nnnnn”)

I’ve tried omitting “variables” (of course in correct Json format), but no help.

What is being missed here?

Helllo, doing a lot if graphql request,but im using jsonmbs to compose my jrequest
Last week i tried to buil a string didnt wirk dont know why,
Composing your post json with json items then cionverting to string brings more flexibily writtin projects.
Does simple query works?

1 Like

Query works. Just the mutation and variables not.

did you try replacing strings instead of variables to see it it works to pinpoint the problem ?
do you json first element is name “query” even if it’s mutation ?

1 Like

queries works with variables ?

also there should be longer message than “bad request” ? it’s shopify backend ?

1 Like