ClinicRail Developers

Overview

Developers

Bring the intake to your customers in the way that suits your site, and follow every order from your own systems.

Start with links that need no code, put the intake on your own page, or run the whole flow from your server. Our API starts intakes and tells you where each order is; webhooks send every change to you as it happens.

Everything lives in your partner portal, under Developers: your API address, keys, the embed script, webhook addresses and every delivery we've made to them.

Choose how to start →

Essentials

Three ways to start

  1. Start links, no code. Each program you offer has its own link in your partner portal, under Links. Put it on your site, in an email or behind a button: it opens the intake in your branding.
  2. The intake on your own page. Your server starts an intake with the API, then your page shows it with our embed script.
  3. Your own flow. Your server starts an intake and sends the customer to its hosted_url.

API keys

Your team's admins create keys in the partner portal, under Developers. Send one with every request, from your server only, never from a browser or an app.

Header
Authorization: Bearer pk_live_yourbrand_…

Test keys work exactly the same way; use them while you build. A key is shown once, when it's made. If one is ever exposed, revoke it in the portal and make another. Requests and answers are JSON, and paths below are relative to your API address, shown in the portal.

GET/v1/programs

The programs switched on for you, with the keys you'll use to start them.

Response
[
  {{ "program_key": "weight", "title": "Weight loss", "consult_price_cents": 4000, "provinces": ["LA"] }}
]

POST/v1/intake-sessions

Starts an intake for one customer. external_customer_id is optional: your own reference, sent back to you in webhooks.

Request
{{ "program_key": "weight", "external_customer_id": "cust_1042" }}
Response
{{
  "session_id": "…",
  "client_token": "…",
  "hosted_url": "https://…/intake/…#t=…",
  "expires_at": "…"
}}

A session lasts two hours, so start one when the customer is ready, not ahead of time.

GET/v1/orders/{{order_ref}}

Where an order is now. You get the order_ref from the embed's intake:completed event and from webhooks.

Response
{{ "order_ref": "…", "coarse_status": "in_progress", "updated_at": "2026-11-25T10:42:00Z" }}

Order statuses

You see where an order is, never what the patient told us.

in_progressWith our clinicians or the pharmacy.
needs_patient_actionWaiting on the customer: to answer a clinician's question, or to pay for their medication.
fulfilledDelivered; refills carry on from here.
closedFinished, or treatment wasn't right for them.

Errors

401The key is missing, wrong or revoked.
403The key isn't allowed to do this.
404There's no such order, or the program isn't switched on for you.
429Too many requests. Wait a moment and try again.

Receiving events

Add an HTTPS address in the partner portal and we'll POST each change of an order's status to it, as it happens. Send yourself a test from the portal: it arrives as a ping event.

POST to your address
{{
  "id": "6f1c…",
  "type": "order.status_changed",
  "created_at": "2026-11-25T10:42:00.000Z",
  "data": {{
    "order_ref": "…",
    "coarse_status": "needs_patient_action",
    "session_id": "…",
    "external_customer_id": "cust_1042"
  }}
}}

Every request carries three headers: ClinicRail-Signature, ClinicRail-Event and ClinicRail-Delivery.

Verifying signatures

Check the signature before you trust a request. It's t=<unix seconds>,v1=<hex HMAC-SHA256 of "t.body">, made with your address's signing secret, which is shown once, when you add the address.

Node.js
import crypto from 'node:crypto';

// body: the raw request body (a string), before you parse it.
export function fromClinicRail(secret, body, header) {
  const parts = Object.fromEntries(header.split(',').map((p) => p.split('=')));
  const t = Number(parts.t);
  if (!t || Math.abs(Date.now() / 1000 - t) > 300) return false; // older than 5 minutes
  const expected = Buffer.from(crypto.createHmac('sha256', secret).update(`${t}.${body}`).digest('hex'));
  const given = Buffer.from(parts.v1 ?? '');
  return expected.length === given.length && crypto.timingSafeEqual(expected, given);
}

Retries and duplicates

  • Answer with any 2xx within 10 seconds. Anything else is retried 8 times over about a day, then given up; you'll see each attempt in the portal.
  • The same event can arrive more than once: use id to skip ones you've already handled.
  • Events can arrive out of order: if it matters, ask the API for the latest status.

The intake on your page

Start an intake from your server, then put it on your page with our script. The embed script's address is in your partner portal.

HTML
<script src="{{embed address from your partner portal}}"></script>
<care-intake src="{{hosted_url}}"></care-intake>

<script>
  document.querySelector('care-intake').addEventListener('intake:completed', (e) => {{
    // e.detail.orderRef: keep it to match updates to this customer
  }});
</script>

Your page hears intake:started, intake:step, intake:completed (with the orderRef) and intake:error, and never what the customer answered.

Questions? Write to support@clinicrail.com. © ClinicRail