> For the complete documentation index, see [llms.txt](https://docs.mdintegrations.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mdintegrations.com/partner/integration-paths/api.md).

# API

Build with the API when you need full control over the patient journey. Your application can own checkout, intake, messaging, patient access, and operational workflows end to end.

This path suits teams that are building custom intake flows or embedding telehealth into an existing product. Under the hood, it still follows the same [Patient Journey](/partner/key-concepts/patient-journey.md) as every other integration path — the API just gives you the freedom to build each step yourself instead of relying on MDI-hosted screens.

{% hint style="info" %}
You can combine API workflows with MDI-hosted experiences. Use [White-Label Apps](/partner/integration-paths/white-label-apps.md) when hosted intake or messaging better fits your product.
{% endhint %}

### Build an API integration

{% stepper %}
{% step %}

#### Create Sandbox credentials

In the Partner Portal, create a **Sandbox** API credential. Store the resulting `client_id` and `client_secret` securely.

Build and test against Sandbox first, before you touch anything Live. See [Environments](/partner/key-concepts/environments.md) for environment behavior.
{% endstep %}

{% step %}

#### Authenticate your application

Request an access token with the `client_credentials` grant:

```http
POST https://api.mdintegrations.com/v1/partner/auth/token

{
  "grant_type": "client_credentials",
  "client_id": "[your_client_id]",
  "client_secret": "[your_secret]",
  "scope": "*"
}
```

Send the returned token as a bearer token on subsequent requests. See [Authentication & Credentials](/partner/troubleshooting/technical-concepts/authentication-and-credentials.md) for credential and token guidance.
{% endstep %}

{% step %}

#### Choose your intake experience

From here, you can use one or both approaches, depending on how much of the intake UI you want to own:

* **Custom UI** — Create Patients and Encounters through the API. Build your own intake and messaging experiences.
* **Hosted intake** — Generate a [Questionnaires & Vouchers](/partner/key-concepts/questionnaires-and-vouchers.md). MDI hosts intake and creates the Patient and Encounter after submission.
  {% endstep %}

{% step %}

#### Create Patients and Encounters

If you're building a custom intake, start by creating the Patient:

```
POST https://api.mdintegrations.com/v1/partner/patients

{
  "prefix": "Sr",
  "first_name": "Joe",
  "last_name": "Doe",
  "gender": 1,
  "date_of_birth": "1983-10-17",
  "phone_number": "(816) 679-2211",
  "phone_type": 2,
  "metadata": "patient number 200",
  "email": "joe.doe@mdintegrations.com",
  "driver_license_id": null,
  "address": {
    "address": "9071 E. Mississippi Ave",
    "address2": "Apt 6C",
    "zip_code": "80247",
    "city_name": "Tazlima",
    "state_name": "Ohio"
  },
  "pregnancy": false
}
```

Then create an [Patients & Encounters](/partner/key-concepts/patients-and-encounters.md). The API calls this object a `case`:

```
POST https://api.mdintegrations.com/v1/partner/cases

{
  "patient_id": "<uuid>",
  "case_files": ["<uuid>"],
  "case_offerings": [{ "offering_id": "{{ offeringId }}" }],
  "case_questions": [
    { "question": "title of the question", "answer": "yes", "type": "string" }
  ],
  "hold_status": false
}
```

`case_offerings` links the Encounter to the requested [Offerings](/partner/key-concepts/offerings.md), and `case_questions` carries the intake answers you collected in your own UI.

You can submit answers with `case_questions` right at case creation, or, if it fits your flow better, use the dedicated questions endpoint afterward instead.
{% endstep %}

{% step %}

#### Integrate messaging and updates

For a custom messaging UI, retrieve the patient conversation through the Get Messages endpoint, and use the Create Message endpoint to send messages on the patient's behalf.

Subscribe to webhooks for asynchronous case, prescription, and order updates rather than polling for changes. See [Webhook Setup & Signature Verification](/partner/troubleshooting/technical-concepts/webhook-setup-and-signature-verification.md) and the [Webhook Event Catalog](/partner/troubleshooting/technical-concepts/webhook-event-catalog.md).
{% endstep %}

{% step %}

#### Move to Live

Once you've tested the full workflow in Sandbox and your partner account reaches `ready`, create Live credentials and complete the [Go-Live Checklist](/partner/get-started/go-live-checklist.md) transition.

{% hint style="warning" %}
Never send Sandbox test traffic with Live credentials. Live prescriptions can reach pharmacies, and patients can be billed.
{% endhint %}
{% endstep %}
{% endstepper %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.mdintegrations.com/partner/integration-paths/api.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
