0

I'm looking for the bulk variant of the product stock update API

/rest/default/V1/products/{productSku}/stockItems/{itemId}

Objective: I want to update quantities of multiple products in one API call

What I've tried

I checked the Magento2 guides on bulk APIs and came across this Bulk endpoints | Magento 2 Developer Documentation and based on the info from there updated the above link to this

PUT rest/async/bulk/V1/products/byProductSku/stockItems/byItemId

and this is the body

[
    {
        "productSku": "Test-Product",
        "stockItem": {
            "itemId": 32,
            "qty": 338,
            "is_in_stock": true,
            "use_config_manage_stock": false
        }
    }
]

But this isn't working, I'm getting the error

{
    "message": "Internal Error. Details are available in Magento log file. Report ID: webapi-..."
}

My two main concerns are whether there is an API i can use that already does this, or if my approach mentioned above is possible and I need to change something to fix the issue.

1

The endpoint you added in your post works properly for me :| I am not sure which is the problem on your environment, but I suggest you check the log files, surely there must be something in there. And also would be a good idea to verify that your RabbitMQ connection is correctly configured and works properly. (the async.operations.all queue is processed only via amqp connection.)

I also found that you can update the stocks by using the endpoint (useful for MSI especially):
POST /rest/default/async/bulk/V1/inventory/source-items with the following payload:

[
 {
  "sourceItems": [
    {
      "sku": "WSH12-29-Red",
      "source_code": "default",
      "quantity": 111,
      "status": 1
    },
     {
      "sku": "MH01-XS-Black",
      "source_code": "default",
      "quantity": 222,
      "status": 1
    }
   ]
  }
]

(Redoc https://magento.redoc.ly/2.4.2-admin/tag/inventorysource-items/#operation/inventoryApiSourceItemsSaveV1ExecutePost)

2
  • The inventory API works, thanks! – AHMED SAJJAD Mar 9 at 13:31
  • you are most welcome! :) – Diana Botean Mar 9 at 13:32

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.