Skip to main content
Create an offer with createOffersWorkflow when you list products for a store outside the Vendor panel, for example in a custom route, a seed script, or an import job.

Before you begin

You need these records in place:
  • A store: its seller_id and the id of a member to record as created_by
  • A master variant: the variant_id the store will sell
  • A shipping profile: one that belongs to the store
  • A stock location: where the starting stock is held

Create the offer

1

Add a route that runs the workflow

Create an API route that runs createOffersWorkflow with one offer.
src/api/admin/custom/offers/route.ts
The workflow returns the created Offer rows. The one inventory_items entry becomes a new inventory item with 50 units at the location.
2

Know what the run wires up

One run does more than insert the row:
  • Inventory: creates an InventoryItem per entry, links it to the offer with its required_quantity, and links it to the store
  • Prices: adds each price to the variant’s price set with an offer_id rule and links it to the offer
  • Barcodes: copies ean and upc from the variant when you leave them out
  • Shipping: links the master product to the shipping profile if the product has none
  • Event: emits offer.created with { id, product_id }
3

Read the offer back with its links

Query the offer with its prices and stock to confirm the result.
prices reads the offer’s own rows on the shared price set. inventory_item_link returns the pivot rows, so you get required_quantity with each item.

Set selling terms and a condition

The offer accepts optional fields beyond the required ones. Add them to the same entry:
condition_id must point at an active offer condition. manage_inventory defaults to true, allow_backorder to false, and leadtime_to_ship to null.

Attach custom data with additional_data

Pass additional_data to the run to hand extra values to the offersCreated hook. Use it to store data from your own module next to the offer.
src/workflows/hooks/offers-created.ts
The hook receives the created offers with their prices loaded. Run the workflow with additional_data: { source: "erp" } to see the value in the handler.

Handle a failed run

The workflow validates the whole input and rolls back on failure. Compensation removes the inventory items, prices, and links it already created. A run fails when:
  • A variant doesn’t exist: Variant with id … was not found
  • An offer has no inventory items: Offer must have at least one inventory item
  • A condition is unknown or inactive: Offer condition … is not active or not found
  • A SKU is taken in the store: the (seller_id, sku) unique index rejects the insert

Next steps