# Send a template for a record

```http
POST https://secure.yoprint.com/v2/api/store/{team_slug}/setting/message_template/send
```

- Spends money: see Side effects.
- API version: v2
- Operation ID: `v2_public_message_template_send`
- Section: Team settings › [Message templates](https://developer.yoprint.com/reference/message-templates.md)
- Web page: https://developer.yoprint.com/reference/message-templates/v2-message-template-send/
- Authentication: `Authorization: Bearer YOUR_API_KEY`

Fills a saved template from one record and sends it now. **It reaches a real customer or vendor and can't be recalled.**

- Email templates send an email, with the template's attachments.
- Text message templates send a text through your Twilio integration.

Who gets it: for an email, the record's message participants who receive mail and messages, or the record's contact if there are none. For a text, the participants who receive texts; with none, nobody is texted.

Email limit: if your team goes over the daily email limit for its plan (60 a day on a free plan or trial, more on paid plans), YoPrint blocks email sending for your whole team until YoPrint support lifts the block. Space out bulk sends.

The six saved email types have no subject line of their own: their compiled `subject` is empty.

Compile it first to check the result. The response has no data.

## Permission

With a personal API key, any member of the team: no permission on the record is checked, even for members who can't see that order. AI apps need permission to message about that record.

## Business rules

- Purchase order templates need the "send purchase order email" feature in your plan (422 `plan_limitation`).
- A team on a trial can send only when YoPrint has turned on email for its trial, and a paid team needs an active subscription (otherwise 422 `email_feature_not_enabled_in_trial`).
- Every team has a daily email limit. Going over it blocks the team's email sending until YoPrint support lifts the block.

## Side effects

- Sends an email or a text message to the customer or vendor, and saves it with the record's messages.
- Document attachments (such as the order PDF) are made from the record at the time of sending.
- **Spends money.** A text message is sent through your Twilio account and costs what Twilio charges.

## Path parameters

- `team_slug` (string, required): Your team slug, shown as Team ID next to your API key in Profile. Example `your-team`.

## Request body

Content type `application/json`, required.

Fields:

- `id` (string, required): The saved template's id.
- `object_id` (string, required): The record it is about: a sales order or quote id for sales order and quote templates, a purchase order id for purchase order templates.

### Example request

```bash
curl -X POST 'https://secure.yoprint.com/v2/api/store/your-team/setting/message_template/send' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Accept: application/json' \
  -H 'X-Yoprint-Decimal-Format: exact-v1' \
  -H 'Content-Type: application/json' \
  -d '{
    "id": "DVubREua5aJkwh",
    "object_id": "zGZRXNGeh5cs6M"
  }'
```

## Response

`200` Successful response.

Fields:

- `data` (null, required)
- `status` (integer, required)
- `success` (boolean, required)

Example response:

```json
{
  "data": null,
  "status": 200,
  "success": true
}
```

## Errors

- `401` The API key is missing or wrong (`unauthenticated`).
- `403` You are not allowed to do this. `api_access_not_in_plan`: your team's plan doesn't include API access (Pro and above, with an active subscription or trial), so every request answers this until the team upgrades. When your role lacks the permission the operation needs, the body is only `{"message": "Insufficient Permission"}`. Other refusals use the error envelope, with `unauthorized` or `user_is_not_authorized`.
- `404` Not found. `page_not_found`: the team slug is unknown, you are not a member of the team, or an id in the path is not one of this team's. `code: null`, with a message that starts "No query results for": there is no record with that id.
  - When: No template of your team has this `id`. Fix: Use an id from the template list.
- `422` The request was refused and changed nothing. `validation_failed` lists what to fix in `error.fields`; other codes name a business rule, explained in `error.message`. A few checks answer with only `{"message": "..."}`. An operation that calls another service (a payment provider, a carrier, an accounting app) can answer `connect_timeout` ("Please retry again") when that service does not answer in time: the change may or may not have happened there, so read the record back before you retry.
  - When: `object_id` is missing (`validation_failed`). Fix: Send the record's id.
  - When: `object_id` is not a record of your team of the right kind: `error.code` `send_failed`. Nothing is sent. Fix: Send a sales order or quote id for those templates, a purchase order id for purchase order templates.
  - When: Your plan doesn't allow purchase order emails (`plan_limitation`), the trial doesn't allow email (`email_feature_not_enabled_in_trial`), or the team is over its daily email limit (`validation_error`, "You are sending too many emails..."). Fix: Read `error.message`; contact YoPrint support if sending is blocked.

## Related

- [Fill in a template for a record](https://developer.yoprint.com/reference/message-templates/v2-message-template-compile.md): `POST /v2/api/store/{team_slug}/setting/message_template/compile`
- [List message templates](https://developer.yoprint.com/reference/message-templates/v2-message-template-index.md): `GET /v2/api/store/{team_slug}/setting/message_template`
