1

if i add a item to cart via api it set Magento 2 default price of the item instead price set via API

1st i create a cart for a customer:

index.php/rest/default/V1/customers/631/carts

via POST

index.php/rest/default/V1/carts/{cartid}/items

via POST

json:

{ "cartItem": { "quote_id": "cart_id_from_1st_response", "sku": "test_sku", "qty": 1, "price": "11" } }

the response is like that:

stdClass Object
    (
        [item_id] => 186
        [sku] => test_sku
        [qty] => 1
        [name] => Testarticle
        [price] => 15
        [product_type] => simple
        [quote_id] => 287
    )

the price should be 11 as in the post, but the API response the prie of 15

1
  • want You to post custom price which you have sent from post parameters
    – Amit Bera
    May 23, 2019 at 9:21

1 Answer 1

0

/V1/carts/{cartId}/items is an endpoint for GET request.
Try with the following endpoint instead:

For POST:

/V1/carts/{quoteId}/items
/V1/carts/mine/items

For PUT

/V1/carts/{cartId}/items/{itemId}  
/V1/carts/mine/items/{itemId}
3
  • quoteId and cartId are still the same? the response of POST V1/customers/631/carts is the id to which i post the items
    – Jan
    May 23, 2019 at 14:07
  • @Jan I'm not really sure but I think is the same. The id from V1/customers/631/carts is the quoteId you use to POST items to cart using /V1/carts/{quoteId}/items endpoint and then from there, you get the cart id from response which you use to update the cart items using /V1/carts/{cartId}/items/{itemId} endpoint
    – fmsthird
    May 24, 2019 at 4:05
  • yes i think im right but...i send to the endpoint this json: { "cartItem": { "item_id": 189, "quoteId":289, "price": 89, "qty":1 } } and get this response: { "cartItem": { "item_id": 189, "quoteId":289, "price": 89, "qty":1 } } so the price will not accept
    – Jan
    May 25, 2019 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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