Hey everyone, I’m new here and could use some help. I’m trying to update a variant price using a PUT request through the Shopify Admin API. I’m working with Airtable Scripts and JavaScript.
Here’s a simplified version of my code:
const data = {
variant: {
price: '999',
compare_at_price: '999'
}
};
const headers = new Headers();
headers.append('X-Shopify-Access-Token', shopifyToken);
headers.append('Content-Type', 'application/json');
const options = {
method: 'PUT',
headers: headers,
body: JSON.stringify(data)
};
const endpoint = 'https://my-store.myshopify.com/admin/api/2022-04/variants/123456789.json';
const result = await fetch(endpoint, options);
console.log(result);
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? Thanks in advance for any help!
As someone who’s wrestled with Shopify API issues before, I think I might know what’s going on here. The 406 error often crops up when there’s a mismatch between what the client is sending and what the server expects to receive.
One thing that jumps out at me is that you’re sending the price as a string (‘999’) instead of a number. Shopify can be finicky about data types. Try modifying your data object like this:
const data = {
variant: {
price: 999,
compare_at_price: 999
}
};
Also, make sure your Airtable script isn’t inadvertently modifying the headers or request body. I’ve seen cases where certain environments can alter the request without you realizing it.
If that doesn’t work, you might want to log the entire response object, not just the result. Sometimes the error details can provide more insight into what’s going wrong. Hope this helps!
hey josephk, welcome to the forum! have u tried adding an ‘Accept’ header to ur request? sometimes APIs can be picky bout that. try adding this line:
headers.append(‘Accept’, ‘application/json’);
might solve ur issue. if not, double-check ur shopify token is valid in airtable. good luck!
I encountered a similar issue when working with the Shopify Admin API. The 406 error often indicates a mismatch in content negotiation. Have you verified that your Airtable Scripts environment is correctly handling the API version? Try explicitly specifying the API version in your endpoint URL:
‘https://my-store.myshopify.com/admin/api/2023-07/variants/123456789.json’
Also, ensure your Shopify access token has the necessary permissions for variant updates. If the problem persists, you might want to check Airtable’s documentation for any known limitations or quirks when making external API calls from their scripting environment.