cancel
Showing results for 
Search instead for 
Did you mean: 

REST API - Bulk Product Availability

REST API - Bulk Product Availability

I am trying to debug a stock availability sync issue with out stock control system and Magento 2.X

 

Try as I might I cant find a way via REST to get the current Magento Stock Quantity & in_stock status of products other than one by one via:

/rest/V1/stockItems/{SKU}

 

This is obviously not ideal requiring thousands of requests and knowledge of all listed SKUS ahead of time.

 

I can get other product info via:

/rest/V1/products?searchCriteria[pageSize]={500}&searchCriteria[currentPage]={3}

 

But this endpoint does not return stock information.

 

Is there any known way to get (paginated) stock info for all products in one request? ie something like:

{

    "page":1,

    "products":[

        {"SKU":"1234","is_in_stock":True,"inventory":4},

        {"SKU":"5678","is_in_stock":True,"inventory":2},

        {"SKU":"9101","is_in_stock":False,"inventory":0},

        {"SKU":"1213","is_in_stock":True,"inventory":1},

        {etc...}

    ]

}

1 REPLY 1

Re: REST API - Bulk Product Availability

To call a bulk endpoint, add the prefix /async/bulk before the /V1 of a synchronous endpoint route.

Bulk API endpoints differ from other REST endpoints in that they combine multiple calls of the same type into an array and execute them as a single request. The endpoint handler splits the array into individual entities and writes them as separate messages to the message queue.

 

Use the bin/magento queue:consumers:start async.operations.all command to start the consumer that handles asynchronous and bulk API messages. Also, before using the Bulk API to process messages, you must install and configure RabbitMQ, which is the default message broker. See RabbitMQ.

 

Routes

To call a bulk endpoint, add the prefix /async/bulk before the /V1 of a synchronous endpoint route. For example:

POST /async/bulk/V1/products
POST /async/bulk/V1/customers

Endpoint routes that contain input parameters require additional changes. For example,

PUT /V1/products/:sku/media/:entryId contains the :sku and :entryId 

input parameters. The route of a bulk request cannot contain input parameters, so you must change the route so that it does not contain any. To do this, replace the colon (Smiley Happy with by and change the first letter of the parameter to uppercase.

The following table provides several examples:

 

SYNCHRONOUS ROUTE

PUT /V1/products/:sku/media/:entryId
POST /V1/carts/:quoteId/items

BULK ROUTE

PUT async/bulk/V1/products/bySku/media/byEntryId
POST async/bulk/V1/carts/byQuoteId/items