Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Time based actions performed by custom app

Solved

Time based actions performed by custom app

AdvaAlex
Shopify Partner
6 0 1

Hello there,

 

Our company is currently developing a custom app which will connect a merchant's shop to our fulfillment API (receiving orders works fine via webhooks).

Now we would like to be able to update stock level information periodically.

As far as I know, there are two possible ways of doing so:

  • Use the admin API to update stock levels explicitly, or
  • Create a custom fulfillment service which will handle "fetch_stock" requests sent by Shopify

The first approach doesn't seem to be proper, as we would have to update the stock levels of hundreds of products and admin API calls are limited to 40 requests per minute. At least the examples shown in the API documentation seem to only allow to update one inventory item per request (are batch updates allowed?).

 

The second approach would be our way to go but unfortunately we cannot be sure, that merchants have maintained the SKU for their product variants (and this approach uses the SKU to fetch stock levels).

 

So our idea is to implement a mechanism in our custom app which will call our API periodically in order to update stock levels. Does Shopify provide some kind of cron job or time based actions for installed custom apps?

 

Thank you very much in advance.

 

Alex

Accepted Solution (1)

ShopifyDevSup
Shopify Staff
1453 238 519

This is an accepted solution.

Hey @AdvaAlex - I am able to confirm that we don't offer a cron/scheduled job that would update stock levels automatically, but this is a really good question. In terms of some methods you could use to achieve something similar to a scheduled task, the best answer at the moment would still be with webhooks, at least for the inventory level tracking. 

There is a suite of inventory item/level webhook subscription topics (starting in this list here) which could help with tracking inventory updates. You could use the webhooks to trigger the logic on your custom fulfillment service's end to create some basic "bulk" mutations to make the app's ability to carry out these stock level updates a bit more performant. 

 

There are a few nearly-production ready examples here in one of our partner developer articles that might give you some starter points to work with. The dev docs for the InventoryItem object in GraphQL also have some good insights and tips/examples. 

Hope this helps!

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Replies 2 (2)

ShopifyDevSup
Shopify Staff
1453 238 519

This is an accepted solution.

Hey @AdvaAlex - I am able to confirm that we don't offer a cron/scheduled job that would update stock levels automatically, but this is a really good question. In terms of some methods you could use to achieve something similar to a scheduled task, the best answer at the moment would still be with webhooks, at least for the inventory level tracking. 

There is a suite of inventory item/level webhook subscription topics (starting in this list here) which could help with tracking inventory updates. You could use the webhooks to trigger the logic on your custom fulfillment service's end to create some basic "bulk" mutations to make the app's ability to carry out these stock level updates a bit more performant. 

 

There are a few nearly-production ready examples here in one of our partner developer articles that might give you some starter points to work with. The dev docs for the InventoryItem object in GraphQL also have some good insights and tips/examples. 

Hope this helps!

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

AdvaAlex
Shopify Partner
6 0 1

Hi @ShopifyDevSup ,

 

Thank you very much for your links.

 

The webhooks you've mentioned seem to notify us when something happened with the inventory tracking of product variants (e.g. tracking has been enabled / disabled or updated). I think this might help when setting up inventory tracking in a shop as this might reduce the risk of exceeding the rate limits.

 

We stumbled upon GraphQL bulk updates (e.g. via "InventoryBulkAdjustQuantitiesAtLocationMutation") and letting Shopify update the stock level by itself by creating a fulfillment service.

 

Both works. We tried both approached and decided to go for the latter (and let Shopify update the stock levels by calling our "fetch_stock.json" endpoint - honestly to avoid running into the rate limits 😉

 

Thanks

 

Alex

 

PS: I'm marking your answer as solution as it points to a way that works.