> 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/troubleshooting/technical-concepts/authentication-and-credentials.md).

# Authentication & Credentials

Every request to the MDI API authenticates using OAuth2's **client\_credentials** grant. In practice, that means you exchange a client ID and secret for a short-lived access token once, and then send that token as a Bearer token on every subsequent call — you never send your client ID and secret directly on the requests that actually move data.

## Requesting a token

```http
POST https://api.mdintegrations.com/v1/partner/auth/token
Content-Type: application/json
```

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

A successful response includes an `access_token`:

```json
{
  "access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
  "token_type": "Bearer",
  "expires_in": 3600
}
```

From there, use it as a Bearer token on every request that follows:

```http
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...
```

{% hint style="warning" %}
Treat `client_id` and `client_secret` as production secrets. Never embed them in client-side code, mobile apps, or anything a patient's browser can inspect — the token exchange should happen server-side.
{% endhint %}

## Sandbox vs. Live credentials

MDI issues separate credentials for each environment, and the separation is enforced, not just conventional: a Sandbox credential only ever produces Sandbox tokens, and those tokens only work against Sandbox data — they can't touch Live patients, Encounters, or orders, and the reverse is equally true. See Sandbox vs. Live Environments for the full distinction between the two.

Both credential types are created the same way, through the Partner Portal:

{% stepper %}
{% step %}
Log in to the Partner Portal as an admin user.
{% endstep %}

{% step %}
Go to **Integration** → **Credentials**.
{% endstep %}

{% step %}
Click **Add new**.
{% endstep %}

{% step %}
Name the credential.
{% endstep %}

{% step %}
Select the environment for the credential — Sandbox or Live.
{% endstep %}

{% step %}
Click **Save**.
{% endstep %}

{% step %}
Store the resulting `client_id` and `client_secret` securely.
{% endstep %}
{% endstepper %}

You can generate a Sandbox credential as soon as your partner account exists, which is deliberate — it lets you start building and testing immediately. A Live credential, by contrast, only becomes available once your account has cleared MDI's review process; see the Partner Onboarding Checklist for where that review fits into your overall integration timeline.

## Scopes

The sample request above uses `scope: "*"`, which is sufficient for most partner integrations and a reasonable default if you're just getting started. If your use case calls for narrower scoping, the current list of available scopes is maintained in the Full API Reference rather than here, since it can change independently of this guide.

## What's next

Once you can obtain a token, the next things worth understanding are how long it lasts and when to refresh it — covered in Token Expiration & Refresh — and the conventions every subsequent request follows, covered in Request & Response Conventions.


---

# 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/troubleshooting/technical-concepts/authentication-and-credentials.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.
