woocommerce-rest-api-js-lib: Refused to set unsafe header "User-Agent"
sample code
const api = new WooCommerceRestApi({
url: "http://my-personal-store.com",
consumerKey: "ck_xxxxxxxxxx",
consumerSecret: "cs_xxxxxxxx",
version: "wc/v3"
});
const { data : categories } = await api.get(`products/categories`)
fires successfully and return the response but it also spit errors in Chrome console
Refused to set unsafe header “User-Agent”
It is also taking a lot of time to fetch (2-3s) due to throwing and catching (i guess)
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 5
- Comments: 21 (2 by maintainers)
I simply fixed it by adding an empty header object to axiosConifg.
axiosConfig: { headers: {} },
seems to do the trick for now.Add content-type header and it works. The reason is if you leave it out, Axios sends a text/plain content header for PUT/POST request.
Soo, I don’t think this works yet? I got the same error.
I’ll update it soon. Thanks for let me know.
I found a decent fix using axios interceptor to force removing custom woocommerce User-Agent 😊
@PlusA2M @claudiosanches
I think it should be fixed in #38
Moreover, I think new version at NPM should publish as soon as possible.
Having the same issue, the error is coming from the axios setting which is setting the user agent:
"User-Agent": "WooCommerce REST API - JS Client/" + this.classVersion
Removing it fixes the issue, but obviously this is hacking source code. Is there some way to get this working by over riding it using theaxiosConfig
option available toWooCommerceRestApi
?I fixed it by using this link in package.json
I experience same issue, wonder when this is fixed damn dont want hacky solution
@mtrabelsi There seems to be a fix for this but it’s not coming through via npm install yet: https://github.com/woocommerce/woocommerce-rest-api-js-lib/commit/90b8bd5816d9ff1b84aacd718fe41c742ac43867