0

I'm fairly new to Magento API (REST) and am trying to create a cart for an existing customer via admin API, update the cart and apply a discount coupon.

So far I've hit two major issues:

1) I can't figure out how to get a clear shopping cart for the user. I'm using the admin API to call POST /all/V1/carts/mine with {"customer_id": 4} (for example) in the body. This returns 8, which is great and calling GET /all/V1/carts/8 or GET /all/V1/carts/mine?customer_id=4 will get me the cart. The issue is that the cart may already contain some items. Is there a quick way to clear the cart? The obvious thing is to call DELETE on all the items in the cart, but one needs to also remember to clear shipping, coupons, etc. This seems to be a similar issue to https://github.com/magento/magento2/issues/7107 There doesn't seem to be a way to delete the entire cart and start over - is there?

2) Having the cart, how do I change the store_id of the cart? I've tried virtually everything (PUT request onto /all/V1/carts/8 with {"store_id": 1} and various variations, most of them ending in error that the request is missing customer_id and with customer_id an error The customer can't be assigned to the cart because the cart isn't anonymous.), but it still says store_id: 0. The issue is that when I try to add a coupon to that cart using PUT /all/V1/carts/8/coupons/20OFF, I get an error Cart isn't assigned to correct store. This happens for all the coupons. The scope of the coupon is the website.

Anyone any ideas what I'm doing wrong?

0

Please review all detail with an example in the rest API swagger.

https://devdocs.magento.com/swagger/

I hope this will help you.

  • Sorry, but I'm not sure if you are asking me to supply specific API calls, or if you are just referring me to the docs as I've gone through them quite a few times and am unable to get past the issues I've mentioned... – Charlie Monroe Nov 22 '19 at 5:30

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.