Jump to content

Commerce API POST Endpoints returning 401 Unauthorized

Recommended Posts

I am trying to update product variants and adjust stock quantities for products using the commerce API endpoints as seen here and here. I am running into an issue where it is giving me a 401 unauthorized request although I have all of the required headers, as well as the correct body. I can make this POST request through Postman no problem but trying to make an identical request through javascript only returns 401 unauthorized. 

Simple example (using product variant endpoint):

await axios.post(`${API_URL}/${productId}/variants/${variantId}`, {

headers: {

'Authorization': 'Bearer ' + API_KEY,

'Content-Type': 'application/json',

'User-Agent': 'blahblahblah'

},

body: body

}).then(function (data) {

console.log(data);

})

.catch(function (error) {

console.log(error);

});

If anyone could provide guidance on why this is happening and how to fix that would be greatly appreciated!

Link to comment
  • Replies 0
  • Created
  • Last Reply

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.