# Build on the pathology API, from staging to production

Put pathology ordering and results inside your own product: keys, first request, first referral, webhooks, Medicare providers, then production.

Source: https://eirly.health/support/articles/build-on-the-pathology-api

The path a health company takes to put pathology ordering and results inside its own product: a staging organisation, API credentials, the first request, the first referral, webhooks that tell you when a result is ready, Medicare provider records, then the same setup in production.

- **Cost:** staging is free; production needs an API plan, quoted to your volume.
- **Environments:** staging and production have separate accounts, organisations, billing and keys.
- **Medicare referrals:** API version 1.1.0 or higher.
- **Results:** webhooks tell you something changed; you fetch results through the API.

## Build your integration

For health companies and developers putting pathology ordering and results inside their own product. The full reference is in [Getting Started in the docs](https://docs.eirly.health/api/getting-started).

- [ ] **Create an account, verify, create an organisation**
  Where: [app.staging.eirly.health/signup](https://app.staging.eirly.health/signup)
  The same first steps as in [Try Eirly in staging](/support/articles/try-eirly-in-staging). A verified profile (pick a practitioner type, Other if unsure) is required before an organisation can exist, and all API access is scoped to an organisation.
  Done when: you're on the organisation's Dashboard.
- [ ] **Add the test card**
  Where: Settings, then Billing
  A billing method must be on file before API access can be enabled. Staging accepts Stripe's test card and never charges it.
  Copy (Test card number): `4242 4242 4242 4242`
  Done when: Billing shows a card ending 4242.
- [ ] **Enable the API**
  Where: Settings, then API Keys
  Follow the steps to enable API access. You receive a client_id and a client_secret for staging. Keep the secret on your server and in your CI's secrets; it never goes in a browser or a repository.
  Done when: a client_id and client_secret are shown once, and you've stored them.
- [ ] **Get a token**
  Where: your terminal
  Exchange the credentials for an access token with the client credentials flow. The token lasts an hour; a refresh token comes with it.
  Copy (Token request):

  ```
  curl -X POST https://auth.staging.eirly.health/oauth/token \
    -u "$CLIENT_ID:$CLIENT_SECRET" \
    -d grant_type=client_credentials
  ```

  Done when: the response carries access_token and expires_in 3600.
- [ ] **Make the first call**
  Where: your terminal
  List the tests, then find the five centres nearest Sydney. Every list endpoint pages the same way, with a cursor.
  Copy (First calls):

  ```
  curl https://api.staging.eirly.health/v1/tests -H "Authorization: Bearer $TOKEN"
  curl "https://api.staging.eirly.health/v1/collection-centres?lat=-33.8688&lng=151.2093&count=5" -H "Authorization: Bearer $TOKEN"
  ```

  Done when: JSON comes back, and the centres carry distanceKm.
- [ ] **Choose tests and create a referral**
  Where: POST /v1/referrals
  List the tests, or order a pre-configured set by bundle and extend it with extra tests. Commercial and Medicare tests can go in the same request. POST /v1/referrals with the person and the tests: Eirly creates and issues the referral, and you retrieve the referral PDF. An order with both Medicare and commercial tests produces two referrals. Use made-up people in staging.
  Done when: you can retrieve the referral PDF. A mixed order gives two referrals.
- [ ] **Show the nearest centre**
  Where: Collection-centre search
  Collection-centre search returns centres by location, nearest first, with opening hours. The person walks in; most tests need no appointment.
  Done when: centres come back nearest first, with opening hours.
- [ ] **Subscribe to webhooks**
  Where: the REST API, webhook subscriptions
  Create a webhook subscription over REST. A webhook tells your system a referral or a result is created or updated: you receive a small event, then fetch the current state from the REST API, which is the source of truth. Each biomarker has a consistent identity across labs and a canonical value beside the lab's own. The event list and retry behaviour are in the webhooks reference in the docs.
  Done when: your system receives an event, and the referral or result you fetch from the API matches it.
- [ ] **Create a Medicare provider record**
  Where: POST /v1/providers
  Send the doctor's provider number, name, address and a PNG signature. The doctor needs no account with Eirly; that practitioner can order Medicare tests from this call on. Medicare referrals need API version 1.1.0 or higher.
  Done when: the practitioner can order Medicare tests from this call on.
- [ ] **Check the provider will receive results**
  Where: GET /v1/providers/{providerNumber}
  Every organisation is on copy routing unless our team has set it to direct routing. On copy routing, a provider record with every detail and a signature receives results: the request form asks the lab to copy us in, so there's no lab to notify. The provider response carries routingMethod and ready. Only call POST /v1/providers/{providerNumber}/routing when routingMethod is DIRECT; on copy routing it succeeds and does nothing.
  Done when: the provider record shows ready true.
- [ ] **Connect the MCP**
  Where: Claude Code, Cursor, Windsurf, Codex, or any assistant that speaks MCP
  The developer MCP is public and read-only: the API reference, schemas, docs and webhook events, read by your coding assistant while it writes your integration. Any tool that speaks MCP over HTTP can connect; the command below is Claude Code's, the others take the same address in their MCP settings.
  Copy (Claude Code):

  ```
  claude mcp add --transport http eirly-dev https://mcp.eirly.health/dev/v1
  ```

  Done when: your assistant can list the endpoints tagged Collection centres.
- [ ] **Go to production**
  Where: [app.eirly.health](https://app.eirly.health/signup)
  Repeat the setup in production: new account, organisation, billing and keys. Nothing carries over from staging, so rebuild your bundles, members and settings there too. Keys from staging do not work there. Production needs a plan, quoted to your volume.
  Done when: your production keys are in your server's secrets, and your staging ones are kept for testing.

## Common questions

### Is there a free sandbox?
Yes. Staging is a full environment with its own keys, and it never charges a real card. Production needs a plan.

### Do webhooks carry the result?
No. A webhook tells you something changed; you fetch the referral or result from the REST API. Webhooks and list endpoints cover orders created through the API.

### Does the ordering doctor need an Eirly account?
Not through the API: a provider record holds their number, details and signature. On the platform, each ordering doctor is a member with their own signature.

### Are there SDKs?
No. It is a REST API with OAuth 2.0 client credentials, cursor paging and JSON; the developer MCP server lets a coding assistant read the reference while it writes your client.

### Can we white-label the referral?
Your branding can appear on referrals, included or as an add-on depending on your plan.

### No key in the browser, ever
A client_id and client_secret in an HTML page, a bundle or a mobile app is public. Exchange them for a token on your server, or at build time, and ship only data.

### Never commit a secret
Keep credentials in environment variables or your CI's encrypted secrets, add .env files to .gitignore, and scan commits before they leave your machine. If a secret reaches a repository, treat it as leaked: rotate it in Settings, then API Keys, and rewrite nothing.

### One key per environment, one per job
Staging and production issue separate keys and neither works in the other. Give an integration its own organisation and key so you can revoke it without touching anything else.

### Keep tokens out of logs
Access tokens last an hour and refresh tokens a month; log neither. Mask them in error reports and never put them in a URL.

### Real clients only in production
Staging is for made-up people. A real name, Medicare number or result never belongs in a test environment, a fixture, a screenshot or a bug report.

### Verify what arrives
Treat a webhook as a notification, then fetch the record from the API with your token before you act on it. Reject anything your server did not ask for.

### Least privilege for people too
In the app, roles add up and no built-in role grants Medicare ordering; give each person the capabilities their job needs and rotate API keys when someone who held them leaves.

### Found a security problem?
Email support@eirly.health with the detail and we will respond; please do not post it publicly first.

## Related

- [Getting started with staging](/support/articles/try-eirly-in-staging): Account, organisation, test card and API keys.
- [Pathology API](/pathology-api): Referrals, results, webhooks, bundles and collection centres in one REST API.
- [Lab results API](/lab-results-api): What a result looks like: normalised across labs, with canonical values.
- [Medicare pathology ordering](/medicare-pathology-ordering): Who can request Medicare pathology, and Medicare and commercial tests on one order.
- [Developer MCP server](/mcp): Let your coding assistant read the API reference while it writes your integration.
- [Pathology booking API](/pathology-booking-api): Referral, nearest collection centre with opening hours, and the result, in one REST API.
- [API pricing](/api/pricing): Plans and what each includes.

## Still need help?

Email support@eirly.health with your organisation name, the environment and the request you made. Never send your client_secret, access tokens or real client details.
