Black Friday / Cyber Monday:30% off yearly plans, up to 15% off monthly.Ends Monday, Nov 30 at 11:59 pm ETSee the prices

← Resources

Guide · Updated November 11, 2026

Connect your website to TFM Manufacturing: a step-by-step API guide

Show live stock on your product pages, send orders in when customers check out, and show order status and tracking. Every step has code you can copy, and you can test each one as you go.

Download PDF

This guide takes you from no connection to a website that shows live stock, sends its orders in and shows tracking. If you or your developer can add a little code to your website's server, it's an afternoon's work. You can stop after any step: each one works on its own.

Looking for every field and error? That's the API reference. This guide is the walkthrough.

What you can connect

  • Stock status on product pages: "In stock", "Made to order: 4-6 weeks" or "Out of stock", from your real inventory.
  • Orders in: when a customer checks out, the order appears in your sales orders. Units on the shelf are reserved for it and the rest go on the build list.
  • Product pages: names, prices, photos (including photos for one option), descriptions and your website shop settings.
  • Order status and tracking out: your site can show "In production", "Shipped" and the tracking number.
  • A customer portal: signed-in customers can also see the orders you entered for them in the app.
  • Instant updates (Custom plan): webhooks tell your site the moment stock or an order changes.

Before you start

  • A plan with the API: Ultra (100,000 requests a month), Custom, or Growth with the API add-on (25,000 a month). Change it in Settings → Billing.
  • An owner or admin login. Only they can create API keys.
  • A SKU on every product variant in TFM Manufacturing that matches the SKU on your website. The SKU is how the two systems recognise the same product.
  • A place to run server code: your website's backend, or a small serverless function (Vercel, Netlify, Cloudflare and similar all work). A key that can create orders must never be in code that runs in the browser.

Step 1: Create an API key

  1. In the app, open Settings → Integrations → API keys and press Create key.
  2. Name it after where it will be used, for example "Website server".
  3. Under Access, keep only what this key needs. All four are ticked to start.
  4. Press Create and copy the key straight away. It starts with tfm_ and is shown only once: we keep only a fingerprint of it, so we can't show it again.
  5. Save it on your server as a secret or environment variable named TFM_API_KEY. Never paste it into your website's code or repository.

What each kind of access lets the key do:

  • Read stock status (inventory:read): stock status and lead time by SKU.
  • Read products (products:read): names, variants, prices, photos and stock status.
  • Create orders (orders:write): send orders in. Server only.
  • Read orders (orders:read): order status, shipments and tracking.

Tip: if a key is ever exposed, press Revoke next to it and create a new one. Nothing else needs to change.

Step 2: Check the key works

Run this in a terminal (on Windows, use PowerShell or Git Bash), with your key in place of the example:

curl https://twelfthfretmfg.com/api/v1/ping \
  -H "Authorization: Bearer tfm_your_key_here"

You should get back something like this:

{
  "ok": true,
  "workspace_id": "…",
  "plan": "growth",
  "scopes": ["inventory:read", "orders:read", "orders:write", "products:read"]
}

A 401 means the key was copied wrongly or has been revoked. A 402 means the workspace's subscription isn't active.

Step 3: Show stock status on product pages

Ask for one or more SKUs (up to 200, separated by commas) and show a label for each. This code runs on your server and keeps each answer for a minute, so busy pages stay well inside your rate limit (120 requests a minute on Starter, 600 on Growth):

// Server code (Node 18 or later). TFM_API_KEY needs "Read stock status".
const BASE = 'https://twelfthfretmfg.com/api/v1';
const cache = new Map();

export async function stockFor(skus) {
  const key = skus.join(',');
  const hit = cache.get(key);
  if (hit && Date.now() - hit.at < 60_000) return hit.data;
  const res = await fetch(`${BASE}/inventory?sku=${encodeURIComponent(key)}`, {
    headers: { Authorization: `Bearer ${process.env.TFM_API_KEY}` },
  });
  if (!res.ok) throw new Error(`TFM API answered ${res.status}`);
  const { data } = await res.json();
  cache.set(key, { at: Date.now(), data });
  return data;   // one entry per SKU found: { sku, available, stock_status, lead_time, price, … }
}

