26 Mar 2021




WooCommerce REST API Cart Endpoint Error

WordPress Development by Digital Apps

“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.

This is easy, we just gonna grab wp_create_nonce function, pass the value via our headers to the API. Submit.

Why do we see the same error again?

If I google around you will realise you are not alone.

The reason why you are seeing the error is due to API requiring not just any nonce, but a specific one.

Don’t just pass the value return from wp_create_nonce(‘my-string’), the value has to come from wp_create_nonce( ‘wc_store_api’ )

As it turns out the end point that I’m trying to use: “/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