“code”:”woocommerce_rest_missing_nonce”,”message”:”Missing the X-WC-Store-API-Nonce header. This endpoint requires a valid nonce.”
You gonna see this error when you are using WooCommerce REST API. The error is self explanatory and easy to understand.
The API asking us to pass a nonce.
Here is a snippet of using JS including nonce in the header, we just gonna grab wp_create_nonce function, generate a string and pass the value via our headers to the API.
Why do we still see the error?
If you google around you will realise you are not alone.
The reason why you are seeing the error is due to API requiring a nonce with a specific name.
If you generate a nonce value using wp_create_nonce(‘my-string’) where ‘my-string’ is a string of your choosing, things won’t work, the value has to come from using expectd key, wp_create_nonce( ‘wc_store_api’ )
As it turns out the end point that I’m trying to use is: “/wp-json/wc/store/cart/add-item”
This endpoint is a part of the WooCommerce Products Block extension, so you need to refer to the WooCommerce Products Block extension documentation.
You can view the source code where the nonce is being verified.
To list all of the endpoints related to the cart, enter into your browser yourdomain.com/wp-json/wc/store
All of the shopping cart related endpoints are not a part of the WooCommerce REST API at this stage as it was pointed out by @wpnomad