The problem Overview
- When getting products using a get method everything works
- when trying to update a product using put method I get 401 unauthorized
- I use same credentials for both methods
- The bearor token is global scope, I should be authorized to do anything to a given product
The code
get
const axiosOptions = {
headers: {
"Authorization": `Bearer ${token}`
}
}
const onAllClick = async () => {
const result = await axios.get(`https://api.printify.com/v1/shops/${shopId}/products.json?limit=30`, axiosOptions );
const products = result.data.data;
console.log(products);
}
put
const axiosTagUpdateOptions = {
headers: {
"Authorization": `Bearer ${token}`
},
data: {
title:"New product title"
}
}
const onEditTagsClick = async (productID, tags) => {
await axios.put(`https://api.printify.com/v1/shops/${shopId}/products/60e0a5c198be4c1296798c27.json`, axiosTagUpdateOptions)
.catch(err => console.log(err));
}
Problem
The get function works perfectly fine. But whenever I try to modify a product using the put method, like the documentation says, I get a 401 unauthorized error. But I’m using the same token for both the get and the put method. The token is set to global scope (for testing purposes) so I should be able to edit and delete products at will.
I read through the API documentation and it looks like I got everything right. I have the bearer token as the header and in the body I included the value I want to modify. Obviously the request is going through, I just don’t know why it keeps saying I’m unauthorized to edit the product. I would have liked to edit the product from the printify UI, but the UI won’t let me add tags (which is really annoying)… So I’m forced to update via a put method.
I couldn’t find any reason for why I am getting this error, can anyone help me?