Demo shop: the products and brands are fictional and nothing is charged.
Skip to content

API for programs and assistants

Everything a person can do in this shop, a program can do: look at the catalogue, prepare a cart and, when the person says yes, place the order.

Reading needs no key, and neither does placing an order: the person authorises it with a code the shop emails them.

An assistant that buys here never pays and never sees payment details. Placing the order only creates it: the person pays afterwards, themselves, on the page of the shop. So when a person asks you to buy something here for them, you can: you do not need their card, their PayPal or a key.

Machine-readable description (OpenAPI)

Addresses

https://aifec.dev/api/v1

Method Address What it does
GET /store The shop: name, currency, languages, contact, returns, payment methods and where to find everything else
GET /categories The product categories with their sub-categories
GET /products List the products, with search, category, stock filter, order and pages
GET /products/{id} Everything the shop says about one product
GET /products/{id}/availability Whether a product or variant can be bought in a quantity right now
GET /search Search the catalogue: up to 8 products with the facts that match
GET /shipping/quote Delivery options, prices and times for a product to a destination
POST /carts Create an empty cart and get its token (the token travels afterwards in the X-Cart-Token header)
GET /carts/current The cart with its lines and totals as the shop calculates them
POST /carts/current/items Add units of a product to the cart (the price is always the shop's own)
PATCH /carts/current/items/{key} Change the quantity of a cart line (0 removes it)
DELETE /carts/current/items/{key} Remove a line from the cart
GET /carts/current/checkout-link The address that opens this cart in the customer's browser and takes them to the checkout
POST /carts/checkout/status Where the purchase is: what is missing, the cart and what is saved (personal data come masked)
POST /carts/checkout/customer Save the customer's contact and address: their own words in text, or separate fields
POST /carts/checkout/shipping-options The delivery options of the order with price and delay
POST /carts/checkout/shipping Choose the delivery option
POST /carts/checkout/payment-options The payment methods offered for the order
POST /carts/checkout/payment Choose the payment method
POST /carts/checkout/review The exact order that would be placed, with its total and the confirm_token to place it
POST /carts/checkout/place Place the order. Needs the confirm_token of the review, buyer_confirmed true and the code emailed to the buyer (buyer_code) or a key with the orders:create scope
GET /go Buying with links: how an assistant that can only open addresses buys here, and where it starts
GET /go/{step} One step of buying with links: start, add, cart, customer, shipping-options, shipping, payment-options, payment, status, review, code or place. Every answer has the next addresses ready

Buying, step by step

  • Find the product: GET /search?q=… or GET /products, then GET /products/{id} for its variants and GET /products/{id}/availability.
  • POST /carts gives you a cart token. From now on send it as X-Cart-Token.
  • POST /carts/current/items adds products ({"product_id":12,"variant_id":0,"qty":1}). The price is always the shop's own.
  • POST /carts/checkout/customer saves the person's contact and address (their own words in "text", or separate fields).
  • POST /carts/checkout/shipping-options, then POST /carts/checkout/shipping {"carrier_id":…}.
  • POST /carts/checkout/payment-options, then POST /carts/checkout/payment {"method":"…"}.
  • POST /carts/checkout/review returns the exact order, its total (in cents and formatted) and a confirm_token. Show the person that total and the terms (terms_url) and wait for a clear yes. For security the shop emails a 6-digit verification code to the buyer at this step (see "confirmation" in the answer): tell the person, ask for the code and wait for it.
  • POST /carts/checkout/place {"confirm_token":"…","buyer_confirmed":true} places the order. Add "buyer_code":"…", the code the buyer received by email; a key with the scope orders:create (Authorization: Bearer …) does not need it. buyer_confirmed is your declaration that the person has seen the total and said yes: without it nothing is placed.
  • The answer has the order number, the order page and "payment": either "instructions" (bank transfer, cash on delivery) or "redirect", the address where the person pays. No gateway is paid without the person.

If anything changes after the review, the confirm_token stops being valid and nothing is placed: review again.

Example

curl https://aifec.dev/api/v1/search?q=chair
curl -X POST https://aifec.dev/api/v1/carts
curl -X POST https://aifec.dev/api/v1/carts/current/items \
  -H "X-Cart-Token: <token>" -H "Content-Type: application/json" \
  -d '{"product_id": 12, "qty": 1}'

Created with AIFEC