Recipe: let another system set stock by SKU

Goal: your ERP or warehouse sends { "sku": "ABC", "quantity": 12 } to a URL, and the workflow sets the available quantity of that variant.

Template: Let another system set stock by SKU (category Data sync). Steps: 5. Needs: access to products, inventory and locations.

Create it

  1. In Browse templates, search for SKU and select Use template on Let another system set stock by SKU.
  2. Select the trigger. Copy the Webhook URL from the panel and give it to the other system. Treat it like a password: anyone who has it can start this workflow. See Incoming webhooks.

How it is built

Step Setting
Trigger Incoming webhook
Find the variant by SKU (Shopify query) Searches productVariants for the SKU of the request
Condition: A variant was found steps.variant.output.productVariants.nodes.0.id has a value
Then: Read the first location (Shopify query) The store's first location
Set inventory quantity Inventory item id and Location id from the two queries, Quantity {{ event.payload.body.quantity }}, Reason Correction
Otherwise: Fail the run No variant has the SKU {{ event.payload.body.sku }}

The first query's Variables (JSON) turn the SKU into a search:

{ "q": {{ event.payload.body.sku | prepend: "sku:" | json }} }

The Fail the run step is what makes this workflow trustworthy: a SKU that does not exist does not pass silently. The run ends as Failed with a message that names the SKU, and you get the failure alert.

Make it yours

  1. Several locations? The template uses the first location of the store. Delete the step Read the first location and put a fixed Location id into the last step, or let the other system send the location and read it from event.payload.body.
  2. Test as a preview. Put a real SKU into the Event (JSON):
{ "body": { "sku": "ABC", "quantity": 12 } }

Both queries run for real, the quantity is only previewed. Then try a SKU that does not exist: the run takes the Otherwise branch and fails with your message.

  1. Save and Turn on. A workflow that is off answers the other system with an error.

Try it from a terminal

The trigger panel has an Example request to copy. It looks like this, with your URL:

curl -X POST "<your webhook URL>" \
  -H "Content-Type: application/json" \
  -d '{ "sku": "ABC", "quantity": 12 }'

The answer is 202 with started: true. It comes at once and does not wait for the run. Find the run under Run history.

Many SKUs at once

One request per SKU is simple, and each is one run. For a whole stock list, two other ways cost fewer runs:

  • Send a list in one request, for example { "items": [ ... ] }, and wrap the steps in a Repeat for each over {{ event.payload.body.items }}. Up to 500 items per run; an item whose SKU is unknown fails only that item when the loop is set to Go on with the next item.
  • Let the other system drop a CSV file on an SFTP server. The template Set stock from a daily CSV file on your SFTP server reads it on a schedule.

The endpoint accepts up to 120 requests per minute and 256 KB per request.

  • Let another system set prices by SKU - the same shape with Update variant price.
  • Let another system tag and annotate orders - finds an order by its number, adds tags and a note.

See also Recipe: send new orders to an ERP for the other direction.