0

When I try to add to card any item via REST API I get this error:

"{"message":"\"%fieldName\" is required. Enter and try again.","parameters":{"fieldName":"quoteId"}}"

First time I get the cart id calling this

"rest/V1/carts/mine"

than I call

"rest/V1/carts/mine/items"

with this data:

{
  "cartItem": {
    "sku": "24-WG080",
    "qty": 1,
    "quote_id": cartID
  }
}

Tried with cart-item, quoteId, quote_id and more...

I'm stuck, I have no ideea what is wrong, the documentation is wrong? https://devdocs.magento.com/guides/v2.4/rest/tutorials/orders/order-add-items.html

Enabed developer mode, and now I got this error in response:

"#0 [internal function]: Magento\Quote\Model\Quote\Item\Repository->save(Object(Magento\Quote\Model\Quote\Item))
#1 /home2/xxx/vendor/magento/module-webapi/Controller/Rest/SynchronousRequestProcessor.php(95): call_user_func_array(Array, Array)
#2 /home2/xxx/vendor/magento/module-webapi/Controller/Rest.php(188): Magento\Webapi\Controller\Rest\SynchronousRequestProcessor->process(Object(Magento\Framework\Webapi\Rest\Request\Proxy))
#3 /home2/xxx/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Webapi\Controller\Rest->dispatch(Object(Magento\Framework\App\Request\Http))
#4 /home2/xxx/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Webapi\Controller\Rest\Interceptor->___callParent('dispatch', Array)
#5 /home2/xxx/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Webapi\Controller\Rest\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#6 /home2/xxx/generated/code/Magento/Webapi/Controller/Rest/Interceptor.php(23): Magento\Webapi\Controller\Rest\Interceptor->___callPlugins('dispatch', Array, Array)
#7 /home2/xxx/vendor/magento/framework/App/Http.php(116): Magento\Webapi\Controller\Rest\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#8 /home2/xxx/generated/code/Magento/Framework/App/Http/Interceptor.php(23): Magento\Framework\App\Http->launch()
#9 /home2/xxx/vendor/magento/framework/App/Bootstrap.php(264): Magento\Framework\App\Http\Interceptor->launch()
#10 /home2/xxx/pub/index.php(29): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http\Interceptor))
#11 {main}"

2 Answers 2

2
  1. Create a request to create the empty cart POST

{{magento_api_url}}/rest/default/V1/guest-carts/

this will return a token which is the cart ID (e.g 'KZepbhhPiGORreBKqIRlMCywGDTyQtR4')

  1. Use that cart ID in the request which adds an item to the cart POST

{{magento_api_url}}/rest/default/V1/guest-carts/KZepbhhPiGORreBKqIRlMCywGDTyQtR4/items

with the payload similar to what you see below (where quote_id is the key you previously used and the SKU is the SKU of the product you want to add):

{
    "cartItem": {
        "qty": 5,
        "sku": "24-UG06"
    }
}
0

Refer to the Below Reference.

https://devdocs.magento.com/guides/v2.4/rest/tutorials/orders/order-create-quote.html

1
  • guest cart works, the one for logged in users doesn't
    – Adrian
    Jan 5 at 8:42

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.