Managing stock in v2

inventory
javascript
products

#1

I am trying to update the stock level for products.
I used “https://api.moltin.com/v2/inventories/{PRODUCT_ID}/transactions” with params as follows:
{
data:{
“type”: “stock-transaction”,
“action”:“increment”,
“quantity”:10
}
}

Now after using this api, I can see the updated stock in my dashboard, but somehow when I fetch the products to my client. I don’t see the updated stock value in “Product.meta.stock.level”.
Its always showing me as "Product.meta.stock.level =0 & Product.meta.stock.availability = “out-of-stock”
How do I fix this??

Also, I can see that now the stocks are managed by “inventory/{PRODUCT_ID}/transactions”,
So let me know if I am wrong : I change the stock via inventory and its suppose to reflect in the products, by products I mean in product.meta.stock.level.


#2

Thanks for submitting this! It’s a very fair question. Whilst the stock object on the product itself takes on the value you add on product creation, it’s actually never updated when you add new stock transactions.

This is because inventory and products are not linked currently (though they will be in future). So, add your new inventory transactions, and when you want to get the current stock of a product using the API, call the inventory endpoints i.e. https://docs.moltin.com/#get-the-stock-for-a-product. Ignore the meta stock object on the product itself for now.

Does that make sense? I appreciate it’s confusing. It’s so we could roll out inventories and build on it without breaking changes.

Thanks,
Matt


#3

Thanks for replying @Matt.
Yes I guess for now I will have to use inventory transactions for checking the stock for each product. I’ll trying implementing that for now and make it work.
Will post if I need more help on this.
Thanks


#4

I was wondering if Moltin updates the inventory for a certain product once an oder is received and a payment authorized?

Wondering because I’d like to decrease the stock after a successful order in a Nuxt.js frontend and I can’t access the inventory API with an implicit token it seems.


#5

Hi studioscholz,

At present you have to decrement stock by making the appropriate call to the inventory service.

Moltin platform will do this automatically when we have addressed the events handling around stock allocation - alas this is not the case right now but it is on the roadmap.

We will announce this change prior to its release (otherwise people will find they are allocating more stock than necessary!).

Hope this information helps.

Regards,

Ian


#6

Is this possible with just an implicit access token? I’d like to decrement the stock when loading a confirmation page in my frontend (given that an order actually occured).


#7

No - this requires client credentials.


#8

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.