WooCommerce and Rest API. Can;
-
store_url2 = 'https://18.185.149.134/wp-json/wc/store/v1/cart/items' product = wcapi.get("products/17").json() response2= requests.get(store_url2) # CART + BU [] > print( response2.headers.get('nonce' )) print(response2.headers.get('cart-token')) print(response2.json()) headers = { 'nonce': response2.headers.get('nonce'), 'cart-token': response2.headers.get('cart-token'), } print(payload)# id:17 quantity:1 response3 = requests.post(store_url2, json=payload, headers=headers) if response3.status_code == 200: print(response3.status_code) print("Product added successfully.") else: print(response3.status_code) print("Error while adding the product. Error message:", response3.text)
So, I have used the
Requests
module in Python to add products to my cart. The website is created with WordPress. It includes WooCommerce too. I includednonce
andcart-token
in my code. We made the product purchasable cause it was False, and we made it True. Right now, the website is not accessible. Cause we thought maybe our website must be HTTPS rather than HTTP.Other than that, can you please check my code to see if it’s right or wrong? I am in the dark here. I need to be able to send it to the cart.
Lastly, I have checked my GET/POST methods.
https://18.185.149.134/wp-json/wc/store/v1/cart/items
outputs a[ ]
, which is a cart empty list. I would be so grateful if someone could shine the tunnel ahead. Truly, thanks in advance. Take care.
- The topic ‘WooCommerce and Rest API. Can;’ is closed to new replies.