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

# Sending messages

Reply to a customer, or reach them with a template when the window is closed.

Every message goes through one endpoint: [`POST /api/v1/messages/`](/docs/inbox/inbox-api/api-ref/messages.md#post-api-v1-messages). What you can send depends on one thing — whether the conversation window is open.

{% stepper %}
{% step %}
**Check the window**

Read the chat and look at `contact.messaging_window_expires_at`:

```bash
curl -H "Authorization: Token $SERVICE_TOKEN" $INBOX/api/v1/chats/$WA_ID/
```

If that time is still in the future, the window is open and you can send anything. If it has passed, you can only send a template. Do not assume a fixed duration — it depends on how the conversation started. See [The customer service window](/docs/inbox/the-customer-service-window.md).

Reference: [Retrieve chat](/docs/inbox/inbox-api/api-ref/chats.md#get-api-v1-chats-wa_id)
{% endstep %}

{% step %}
**Window open: send a message**

```bash
curl -X POST $INBOX/api/v1/messages/ \
  -H "Authorization: Token $SERVICE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"wa_id": "'"$WA_ID"'", "type": "text", "text": {"body": "Thanks, your order is on its way."}}'
```

`wa_id` is the value you got from the chat — a phone number or a BSUID. Pass it as is.

Reference: [Create message](/docs/inbox/inbox-api/api-ref/messages.md#post-api-v1-messages)
{% endstep %}

{% step %}
**Window closed: send a template**

Use one of your approved templates, in the same format as the WhatsApp API. Replace `order_update` with the name of one of yours:

```bash
curl -X POST $INBOX/api/v1/messages/ \
  -H "Authorization: Token $SERVICE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "wa_id": "'"$WA_ID"'",
    "type": "template",
    "template": {
      "name": "order_update",
      "language": { "code": "en" }
    }
  }'
```

To see which templates you have, call [`GET /api/v1/templates/`](/docs/inbox/inbox-api/api-ref/templates.md#get-api-v1-templates).

{% hint style="warning" %}
The API does not check the template before accepting the message. If the name or language does not match an approved template, you still get `202`, and the error arrives later in the message's `waba_payload.errors` — for example code `132001`, template does not exist.
{% endhint %}
{% endstep %}
{% endstepper %}

## What the response means

`202 Accepted` means the message is queued, not yet delivered. The most common failure is `453`: the window has closed, so send a template instead. All response codes are listed in the [Create message](/docs/inbox/inbox-api/api-ref/messages.md#post-api-v1-messages) reference.


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.360dialog.com/docs/inbox/inbox-api/sending-messages.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
