This post will show you the process of creating stocks using Magento 2 API. In Magento, the stock is like a virtual inventory of products for sources of your sale channels (websites). A stock can map to multiple sales channels, but a sales channel can be assigned to only one stock.
Create the stock
While creating a new warehouse, this information will be needed:
- name
- type
- code
Endpoint:
POST <host>/rest/default/V1/inventory/stocks
Authorization: Admin – Bearer token
Payload:
{
"stock": {
"name": "US Stock",
"extension_attributes": {
"sales_channels": [
{
"type": "website",
"code": "base"
}
]
}
}
}
Code language: JSON / JSON with Comments (json)
Response:
Magento will return stock ID. Later we will use this ID to link the source to stock.
![Magento 2 API (Updated [year]): How to create stocks 1 create stock using magento 2 api](https://www.beehexa.com/wp-content/uploads/2020/11/create-stock-02-1024x466.png)
Verify the result
Log in to your admin account and check your new stocks. Goes to
Stores > Inventory > Stocks
They are displayed in the Stock grid.
![Magento 2 API (Updated [year]): How to create stocks 2 view stock on admin Magento 2](https://www.beehexa.com/wp-content/uploads/2020/11/create-stock-03-1024x316.png)
I have shown you how to create stocks with Magento 2 API. Check how to create warehouses with Magento 2 here. If you have any questions, please leave a comment in the section below, or refer to Magento DevDocs.