Permendra Singh
Permendra Singh

Reputation: 97

Missing the X-WC-Store-API-Nonce header. This endpoint requires a valid nonce. Postman Error

POST : xyz.com/wp-json/wc/store/cart/add-item I'm Developing a mobile woocommerce application and try to add-item in cart but getting some error please help to fix this problem thanks.

In Body:
  
{
"id": "8924",
"quantity":1,
"variation": [
             {
              "items" :{
              "attribute": "hj",
              "value": "knk"
              }
           }
        
           ]
        }

Error:
{
 "code": "woocommerce_rest_missing_nonce",
 "message": "Missing the X-WC-Store-API-Nonce header. This endpoint requires a valid nonce.",
 "data": {
 "status": 401
        }
}

Upvotes: 6

Views: 4895

Answers (3)

N. Seghir
N. Seghir

Reputation: 131

You need to pass back a nonce as a header, previously X-WC-Store-API-Nonce, now just Nonce.

A nonce is required on all POST requests and all requests to store/checkout. You can get a nonce on every response you get from the server, so if you hit store/cart, you will get a nonce, save that nonce and use it for future requests, but make sure to update it after each response.

Upvotes: 2

user1773030
user1773030

Reputation: 1

You can disable nonce check by adding this filter in your WordPress functions.php file or in a snippet using code snippets plugin

add_filter( 'woocommerce_store_api_disable_nonce_check', '__return_true' );

Upvotes: 0

user30899
user30899

Reputation: 27

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')

you can read more about it here:

https://digitalapps.com/woocommerce-rest-api-cart-endpoint-error/

Upvotes: 0

Related Questions