Update Inventory

Last updated 2 months ago

Action types

Type

Description

increment

You'll use this when you receive stock from a supplier, making products available for purchase

decrement

You'll use this when you want to remove stock from product inventory

allocate

You'll use this when you want to allocate stock, normally to a reseller who will sell on the stock

deallocate

You'll use this when you want to deallocate any previously allocated stock

post
Create a Stock Transaction for a Product

https://api.moltin.com
/v2/inventories/:productId/transactions
Request
Response
Path Parameters
productId
required
string
The ID for the product you're performing this action on
Headers
Authorization
required
string
The Bearer token to grant access to the API
Body Parameters
quantity
required
integer
The amount of stock affected by this transaction
action
required
string
increment, decrement, allocate, deallocate
type
required
string
Always stock-transaction
200: OK
You will get the response below for any of the action types.
{
"data": {
"id": "da9a0008-d2c4-4a17-bbc6-5e0b2f9430aa",
"type": "stock-transaction",
"action": "increment",
"product_id": "9eda5ba0-4f4a-4074-8547-ccb05d1b5981",
"quantity": 10,
"timestamps": {
"created_at": "2018-05-01 10:10:57 +0000 UTC"
}
}
}
422: Unprocessable Entity
You will get an error if you try to perform an action with incorrect amounts
{
"errors": [
{
"status": 422,
"title": "Cannot complete request",
"detail":
"Your request could not be completed due to insufficient stock levels"
}
]
}
cURL
JavaScript SDK
Moltin Request
curl -X POST https://api.moltin.com/v2/inventories/:productId/transactions \
-H "Authorization: Bearer XXXX" \
-H "Content-Type: application/json" \
-d $'{
"data": {
"type": "stock-transaction",
"action": "increment",
"quantity": 10
}
}'
const MoltinGateway = require('@moltin/sdk').gateway
const Moltin = MoltinGateway({
client_id: 'X',
client_secret: 'X'
})
const productId = 'XXXX'
const quantity = 10
Moltin.Inventories.IncrementStock(productId, quantity).then(transaction => {
// Do something
})
Moltin.Inventories.DecrementStock(productId, quantity).then(transaction => {
// Do something
})
Moltin.Inventories.AllocateStock(productId, quantity).then(transaction => {
// Do something
})
Moltin.Inventories.DeallocateStock(productId, quantity).then(transaction => {
// Do something
})
const { createClient } = require('@moltin/request')
const client = new createClient({
client_id: 'X',
client_secret: 'X'
})
const productId = 'XXXX'
client
.post(`inventories/${productId}/transactions`, {
type: "stock-transaction",
action: "increment",
quantity: 10
})
.then(inventory => {
// Do something...
})
.catch(console.error)