0

I am trying to build a simple tool that lets me add products directly to the shopping cart from an external CMS site using the REST API. Currently, I am trying to leverage the guest-carts to minimize security risk.

It looks like I need to first generate a new guest cart id:

POST /rest/default/V1/guest-carts

Then I add products to that cart:

POST /rest/default/V1/guest-carts/<generated cart id>/items {
    "cartItem": {
        "sku": "<item_sku>",
        "qty": 1
    }
}

Which returns:

{ "message": "No such entity with %fieldName = %fieldValue",
  "parameters": { "fieldName": "cartId", "fieldValue": null } }

If I add cartId to the first part I now get:

Next Exception: Message: Property "CartId" does not have corresponding setter in class "Magento\Quote\Api\Data\CartItemInterface". in <magento_root>/vendor/magento/framework/Webapi/ErrorProcessor.php:195
Stack trace:
#0 <magento_root>/vendor/magento/framework/Webapi/ErrorProcessor.php(139): Magento\Framework\Webapi\ErrorProcessor->_critical(Object(LogicException))
#1 <magento_root>/vendor/magento/module-webapi/Controller/Rest.php(219): Magento\Framework\Webapi\ErrorProcessor->maskException(Object(LogicException))
#2 <magento_root>/var/generation/Magento/Webapi/Controller/Rest/Interceptor.php(37): Magento\Webapi\Controller\Rest->dispatch(Object(Magento\Framework\App\Request\Http))
#3 <magento_root>/vendor/magento/framework/App/Http.php(135): Magento\Webapi\Controller\Rest\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#4 <magento_root>/vendor/magento/framework/App/Bootstrap.php(258): Magento\Framework\App\Http->launch()
#5 <magento_root>/index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
#6 {main} [] []

What's going on? How do I use the guest cart REST API?

1 Answer 1

0

Nevermind, it looks like you need to include quote_id in the cartItem payload.

2
  • But isn't the quote only generated only when you place the order?
    – colefner
    Commented Feb 14, 2017 at 19:33
  • FYI, the quote_id being the same token as the cart id (not the actual quote entity primary key)
    – Erfan
    Commented Apr 29, 2017 at 18:18

Your Answer

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

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