Stock
Requires Authentication
All of the following stock management methods require that you are logged in as an admin for your shop.
See the authentication guide for more information.
Fetch all stock from a product
const productId = '_id of the product you want to retrieve all stock from';
DDPClient.call('admin.product.stock.get.all', [productId], (err, stock) => {
if (err) {
return console.error(err);
}
console.log('Successfully retrieved %s stock entries from product #%s!', stock.length, productId);
stock.forEach((item) => {
item._id // ID of the stock entry.
item.entry // Line-item for the stock entry. This is what is displayed to the customer.
item.createdAt // UTC timestamp for when this stock item was added to your shop.
})
})
Add stock to product
const productId = '_id of the product you want to add stock to';
const stock = [
'stock entry 1',
'stock entry 2',
'some-other-stock-entry'
];
DDPClient.call('admin.product.stock.add', [productId, stock], (err, amountAdded) => {
if (err) {
return console.error(err);
}
console.log('Successfully added %s items to your product stock!', amountAdded);
})
Remove stock from product
const stockToRemove = [
{
_id: '_id of the stock entry you want to remove',
productId: '_id of the product this stock entry belongs to',
},
{
_id: '_id of another stock entry',
productId: 'associated product ID for this stock entry'
},
/// ...
// Feel free to populate with as many or as few stock entries as you wish to delete at once.
]
DDPClient.call('admin.product.stock.delete', [stockToRemove], (err) => {
if (err) {
return console.error(err);
}
console.log('Successfully removed %s stock entries from your shop!', stockToRemove.length);
})