export function stockLabel(item) {
  if (!item) return '';   // SKU not found: check it matches TFM Manufacturing
  if (item.stock_status === 'in_stock') return 'In stock';
  if (item.stock_status === 'made_to_order') return `Made to order: ${item.lead_time}`;
  return 'Out of stock';
}

What the three statuses mean:

  • in_stock: ready to ship. available is how many units are free to sell.
  • made_to_order: none on the shelf, but it can be ordered. lead_time is the lead time you set on the product or variant.
  • out_of_stock: none on the shelf and no lead time set. Don't take orders for it.

If the API can't be reached, show the page without the stock line rather than blocking the sale.

Product pages

GET /v1/products returns everything a product page needs: name, description, photos, variants with prices and stock status, and the Website shop settings from the product's page in the app (option order, sort order, most per order, deposit, a "buy elsewhere" link, extra choices such as a colour, and a title or description per option). Photos you set to Only for… one option come back in option_images, so your page can switch photos when that option is picked.

  • Descriptions can contain HTML. Clean it with an HTML sanitizer before showing it.
  • Each variant's made_to_order_lead_time is its lead time whenever one is set, even while some are in stock. Use it to take orders beyond the stock on hand. lead_time is only filled in when it's out of stock.
  • Page addresses are yours to choose. A common choice is the product name in lower case with dashes: "Studio Racks" becomes /product/studio-racks.

Prefer to call it from the browser? Create a separate key with only Read stock status (and Read products if you need them). Browsers can read stock that way, but anyone can see that key, and with it your stock levels.

Step 4: Send orders in when customers check out

Send the order from your server once the payment has gone through, for example where your site sends its order confirmation email, or in your payment provider's "payment succeeded" webhook.

