Connecting a shop
A web shop sells; Foudra makes, stocks and ships. This page is the contract any storefront integration follows, whatever the shop runs on. Two follow it already: Foudra's own Shopify integration, built in, and solidus_foudra (on RubyGems), a Rails engine Kalopa Robotics wrote for its own Solidus shop. Read either beside this page.
Who owns what
Foudra keeps the physical facts, never money, and has no storefront.
- Foudra owns what is listed for sale on the shop, its stock, and shipping. The shop shows Foudra's available stock, never its own idea of it, and marks as shipped what Foudra says left.
- The shop owns the storefront, the checkout, payments, tax, promotions, and its customers' accounts.
- Prices are information. A listing's price travels to the shop because that is where it is kept, and an order's prices travel back to Foudra as a record of what the customer was charged. Nothing in Foudra charges a customer, issues an invoice or books money: that is the shop's and the accounts'.
- Nothing is deleted. Unlisting a part discontinues the shop's product; cancelling an order in the shop cancels in Foudra what hasn't shipped.
What the company sets up
- A channel for the shop (Sales channels): its code,
SHOPsay, is how the integration names it in every call. - An API key with the
writescope, made by a user who is at least a planner: customers and sales orders need that role. See API keys. - A webhook to the shop's receiver, with the events below. Its signing secret is shown once.
- Listings: each part the shop sells, listed on the channel with its price.
Part numbers and SKUs
The part number is the join between a shop's product and a Foudra part. Use Foudra's canonical form, dashed (902-040169-00), whatever the company shows: it never changes with the company's display settings. The shop's SKU is the customer's and needn't be the part number; record it on the listing as channel_part_number, so Foudra's people can find the product and Foudra shows the listing as pushed.
| Call | For |
|---|---|
GET /api/parts?part_number=902-040169-00 |
A part by its exact number, display or canonical form; none, or the one part |
GET /api/parts/{id} |
Its name, description (Markdown), status (is_active), and available |
GET /api/parts/{id}/images |
Its images, primary first. Skip those marked from_category: they are its category's, not a picture of the part |
Listings and prices
GET /api/channels/SHOP/listings is every part on the channel, listed or not, unpaged: id, part_id, part_number, part_name, part_is_active, is_listed, price, currency, channel_part_number. ?part_id= narrows it to one part's row.
- Listed, and the part is active: the shop sells it, at
priceincurrency. A listing with no price, or a price in another currency, leaves the shop's price alone. - Not listed, or the part archived (
part_is_activefalse): the product is discontinued, never deleted. Orders point at it. - A product already in the shop with the part's number is adopted, never duplicated.
PUT /api/channels/SHOP/listings/{part_id}with{"channel_part_number": "KRT-XL"}records the shop's SKU. Send it only when it differs: every change to a listing raiseslisting.changed.
Sales orders
A completed order becomes a Foudra sales order on the channel. POST /api/sales-orders:
{
"channel": "SHOP",
"channel_order_ref": "R123456789",
"customer_id": 41,
"customer_reference": "R123456789",
"ordered_at": "2026-11-23",
"wanted_at": "2026-11-23",
"currency": "EUR",
"ship_to": {"name": "Ann Smith", "line1": "1 Quay St", "city": "Galway", "postcode": "H91 X2Y3", "country": "IE"},
"lines": [{"part_number": "902-040169-00", "quantity": "1", "unit_price": "249.00"}]
}
- Idempotent by
channelandchannel_order_ref: the same order sent again returns the one already made, and makes nothing. Send anIdempotency-Keyas well (shop:order:R123456789), so a retry gets the first answer back. - A line names its part by
part_number,part_id, or the channel's ownchannel_part_number. An unknown number refuses the whole order (422), naming the line. - Leave out lines for what Foudra doesn't make or stock: gift cards, services.
unit_priceis what the customer was charged per unit, before order-level discounts, as the shop shows it (with VAT if the shop's prices include it). Information only.GET /api/sales-orders?channel=SHOP&channel_order_ref=R123456789asks whether an order is already here.- Cancelling in the shop:
POST /api/sales-orders/{id}/cancel, with anIdempotency-Key. What hasn't shipped stops being demand; an order that has all shipped answers 409 and is left as it is.
Customers and their ids in the shop
Customers are kept thin: who they are and where things go, and their id in each channel.
GET /api/customers?channel=SHOP&channel_ref=1234finds the customer the shop knows as 1234. A guest checkout has no account id:GET /api/customers?email=finds them by address (exact, any case). Skip archived customers.POST /api/customersmakes one (name,email,phone,billing_address,shipping_address), with"channel_refs": [{"channel": "SHOP", "ref": "1234"}]to record the shop's id;PUT /api/customers/{id}adds one later. A ref already given to another customer moves to this one.- Each customer's JSON carries its
channel_refs. - Don't overwrite a customer that is already there: Foudra's people may have edited it, and each order carries its own
ship_to.
Available stock
A part's available is on hand, across every location, less what open orders have committed: what may be sold. Set the shop's count to it, rounded down, never below zero. Read it again when told to (below), and in a nightly pass over every part (GET /api/parts?page=&per=100), because a webhook can be missed.
A per-channel figure, counting only the locations that stock the shop, is not in the API yet: every location counts.
Webhooks
Subscribe the shop's receiver to:
| Event | Then |
|---|---|
stock.changed |
Read data.part.id's part again and set its stock |
sales_order.created, sales_order.cancelled |
Committed stock moved: read each data.lines[].part.id again and set its stock |
listing.changed |
Read the listing (?part_id=data.part.id) and the part again; create, update or discontinue the product. data.change is created, updated or removed |
shipment.shipped, shipment.updated |
Read data.shipment.id's shipment and its sales order again; ship the shop's order or correct its tracking |
ping |
Nothing: it is the Send test button |
An event is a nudge, never data: always read the present from the API, because events arrive late, twice, or out of order. Keep only the ids it names; shipment and sales order events carry customers' names and addresses, which have no business in a job queue.
Every delivery is signed. X-Foudra-Signature is t=<unix time>,v1=<hex HMAC-SHA256>, keyed with the signing secret, over <t>.<body> with the body exactly as received. Compare in constant time, refuse a t more than five minutes from now, remember the event ids you have handled and answer a repeat with 204, and answer within ten seconds, doing the work afterwards. Webhooks has a receiver to copy.
A sales order line changed through the API (PUT /api/sales-orders/{id}/lines/{line}) moves committed stock without any event: the nightly pass catches it.
Shipping
Foudra ships; the shop is told. On shipment.shipped, GET /api/shipments/{id}: its status is shipped, its sales_order_id leads to the order, whose channel and channel_order_ref name the shop's order. Ship, in the shop, as many of each line's part_number as the shipment's quantity, with its tracking_number, so the shop sends the customer its "on its way" email. Record the shipment's number on what you ship: a repeat finds it and only corrects the tracking (shipment.updated), without a second email. Don't ship in the shop's own admin: Foudra wouldn't know.
The nightly pass asks, for each recent order not yet shipped in the shop, GET /api/shipments?sales_order_id=&status=shipped.
Failures
429 and 5xx are worth retrying with growing pauses, honouring a Retry-After when there is one; a request with an Idempotency-Key is always safe to send again. 401, 402 and 403 need a person (the key, the subscription, the role); 404 and 422 won't change on a retry. Log the path, never the query: emails go in queries.