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.

Use shopify graphql in java application get 406

Use shopify graphql in java application get 406

xsjiang
Shopify Partner
7 0 3

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 (Retired)
267 40 51

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!

To learn more visit the Shopify Help Center or the Community Blog.