Magento 2.3 ERP integration and update stock via Bulk Api

Almost every merchant wants to update or synchronize product stock in Magento over API. In this post we will explain how to do it on Magento 2.3 version. Probably you know that Magento 2.3 is coming with built in support for RabbitMQ.

Support for RabbitMQ is excellent thing because with RabbitMQ we can use asynchronous API and process big amount of API requests.

What does it mean? It means that you can send few thousand of requests from ERP to Magento and you don’t need to wait for finishing it. All ERP requests will be stored in RabbitMQ queue and executed / processed in background by RabbitMQ consumer.
RabbitMQ consumer is different Magento script which is in charge for processing messages from queue.

In first example we will demonstrate how to update product stock over standard Magento REST API.

If you open webapi.xml (config file for Magento API) file inside module-catalog/inventory module you will see next declaration:

As you can see this is declaration for route / update stock item. For testing purpose I’m using great tool Postman for creating api requests to instance of Magento 2.3. You can see in screen shot how to configure Postman for updating process.

Api endpoin url is: http://m23.lo/rest/V1/products/24-MB01/stockItems/1 . 

Our call will update qty for product SKU: 24-MB01 and stock_item: 1.

Next example will demonstrate how to update stock over Magento async or bulk api.

All logic for async api is inside module: module-webapi-async. All api requests to asny api should contains async part of url. Take a look on our API endpoint url: http://m23.lo/rest/async/V1/products/24-MB01/stockItems/1 . I hope that you noticed what is different in url.  Every request to asny api should start with ‘rest/async/‘.

Below is screen shoot from Postman:

If you send request to async api you will get next response from Magento:

Your request is accepted and stored in RabbitMQ queu but not yet processed. For processing request there is specific script in Magento which is called RabbitMQ consumer. How to start Rabbit consumer we will explain in some of the further posts.

If you need any explanation feel free to ask Magento Certified Developer.

You may also like...

2 Responses

  1. Some Dev says:

    This was the most useless explanation of the Bulk API, I’ve come across.
    Why would you even consider using the Bulk API, when you are only updating one product?
    I was hoping to get some in-depth information on how to correctly set up a call for multiple SKU’s, via an endpoint like “PUT async/bulk/V1/products/byProductSku/stockItems/{itemId}” where “byProductSku” is the critical part. The Magento docs do not explain how to organise the SKU’s in the JSON body.

    • dpotkoc says:

      For now there is no possibility to update more then one sku per request.
      When Magento 2.3 was announced with new bulk api, I expected that Magento will have bulk update products.

      With RabbitMQ you can send big amount of requests and they will be processed in background. Only problem is that you have to create big amount of http requests to API.

Leave a Reply