Encountering 'Not Acceptable' error when updating variant prices via Shopify Admin API in Airtable Scripts

Hey everyone, I’m new here and could use some help with a problem I’m facing.

I’m trying to update variant prices using a PUT request through the Shopify Admin API. I’m doing this in Airtable Scripts using JavaScript. Here’s a simplified version of my code:

const variantData = {
  variant: {
    price: '999',
    compare_at_price: '999'
  }
};

const headers = new Headers({
  'X-Shopify-Access-Token': shopifyToken,
  'Content-Type': 'application/json'
});

const requestOptions = {
  method: 'PUT',
  headers: headers,
  body: JSON.stringify(variantData)
};

const apiUrl = 'https://my-store.myshopify.com/admin/api/2022-04/variants/12345678.json';

const response = await fetch(apiUrl, requestOptions);
console.log(response);

The weird thing is, this works fine in Postman. But when I run it in Airtable Scripts, I get a 406 ‘Not Acceptable’ error. Any ideas what might be causing this? I’m stumped!

Thanks in advance for any help you can offer!

hey luna, have u tried adding the ‘Accept’ header? sometimes shopify can be picky. try adding this to ur headers:

‘Accept’: ‘application/json’

if that doesnt work, double check ur shopify token is correct. api errors can be tricky, hang in there!

I encountered a similar issue when working with the Shopify Admin API. The 406 error often indicates a mismatch between the requested content type and what the server can provide. In your case, it’s likely due to the API version you’re using.

Try updating your API endpoint URL to the latest version. As of now, it’s 2023-07. So your URL should look like:

https://my-store.myshopify.com/admin/api/2023-07/variants/12345678.json

Also, ensure your Shopify app has the necessary permissions to modify products and variants. If the issue persists, consider logging the full response body for more detailed error information. This approach helped me diagnose and resolve the problem in my project.

I’ve dealt with similar Shopify API headaches before. One thing that’s not immediately obvious is that Airtable Scripts might be modifying your headers or request structure slightly. Have you tried using the UrlFetchApp.fetch() method instead of the standard fetch()? It tends to play nicer with external APIs in my experience.

Also, double-check your store’s API access settings. Sometimes permissions can get wonky, especially if you’ve recently made changes to your app or access tokens. It might be worth regenerating your access token just to rule that out.

If all else fails, try breaking down your request into smaller parts. Update the price and compare_at_price separately to see if one of them is causing the issue. It’s a pain, but it can help pinpoint where things are going wrong. Good luck, and don’t let Shopify’s quirks get you down!