Use shopify graphql in java application get 406

xsjiang
New Member
1 0 0

I used cUrl to perform the ProductVariant update by referring to the official example, and it worked.

curl -X POST \
  https://xxxx.myshopify.com/admin/api/2021-10/graphql.json \
  -H 'Content-Type: application/graphql' \
  -H 'X-Shopify-Access-Token: xxxxx' \
  -d '
  mutation updateVariants {
    f1: productVariantUpdate(input: {
      id: "gid://shopify/ProductVariant/xxxxx",
      price: 120
    }) {
      userErrors { field, message }
    },
    f2: productVariantUpdate(input: {
      id: "gid://shopify/ProductVariant/xxxxx",
      price: 130
    }) {
      userErrors { field, message }
    }
  }
  '

After that I send http request inside java using unirest tool, but it returns me 406.

// This value is the same as the parameter submitted by cUrl
String mutation = new String(Files.readAllBytes(Paths.get("hql.txt")));

String url = "https://mystore.myshopify.com/admin/api/2021-10/graphql.json";
HttpResponse<String> resp = Unirest.put(url)
    .header("Content-Type", "application/graphql")
    .header("X-Shopify-Access-Token", apiSecret)
    .body(mutation)
    .asString();
System.out.println(resp.getStatus() + " " + resp.getStatusText());
System.out.println(resp.getBody());

 

This is hql.txt

mutation updateVariants {
    f1: productVariantUpdate(input: {
      id: "gid://shopify/ProductVariant/xxxxx",
      price: 120
    }) {
      userErrors { field, message }
    },
    f2: productVariantUpdate(input: {
      id: "gid://shopify/ProductVariant/xxxx",
      price: 130
    }) {
      userErrors { field, message }
    }
  }

 

Reply 1 (1)
csam
Shopify Staff
154 24 25

Hi @xsjiang 

Can you please log all the request header fields you are including in the request *aside from password/authentication fields* and post them here? 

Thanks!

CS | API Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog