I’m stuck trying to use JavaScript in Zapier to connect with the BigCommerce API. My code keeps failing with a 401 error. Here’s what I’ve tried:
const apiKey = 'my_secret_key';
const endpoint = 'https://mystore.example.com/api/v3/[email protected]';
fetch(endpoint, {
method: 'GET',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
}
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
I’ve double-checked my API key and made sure I’m using HTTPS, but no luck. The server keeps saying I’m not authenticated. Any ideas on what I might be doing wrong or how to fix this? I’m pretty new to API stuff, so simple explanations would be awesome. Thanks!
I’ve been through this headache with BigCommerce authentication before. One thing that’s not obvious is that BigCommerce actually uses a three-part authentication system. You need the store hash, the access token, and the client ID. Your endpoint URL should look something like this:
https://api.bigcommerce.com/stores/{store_hash}/v3/catalog/products
And then in your headers, you’d have:
‘X-Auth-Token’: ‘{access_token}’,
‘X-Auth-Client’: ‘{client_id}’
Also, make sure you’re using the right scopes for your API credentials. If you’re trying to access user data, you need the ‘users_read’ scope. You can check and modify these in your app’s API account section in the BigCommerce dashboard.
If all else fails, try using their official Node.js client library. It handles a lot of the authentication hassle for you. Hope this helps!
I encountered a similar issue when integrating with BigCommerce’s API. The problem likely lies in the authentication method you’re using. BigCommerce typically requires a combination of headers for proper authentication:
- X-Auth-Token: Your API token
- X-Auth-Client: Your client ID
- Content-Type: application/json
Try modifying your headers object like this:
headers: {
'X-Auth-Token': apiKey,
'X-Auth-Client': 'your_client_id',
'Content-Type': 'application/json'
}
Also, ensure your endpoint URL includes the correct store hash. If these changes don’t resolve the issue, double-check your API credentials in your BigCommerce control panel. Sometimes, regenerating the API token can solve persistent authentication problems.
hey there! just a quick thought - have u tried using the ‘X-Auth-Token’ header instead of ‘Authorization’? BigCommerce can be picky bout that. also, double check ur store hash is correct in the URL. those things tripped me up before. good luck!