// Server code. TFM_API_KEY needs "Create orders".
export async function sendOrderToTfm(order) {
  const res = await fetch(`${BASE}/orders`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${process.env.TFM_API_KEY}`,
      'Content-Type': 'application/json',
      'Idempotency-Key': `website-order-${order.number}`,
    },
    body: JSON.stringify({
      external_id: String(order.number),   // your order number
      customer: { name: order.customerName, email: order.customerEmail },
      shipping_address: order.shippingAddress,
      items: order.lines.map((l) => ({ sku: l.sku, quantity: l.quantity, unit_price: l.price })),
      shipping: order.shippingTotal,
      tax: order.taxTotal,
      payment: { amount: order.amountPaid, method: 'Stripe', reference: order.paymentId },
    }),
  });
  const body = await res.json();
  if (!res.ok) throw new Error(`${body.error.code}: ${body.error.message} (${body.error.request_id})`);
  return body;   // the order: id, order_number, status, items, …
}

Things that make this reliable:

  • external_id is your order number. Sending the same order twice never creates two orders: the second time you get the first one back.
  • Retry on failure. If the request fails (no connection, 429 or a 5xx), try again later with the same Idempotency-Key. A simple way: mark each order "sent to TFM: yes/no" on your side and have a scheduled job resend the "no"s every few minutes.
  • Don't retry 400 errors unchanged. The message says what to fix, for example "No product with SKU KOA-WAL." when a SKU doesn't match.
  • payment records what the customer paid, so the order's balance is right. If you use QuickBooks, the method decides which account the payment goes to: a word containing "cash" uses your cash account, "bank" or "check" your bank account, anything else (Stripe, PayPal, card) your card payments account. Paid before the order ships, it's held as Unearned revenue in QuickBooks until the shipment's invoice.
  • unit_price is what the customer paid per unit. Leave it out to use the price in TFM Manufacturing.
  • Keep your own copy of the customer's details. We keep the order's customer and shipping_address only while you're working on it: 30 days after it's shipped, delivered, cancelled or refunded (with nothing still owed), we delete them. The rest of the order stays, including your external_id. Don't put customer details in notes or metadata: those are kept.

The order now appears in Sales orders in the app. Its status follows automatically as you build and ship.

Step 5: Show order status and tracking

Look the order up by your own order number:

// Server code. TFM_API_KEY needs "Read orders".
export async function tfmOrder(orderNumber) {
  const res = await fetch(`${BASE}/orders/by-external-id/${encodeURIComponent(orderNumber)}`, {
    headers: { Authorization: `Bearer ${process.env.TFM_API_KEY}` },
  });
  if (res.status === 404) return null;
  const order = await res.json();
  return {
    status: order.status,   // awaiting_build, in_production, preparing_shipment, partially_shipped, shipped, delivered, cancelled, refunded
    tracking: order.shipments.map((s) => ({ carrier: s.carrier, number: s.tracking_number })),
  };
}

A shipment's tracking_number is empty when the order was handed over instead of shipped: carrier is then Local pickup, Delivered by us or Installed, so show that and leave tracking out.

Words customers understand: awaiting_build "Order received" (nothing started yet), in_production "Being made", preparing_shipment "Getting ready to ship", partially_shipped "Part of your order has shipped", shipped "Shipped", delivered "Delivered".

To keep your own copy of every order up to date instead, call GET /v1/orders?updated_since=… every few minutes with the time of your last check.

Orders you entered in the app (a customer portal)

Orders you type in yourself (a phone order, a custom job) can show in your customer's account on your website too. Ask for a customer's orders by email:

// Server code. TFM_API_KEY needs "Read orders". Only pass an email the customer has confirmed is theirs
// (for example, your login system's "email verified" flag), or anyone could sign up with someone else's address.
export async function ordersEnteredForCustomer(confirmedEmail) {
  const q = new URLSearchParams({ customer_email: confirmedEmail, source: 'manual', kind: 'order', limit: '10' });
  const res = await fetch(`${BASE}/orders?${q}`, { headers: { Authorization: `Bearer ${process.env.TFM_API_KEY}` } });
  if (!res.ok) throw new Error(`TFM API answered ${res.status}`);
  const want = confirmedEmail.trim().toLowerCase();
  // Belt and braces: show only orders that really carry this email.
  return (await res.json()).data.filter((o) => (o.customer_email ?? '').trim().toLowerCase() === want);
}
  • customer_email matches the order's email (upper or lower case doesn't matter) or the email of the saved customer it's linked to. A blank email is refused.
  • source=manual means entered in the app (api means sent by your website), and kind=order means sales orders, not work orders.
  • Type customers' emails carefully on orders you enter: whoever owns that address will see the order.

Let customers pay what they still owe

Orders with money still owed (a deposit order, or a sales order you entered) can be paid from your website. Your server works out the balance from the order (total minus amount_paid, never a number sent by the browser), takes the payment with your payment provider, then records it here. If the order has a deposit_due (the deposit you asked for on the sales order), you can also offer just the deposit still owed: deposit_due minus amount_paid, when that's above zero.

Your team can change an order's lines in the app after it arrives (add or remove a line, change a quantity or price). So when you show an order to a customer, read its items and total from GET /v1/orders/{id} rather than what was sent at checkout: an added line has a new id, and a removed one is no longer listed.

// Server code, after the payment succeeded. TFM_API_KEY needs "Create orders".
export async function recordPayment(orderId, amount, paymentId) {
  const res = await fetch(`${BASE}/orders/${orderId}/payments`, {
    method: 'POST',
    headers: { Authorization: `Bearer ${process.env.TFM_API_KEY}`, 'Content-Type': 'application/json' },
    body: JSON.stringify({ amount, method: 'Stripe', reference: paymentId }),
  });
  const body = await res.json();
  if (!res.ok) throw new Error(`${body.error.code}: ${body.error.message}`);
  return body;   // the order, with amount_paid updated
}
  • The same reference twice is recorded once, so retrying after a failure is safe.
  • A payment is refused if the order was cancelled or it would pay more than is due (for example the customer paid twice from two tabs). Refund that one with your payment provider.

Step 6: Get told when things change (Custom plan)

Instead of asking every few minutes, let us tell your site. Your server needs a public https address that accepts a POST, for example https://your-site.com/webhooks/tfm. (We can't send to your own computer: test on a deployed preview of your site.)

  1. Build the endpoint with the code below and deploy it.
  2. In the app, open Settings → Integrations → Webhooks and press Add endpoint.
  3. Paste the address, tick the events you want, and save.
  4. Copy the signing secret straight away (it's shown once) and save it on your server as TFM_WEBHOOK_SECRET.
// An Express endpoint. Other frameworks work the same way: check the signature on the raw body first.
import crypto from 'node:crypto';
import express from 'express';

function verifyTfmWebhook(rawBody, header, secret, toleranceSeconds = 300) {
  const parts = Object.fromEntries(header.split(',').map((p) => p.split('=')));
  const t = Number(parts.t);
  if (!t || Math.abs(Date.now() / 1000 - t) > toleranceSeconds) return false;
  const expected = crypto.createHmac('sha256', secret).update(`${t}.${rawBody}`).digest();
  const given = Buffer.from(parts.v1 || '', 'hex');
  return given.length === expected.length && crypto.timingSafeEqual(given, expected);
}

const app = express();
app.post('/webhooks/tfm', express.raw({ type: 'application/json' }), async (req, res) => {
  const raw = req.body.toString('utf8');
  if (!verifyTfmWebhook(raw, req.get('TFM-Signature') || '', process.env.TFM_WEBHOOK_SECRET)) return res.status(400).end();
  const event = JSON.parse(raw);
  if (await alreadyHandled(event.id)) return res.status(200).end();   // events can arrive twice
  if (event.type === 'inventory.updated') await refreshStockCache(event.data);
  if (event.type === 'order.shipped') await emailTracking(event.data);
  await markHandled(event.id);
  res.status(200).end();
});

alreadyHandled, markHandled, refreshStockCache and emailTracking are yours to write. The events:

  • inventory.updated: a variant's available quantity, lead time or active setting changed.
  • order.created: an order was created, through the API or in the app.
  • order.status_changed: an order's status changed.
  • order.shipped: a shipment went out or was handed over, with carrier, tracking (empty if handed over) and items.
  • order.refunded: an order was fully refunded.

Answer with a 2xx within 10 seconds. If the work takes longer, save the event, answer, then do the work. We retry failed deliveries with growing gaps for about a day; after 50 failures in a row the endpoint is switched off, and Settings → Integrations → Webhooks shows it as Off with a button to turn it back on. Events can arrive out of order: if you need an order's latest state, fetch it (step 5).

If your site runs on a website builder

There's no plugin to install. Most platforms (Shopify, WooCommerce, Squarespace and others) can send their own "order created" notification to an address you choose, or let you add custom code. The usual setup is a small serverless function in between: it receives your platform's order notification, checks it really came from your platform (each one documents how), and calls step 4. Stock status works the same way through step 3.

Want us to set it up for you? We can, for a one-time fee quoted after a call: contact us.

Before you go live

  • Every variant you sell online has a SKU, and it matches your website exactly (upper or lower case doesn't matter).
  • Your keys are stored as server secrets. The key that creates orders is never in browser code.
  • Failed order sends are retried (step 4).
  • You've sent one test order and seen it in Sales orders. Test orders are real orders in your workspace: cancel it afterwards from the order's page.
  • Custom plan: your webhook endpoint shows Active in Settings → Integrations → Webhooks.

When something goes wrong

Every error has the same shape: a code, a message that says what's wrong, and a request_id.

  • 401 invalid_api_key: the key is missing, mistyped or revoked. Check the Authorization: Bearer tfm_… header.
  • 403 insufficient_scope: the key doesn't have that access. Create a new key with it (a key's access can't be changed), then revoke the old one.
  • 400 invalid_request: something in the request is missing or wrong, and the message says what, such as an unknown SKU.
  • 429 rate_limited: too many requests. Wait the number of seconds in the Retry-After header, and cache stock answers (step 3).
  • 402 subscription_inactive: the workspace's plan isn't active. An owner or admin can fix it in the app.

Settings → Integrations → Integration log lists every API request from the last 30 days with its result and request id. Still stuck? Contact us with the request id (also in every response's X-Request-Id header) and we'll look it up.

APIWebsiteIntegrations

Say goodbye to spreadsheets. Join now.