ANSWERED

Public API > How do I Manage Stock Levels?

Q: How can I view and update the stock level of an inventory item in Disco via the public API? A: This can be done using a few calls in the "Products" section. You can find the warehouse list via API from the Products/Get Warehouses call. # GET Stock Level call: **Note:** This is the only call that retrieves stock level on an item. You won't find it in the Get Item call. **Note 2:** You will not find Warehouse in the Get Item call. You will need to know the warehouse you're fetching for. For this example, the Warehouse ID is "2". Here I'll grab stock for Item 2, warehouse 2: URL: `https://dsapi-stage.directscale.com/v1/products/item/2/stockLevel/2` Response: ``` { "WarehouseId": 2, "ItemId": 2, "Committed": 0.0, "OnHand": 6000.0, "OnOrder": 0.0, "TrackStock": 1, "Avaliable": 6000.0 } ``` # PUT (Update Stock Level): I looked at the system that the API works with, and I see that it expects this payload: ``` { "Item": { "WarehouseId": 0, "ItemId": 0, "Committed": 0, "OnHand": 0, "OnOrder": 0, "TrackStock": 0, "Avaliable": 0 } } ``` The ItemId needs to be passed in the URL, like this: ``` https://dsapi-stage.directscale.com/v1/products/items/{itemId}/stockLevel ``` It will then be added to the payload for the back-end system. # Example: I will now call the "Update Stock Level" API for item 2: URL: `https://dsapi-stage.directscale.com/v1/products/items/2/stockLevel` PUT Request: ``` { "warehouseId": 2, "onHand": 1234 } ``` HTTP Response: 200 Now we will verify that this actually did something :) GET URL: `https://dsapi-stage.directscale.com/v1/products/item/2/stockLevel/2` Response: ``` { "WarehouseId": 2, "ItemId": 2, "Committed": 0.0, "OnHand": 1234.0, "OnOrder": 0.0, "TrackStock": 1, "Avaliable": 1234.0 } ``` It worked!