PPact
Developers

Commerce API

Set up a product catalog, a hosted shop, and take orders that Finance invoices, through the Commerce API.

Commerce lets a workspace sell from its own product catalog: categories, products with variants, price books, and a simple hosted shop. A shopper's checkout records an order, and Finance gets a draft invoice for it at the same moment. No card is charged: the buyer pays the invoice.

Commerce is a module. It works only on a workspace that has it turned on. A Field Rep seat, or a workspace that has only Field, can't open it.

Who can use it

  • Anyone in the workspace who can read accounts can read Commerce.
  • Only an owner or admin can change the catalog, variants, price books and shops. These are the same products and prices your quotes use.
  • Anyone who can change accounts can fulfil orders, handle returns and link an order to a contact. A Viewer can't.
  • Every change is written to the audit log.

Set up the catalog

All staff routes are under /v1/commerce and take your usual sign-in. Every id in a request or an answer is a public id (a UUID).

  1. Create a category with POST /v1/commerce/categories. Categories go one level deep: a category can have a parent, but the parent can't have one.
  2. Create a product with POST /v1/commerce/products. Give it a name, a price_cents and a currency. A sku is optional. To sell it in your shops, set "sold_online": true.
  3. If the product comes in sizes or colours, add variants with POST /v1/commerce/products/{product_id}/variants. A variant can have its own SKU, price and stock_on_hand. SKUs are unique across your workspace.
  4. Optionally, create a price book with POST /v1/commerce/price-books and set its prices with PUT /v1/commerce/price-books/{price_book_id}/entries.

Which price a shopper sees

  1. A variant's own price, if it has one.
  2. Otherwise the shop's price book price for the product, if the shop has a price book and the book prices it.
  3. Otherwise the product's list price.

A shop sells a product only when it's active and sold_online is on. It's off unless you turn it on, so a product you made for quotes never shows up in a shop. A product with active variants is sold only as one of them. An inactive product or variant isn't for sale.

Open a shop

  1. Create a storefront with POST /v1/commerce/storefronts. Give it a name and, optionally, a slug, a price book, a currency, a tagline and an accent colour. The slug is the shop's public address, and it must be free across all of Pact.
  2. Publish it with PATCH /v1/commerce/storefronts/{storefront_id} and "is_published": true. A draft shop isn't visible to anyone.

You can't delete a shop that has taken orders.

Shop limits

A shopper pays by invoice, so checkout takes stock before anyone has paid. Three settings on the storefront keep one shopper from emptying your shelves:

SettingDefaultWhat it does
max_line_quantity10The most of one item a cart can hold (1 to 999).
max_order_quantity25The most items in one order (1 to 9,999).
hold_days7How long an unpaid order holds its stock (1 to 90 days).

A line over a limit answers 400 too_many. Lowering a line always works, so a shopper can get back under a limit you lowered after they filled the cart. When an order is still unpaid and unfulfilled after hold_days, and you haven't sent its invoice or opened a return on it, Pact cancels it, puts the stock back and voids the draft invoice. This happens the next time someone opens the shop or you open your order list.

What a shopper's browser calls

The public routes are under /v1/shop/{slug}. They need no sign-in and are rate limited per IP address.

RouteWhat it does
GET /v1/shop/{slug}The shop's name, categories and products, priced by its price book.
GET /v1/shop/{slug}/products/{product_id}One product.
POST /v1/shop/{slug}/cartsOpens a cart. The answer's cart_token is shown once.
GET /v1/shop/{slug}/cartThe cart. Send the token as the X-Cart-Token header.
PUT /v1/shop/{slug}/cart/itemsSets one line's quantity. 0 removes it.
POST /v1/shop/{slug}/checkoutPlaces the order with the buyer's name, email and shipping address.
GET /v1/shop/{slug}/orders/{order_id}The buyer's order status. Send the checkout's status_token as the X-Order-Token header.

The order status answers the order's number, placed_at, fulfillment_status, payment_status (pending until its invoice is paid, then paid), paid_at, fulfilled_at, cancelled_at, the total and each line's name, quantity and prices. It never includes the shipping address, the email or the invoice.

A draft shop, an unknown address and a workspace that no longer has Commerce all answer 404, so they can't be told apart. Pact stores only a hash of each cart and order token. A cart expires 30 days after its last change.

At checkout Pact re-reads every price in the shop's current currency, takes tracked stock (a sold-out line answers 409 out_of_stock), and closes the cart, so a second submit places no second order.

Fulfil an order

Orders from your shops are under GET /v1/commerce/orders. Move one forward with POST /v1/commerce/orders/{order_id}/fulfillment and a status. The steps are unfulfilled, provisioning, fulfilling, fulfilled and closed, which the Commerce screens call Unfulfilled, Preparing, Packing, Shipped and Delivered. You can skip a step but can't go back, and you can cancel (cancelled) until the order is closed. Cancelling puts tracked stock back, and is refused while a return on the order is still open.

With fulfilled you can also send a carrier and a tracking_number. Pact writes them into the order's fulfillment_note ("Shipped with … Tracking number …"); sending either with another status answers 400 shipping_needs_shipped. The shopper's order status link shows the step, never the note.

Each order's events is its history. A row names who made the change in actor_name (their display name), or null when nobody signed in did, such as checkout. It never carries a user id.

A shop order isn't linked to a contact or account on its own, because anyone can type a customer's email at checkout. When the email matches exactly one contact, the order shows it as suggested_contact_id. Once you've checked, link it with POST /v1/commerce/orders/{order_id}/contact and {"contact_id": "..."}, or send null to unlink it. The order's draft invoice moves to the same account; an invoice you've already sent stays as it was.

Handle a return

  1. Open a return with POST /v1/commerce/orders/{order_id}/returns, naming the lines and quantities. You can't return more than was bought, counting returns that are still open.
  2. Move it with POST /v1/commerce/returns/{return_id}/status: Requested, then Approved, then Received, then Closed. A requested return can also be Rejected.
  3. When a return is Received, Pact puts the stock back.

A return only asks for a refund (refund_cents_requested). Finance issues the refund, and you record its reference when you close the return. See Refunds.

What Commerce doesn't do yet

Card payments, shipping rates, automatic tax, discount codes, product images and order emails aren't part of this version.

Commerce API — Pact Docs · Pact