> 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/key-concepts/pharmacy-fulfillment/webhooks-and-order-sync.md).

# Webhooks & Order Sync

Webhooks are what keep your order records aligned with pharmacy activity in real time — MDI fires events as an order gets created, acknowledged, updated, and eventually shipped.

You can use these events to drive an internal order view or a customer-facing order history, and because they push changes to you as they happen, you don't need to poll the API for fulfillment updates.

### When to use order webhooks

| Fulfillment model  | Use case                                                      |
| ------------------ | ------------------------------------------------------------- |
| Order-driven       | Trigger order submission when prescription data is ready.     |
| Direct to Pharmacy | Mirror MDI-managed order and shipment status in your systems. |

See [Pharmacy Fulfillment](/partner/key-concepts/pharmacy-fulfillment.md) for how each model works.

### Pharmacy events

<table><thead><tr><th width="191.66754150390625">Event</th><th width="84.95318603515625" align="center">DTP Only</th><th width="251.91937255859375">Fires when</th><th width="224.46002197265625">Use it to</th></tr></thead><tbody><tr><td><code>offering_submitted</code></td><td align="center">❌</td><td>An Encounter is approved and prescription or Service Offering data is ready.</td><td>Start order submission or partner-owned transmission.</td></tr><tr><td><code>case_order_created</code></td><td align="center">✅</td><td>A pharmacy order is created.</td><td>Create the corresponding record in your system.</td></tr><tr><td><code>case_order_updated</code></td><td align="center">✅</td><td>A pharmacy order changes status.</td><td>Update fulfillment and shipping status.</td></tr></tbody></table>

`offering_submitted` matters most for the order-driven and [Partner-Owned Transmission](/partner/key-concepts/pharmacy-fulfillment/partner-owned-transmission.md) models, since both depend on it to know when they can act.

#### Process events safely

{% stepper %}
{% step %}

#### Verify and acknowledge

Verify the webhook signature first, then return a 2xx response as quickly as possible — do the actual processing asynchronously, after you've acknowledged receipt.
{% endstep %}

{% step %}

#### Identify the Encounter and order

Use `case_id` to identify the Encounter — note that `encounter_id` and `case_id` refer to the same underlying record, just under different names — and use `case_order_id` when it's present to identify the specific order.
{% endstep %}

{% step %}

#### Apply the current state

Update your order record from whichever of `order_status`, `tracking_number`, and `order_details` the payload includes.
{% endstep %}

{% step %}

#### Handle duplicates and ordering

Use the event `timestamp` to deduplicate retries and put events in the right order, and design your handlers so they tolerate deliveries that arrive late or out of sequence.
{% endstep %}
{% endstepper %}

{% hint style="warning" %}
Webhook delivery is asynchronous.

Do not assume an event arrives when the related API request completes.
{% endhint %}


---

# 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/key-concepts/pharmacy-fulfillment/webhooks-and-order-sync.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.
