5

I am trying like this,

Step 1: Post(empty) baseurl/rest/V1/guest-carts

get: guest customerid =02ccea0d67a4be667fa6ebf7905tia21

Step 2: I want add items to cart,so am using this api, POST /V1/guest-carts/{cartId}/items

Post: {
"cartItem": {
"itemId": 2,
"sku": "RJ0111",
"qty": 1,
"name": "Normal Kit",
"quoteId": "02ccea0d67a4be667fa6ebf7905tia21",

}

baseurl/rest/V1/guest-carts/02ccea0d67a4be667fa6ebf7905tia21/items

it gives response as 400 Bad Request,how can i get this and please tell me process step by step.

and what is "quoteId" here,

8

Please follow the below steps as shown in the screenshots so that it will help you

enter image description here

enter image description here

enter image description here

enter image description here

Note:

1) Mask Key we can trace out from the table called 'quote_id_mask' enter image description here

2) quote_id (or) cart id as well you can check it in the same table

3) cart item info saved in the table called quote_item

6

The API is very tricky here.

  1. You need to create a cart first: [POST] /V1/carts/

This will return an ID.

  1. Now add the item to your cart: [POST] /V1/guest-carts/{cartId}/items

Body:

{
    "cart_item": {
        "quote_id": "{{use_your_cart_id}}",
        "sku": "YOUR_PRODUCT_SKU",
        "qty": 1
    }
}
  • 1
    Do you guys know of a way to get items thumbnails when requesting the cart? – Mackelito Aug 19 '16 at 9:48
  • So {cartId} and the value of "quote_id" should be the same value? What if they are not? – BrandenB171 Mar 19 '18 at 20:03
  • @awavi when i run the POST http:/test.com/rest/V1/carts/mine/items Response: The consumer isn't authorized to access %resources – Kirti Nariya Aug 13 at 6:58
5

For guest you need to follow these steps:

Step-1: Create empty guest-cart

POST http://yourhost.com/rest/V1/guest-carts

The response of above request will give you "cartKey"

[Note: remove double quotes from the response]. And store it in some area, it will be needed in Step-2.

Step-2: Get cart details at any time after Step-1 above,

GET http://yourhost.com/rest/V1/guest-carts/{cartKey from step-1}

Step-3: Add product to the cart

POST http://yourhost.com/rest/V1/guest-carts/{cartKey from step-1}/items

Submit the JSON Payload

{ "cartItem" : { "sku" : productSKU, "qty" : 1, "quoteId" : quoteId } }

Note:

  1. productSKU = The product you want to add to cart

  2. qty=1 means you want to add one product to cart

  3. quoteId=quoteId you received in step-2

how can i get this and please tell me process step by step. and what is "quoteId" here,

quoteId is the actual cart id in quote table. From the response of Step-2 you can find it in JSON response with key id.

Here are the list of magento 2 APIs listing with modules.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.