Encountering 406 Error When Updating Variant Price via Shopify Admin API in Airtable Scripts

Hey everyone! I’m new here and could use some help. I’m trying to update a variant price using the Shopify Admin API through Airtable Scripts. Here’s what I’m doing:

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

const headers = new Headers();
headers.append('X-Shopify-Access-Token', myApiToken);
headers.append('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/123456789.json';

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

It works fine in Postman, but in Airtable Scripts, I get a 406 Not Acceptable error. Any ideas what might be causing this? Thanks in advance for any help!

I’ve run into this issue before when working with the Shopify Admin API in Airtable Scripts. The 406 error usually indicates a problem with the Accept header. Try adding ‘Accept’: ‘application/json’ to your headers. This tells the server you’re expecting a JSON response.

Also, make sure your API version is up to date. Shopify periodically deprecates older versions, which can cause unexpected errors. You’re using 2022-04, but the latest stable version is typically more reliable.

One more thing - double-check your myApiToken variable. Sometimes, token issues can manifest as strange errors. Ensure it’s correctly set and hasn’t expired.

If these don’t solve it, you might need to look into Airtable’s fetch implementation. Sometimes, it behaves differently from standard fetch, especially with certain headers or request structures.

hey avamtz, i’ve had this issue too. try adding ‘Accept-Encoding’: ‘gzip’ to ur headers. sometimes airtable’s fetch is weird with compression. also, check if ur using the right shop url - make sure it’s the .myshopify.com one, not a custom domain. if that doesnt work, maybe try using XMLHttpRequest instead of fetch?

I encountered a similar issue when working with the Shopify Admin API in Airtable Scripts. Have you considered using the Shopify JavaScript Buy SDK instead? It’s designed to work well with client-side JavaScript and might be more compatible with Airtable’s environment.

If you prefer sticking with the Admin API, try simplifying your request. Sometimes, Airtable’s fetch implementation can be finicky with complex headers. You could try removing the ‘Content-Type’ header and let fetch set it automatically. Also, ensure your API token has the necessary permissions for modifying products.

Another potential workaround is to use Airtable’s built-in HTTP request function instead of fetch. It might handle the request differently and avoid the 406 error. If all else fails, you might need to set up a proxy server to handle the API requests outside of Airtable’s environment.