---
title: "Send a templated email once under an external identifier"
description: "The body is the full representation: null clears a field, an absent field is left alone. Answers 201 when the row was created and 200 when it was updated, which is how a system of record tells a create from a reconcile.\n\n### Quire permissions\n\nRequired capability: `email/campaign_manage`.\n\nCredential scopes: `email:write`.\n\nThe acting subject must also be allowed to perform this action in the organisation."
image: "https://docs.quirelms.com/og.png"
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.quirelms.com/llms.txt
> Use this file to discover all available pages before exploring further.

Path: Quire API › email

`PUT /email_messages/ext:{external_id}`

The body is the full representation: null clears a field, an absent field is left alone. Answers 201 when the row was created and 200 when it was updated, which is how a system of record tells a create from a reconcile.

\### Quire permissions

Required capability: `email/campaign_manage`.

Credential scopes: `email:write`.

The acting subject must also be allowed to perform this action in the organisation.

## Authentication

Requires one of the following:

- `apiKey`, http, header `Authorization`, scopes: `email:write`
- `oauth2`, oauth2, scopes: `email:write`

## Path parameters

- `upsertEmailMessage.path.external_id` (string, required) — The external identifier, unique per tenant per type, as supplied by the system of record.

## Header parameters

- `upsertEmailMessage.header.Quire-Version` (string, optional) — The dated API revision to serve this request at. Omitted, the request is served at the revision the credential was issued against. The response echoes the revision actually applied.
  - format `date`
- `upsertEmailMessage.header.Idempotency-Key` (string, optional) — A caller-chosen key making this request safe to retry. A replay of a completed request returns the recorded response with `Idempotency-Replayed: true`. Reusing a key for a different request is refused.
  - maxLength 255

## Request body

_Required._

- `upsertEmailMessage.user_id` (string, required) — Who receives it; their address, name and language come from their account.
  - format `uuid`; pattern `^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$`
- `upsertEmailMessage.message_key` (string, required) — The message to send, as the email templates page lists it. Its published template for the recipient's language is used.
  - minLength 3; maxLength 200
- `upsertEmailMessage.context` (map<unknown>, optional) — Values for the template's merge tags.

## Example request

```json
{
  "user_id": "a169451c-8525-4352-b8ca-070dd449a1a5",
  "message_key": "string",
  "context": {
    "property1": null,
    "property2": null
  }
}
```

## Code samples

### cURL

```curl
curl --request PUT \
  --url https://your-organisation.quirelms.com/api/v1/email_messages/ext:string \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "user_id": "a169451c-8525-4352-b8ca-070dd449a1a5",
  "message_key": "string",
  "context": {
    "property1": null,
    "property2": null
  }
}
'
```

### TypeScript

```typescript
const url = 'https://your-organisation.quirelms.com/api/v1/email_messages/ext:string';
const options = {
  method: 'PUT',
  headers: {'Content-Type': 'application/json', Authorization: 'Bearer <token>'},
  body: JSON.stringify({
    user_id: 'a169451c-8525-4352-b8ca-070dd449a1a5',
    message_key: 'string',
    context: {property1: null, property2: null}
  })
};

fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://your-organisation.quirelms.com/api/v1/email_messages/ext:string"

payload = {
    "user_id": "a169451c-8525-4352-b8ca-070dd449a1a5",
    "message_key": "string",
    "context": {
        "property1": None,
        "property2": None
    }
}
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer <token>"
}

response = requests.put(url, json=payload, headers=headers)

print(response.text)
```

## Responses

### 200

Success.

#### Example

```json
{
  "id": "string",
  "external_id": "string",
  "message_key": "string",
  "recipient_user_id": "string",
  "recipient_address": "string",
  "stream": "string",
  "language": "string",
  "subject": "string",
  "state": "string",
  "provider": "string",
  "attempt": -9007199254740991,
  "bounce_class": "string",
  "failure_reason": "string",
  "created_at": "string",
  "updated_at": "string"
}
```

- `upsertEmailMessage.response.200.id` (string, required)
- `upsertEmailMessage.response.200.external_id` (string | null, required)
- `upsertEmailMessage.response.200.message_key` (string, required)
- `upsertEmailMessage.response.200.recipient_user_id` (string | null, required)
- `upsertEmailMessage.response.200.recipient_address` (string, required)
- `upsertEmailMessage.response.200.stream` (string, required)
- `upsertEmailMessage.response.200.language` (string, required)
- `upsertEmailMessage.response.200.subject` (string, required)
- `upsertEmailMessage.response.200.state` (string, required)
- `upsertEmailMessage.response.200.provider` (string | null, required)
- `upsertEmailMessage.response.200.attempt` (integer, required)
  - min -9007199254740991; max 9007199254740991
- `upsertEmailMessage.response.200.bounce_class` (string | null, required)
- `upsertEmailMessage.response.200.failure_reason` (string | null, required)
- `upsertEmailMessage.response.200.created_at` (string, required) — RFC 3339 timestamp in UTC.
- `upsertEmailMessage.response.200.updated_at` (string, required) — RFC 3339 timestamp in UTC.

### 201

Success.

#### Example

```json
{
  "id": "string",
  "external_id": "string",
  "message_key": "string",
  "recipient_user_id": "string",
  "recipient_address": "string",
  "stream": "string",
  "language": "string",
  "subject": "string",
  "state": "string",
  "provider": "string",
  "attempt": -9007199254740991,
  "bounce_class": "string",
  "failure_reason": "string",
  "created_at": "string",
  "updated_at": "string"
}
```

- `upsertEmailMessage.response.201.id` (string, required)
- `upsertEmailMessage.response.201.external_id` (string | null, required)
- `upsertEmailMessage.response.201.message_key` (string, required)
- `upsertEmailMessage.response.201.recipient_user_id` (string | null, required)
- `upsertEmailMessage.response.201.recipient_address` (string, required)
- `upsertEmailMessage.response.201.stream` (string, required)
- `upsertEmailMessage.response.201.language` (string, required)
- `upsertEmailMessage.response.201.subject` (string, required)
- `upsertEmailMessage.response.201.state` (string, required)
- `upsertEmailMessage.response.201.provider` (string | null, required)
- `upsertEmailMessage.response.201.attempt` (integer, required)
  - min -9007199254740991; max 9007199254740991
- `upsertEmailMessage.response.201.bounce_class` (string | null, required)
- `upsertEmailMessage.response.201.failure_reason` (string | null, required)
- `upsertEmailMessage.response.201.created_at` (string, required) — RFC 3339 timestamp in UTC.
- `upsertEmailMessage.response.201.updated_at` (string, required) — RFC 3339 timestamp in UTC.

### 401

The credential is missing, malformed, expired or revoked.

#### Example

```json
{
  "type": "http://example.com",
  "title": "string",
  "status": 0,
  "code": "string",
  "category": "validation",
  "detail": "string",
  "request_id": "string",
  "errors": [
    {
      "path": "string",
      "code": "string",
      "detail": "string"
    }
  ],
  "retry_after": 0,
  "docs_url": "http://example.com"
}
```

- `upsertEmailMessage.response.401.type` (string, required)
  - format `uri`
- `upsertEmailMessage.response.401.title` (string, required)
- `upsertEmailMessage.response.401.status` (integer, required)
- `upsertEmailMessage.response.401.code` (string, required)
- `upsertEmailMessage.response.401.category` (string, required)
  - one of `"validation"`, `"authentication"`, `"authorization"`, `"not_found"`, `"conflict"`, `"precondition"`, `"quota"`, `"rate_limit"`, `"upstream"`, `"internal"`
- `upsertEmailMessage.response.401.detail` (string, required)
- `upsertEmailMessage.response.401.request_id` (string, required)
- `upsertEmailMessage.response.401.docs_url` (string, required)
  - format `uri`
- `upsertEmailMessage.response.401.errors` (array<object>, optional)
  - `upsertEmailMessage.response.401.errors.path` (string, required) — RFC 6901 JSON Pointer into the request body.
  - `upsertEmailMessage.response.401.errors.code` (string, required)
  - `upsertEmailMessage.response.401.errors.detail` (string, required)
- `upsertEmailMessage.response.401.retry_after` (integer | null, optional)

### 403

The credential lacks the scope this operation requires, or the acting subject lacks the capability.

#### Example

```json
{
  "type": "http://example.com",
  "title": "string",
  "status": 0,
  "code": "string",
  "category": "validation",
  "detail": "string",
  "request_id": "string",
  "errors": [
    {
      "path": "string",
      "code": "string",
      "detail": "string"
    }
  ],
  "retry_after": 0,
  "docs_url": "http://example.com"
}
```

- `upsertEmailMessage.response.403.type` (string, required)
  - format `uri`
- `upsertEmailMessage.response.403.title` (string, required)
- `upsertEmailMessage.response.403.status` (integer, required)
- `upsertEmailMessage.response.403.code` (string, required)
- `upsertEmailMessage.response.403.category` (string, required)
  - one of `"validation"`, `"authentication"`, `"authorization"`, `"not_found"`, `"conflict"`, `"precondition"`, `"quota"`, `"rate_limit"`, `"upstream"`, `"internal"`
- `upsertEmailMessage.response.403.detail` (string, required)
- `upsertEmailMessage.response.403.request_id` (string, required)
- `upsertEmailMessage.response.403.docs_url` (string, required)
  - format `uri`
- `upsertEmailMessage.response.403.errors` (array<object>, optional)
  - `upsertEmailMessage.response.403.errors.path` (string, required) — RFC 6901 JSON Pointer into the request body.
  - `upsertEmailMessage.response.403.errors.code` (string, required)
  - `upsertEmailMessage.response.403.errors.detail` (string, required)
- `upsertEmailMessage.response.403.retry_after` (integer | null, optional)

### 404

No such resource, or none this credential is permitted to know about.

#### Example

```json
{
  "type": "http://example.com",
  "title": "string",
  "status": 0,
  "code": "string",
  "category": "validation",
  "detail": "string",
  "request_id": "string",
  "errors": [
    {
      "path": "string",
      "code": "string",
      "detail": "string"
    }
  ],
  "retry_after": 0,
  "docs_url": "http://example.com"
}
```

- `upsertEmailMessage.response.404.type` (string, required)
  - format `uri`
- `upsertEmailMessage.response.404.title` (string, required)
- `upsertEmailMessage.response.404.status` (integer, required)
- `upsertEmailMessage.response.404.code` (string, required)
- `upsertEmailMessage.response.404.category` (string, required)
  - one of `"validation"`, `"authentication"`, `"authorization"`, `"not_found"`, `"conflict"`, `"precondition"`, `"quota"`, `"rate_limit"`, `"upstream"`, `"internal"`
- `upsertEmailMessage.response.404.detail` (string, required)
- `upsertEmailMessage.response.404.request_id` (string, required)
- `upsertEmailMessage.response.404.docs_url` (string, required)
  - format `uri`
- `upsertEmailMessage.response.404.errors` (array<object>, optional)
  - `upsertEmailMessage.response.404.errors.path` (string, required) — RFC 6901 JSON Pointer into the request body.
  - `upsertEmailMessage.response.404.errors.code` (string, required)
  - `upsertEmailMessage.response.404.errors.detail` (string, required)
- `upsertEmailMessage.response.404.retry_after` (integer | null, optional)

### 409

The request conflicts with the current state, with a previous use of the same idempotency key, or with a concurrent write.

#### Example

```json
{
  "type": "http://example.com",
  "title": "string",
  "status": 0,
  "code": "string",
  "category": "validation",
  "detail": "string",
  "request_id": "string",
  "errors": [
    {
      "path": "string",
      "code": "string",
      "detail": "string"
    }
  ],
  "retry_after": 0,
  "docs_url": "http://example.com"
}
```

- `upsertEmailMessage.response.409.type` (string, required)
  - format `uri`
- `upsertEmailMessage.response.409.title` (string, required)
- `upsertEmailMessage.response.409.status` (integer, required)
- `upsertEmailMessage.response.409.code` (string, required)
- `upsertEmailMessage.response.409.category` (string, required)
  - one of `"validation"`, `"authentication"`, `"authorization"`, `"not_found"`, `"conflict"`, `"precondition"`, `"quota"`, `"rate_limit"`, `"upstream"`, `"internal"`
- `upsertEmailMessage.response.409.detail` (string, required)
- `upsertEmailMessage.response.409.request_id` (string, required)
- `upsertEmailMessage.response.409.docs_url` (string, required)
  - format `uri`
- `upsertEmailMessage.response.409.errors` (array<object>, optional)
  - `upsertEmailMessage.response.409.errors.path` (string, required) — RFC 6901 JSON Pointer into the request body.
  - `upsertEmailMessage.response.409.errors.code` (string, required)
  - `upsertEmailMessage.response.409.errors.detail` (string, required)
- `upsertEmailMessage.response.409.retry_after` (integer | null, optional)

### 422

The request was understood and its content is not valid. `errors` names each field.

#### Example

```json
{
  "type": "http://example.com",
  "title": "string",
  "status": 0,
  "code": "string",
  "category": "validation",
  "detail": "string",
  "request_id": "string",
  "errors": [
    {
      "path": "string",
      "code": "string",
      "detail": "string"
    }
  ],
  "retry_after": 0,
  "docs_url": "http://example.com"
}
```

- `upsertEmailMessage.response.422.type` (string, required)
  - format `uri`
- `upsertEmailMessage.response.422.title` (string, required)
- `upsertEmailMessage.response.422.status` (integer, required)
- `upsertEmailMessage.response.422.code` (string, required)
- `upsertEmailMessage.response.422.category` (string, required)
  - one of `"validation"`, `"authentication"`, `"authorization"`, `"not_found"`, `"conflict"`, `"precondition"`, `"quota"`, `"rate_limit"`, `"upstream"`, `"internal"`
- `upsertEmailMessage.response.422.detail` (string, required)
- `upsertEmailMessage.response.422.request_id` (string, required)
- `upsertEmailMessage.response.422.docs_url` (string, required)
  - format `uri`
- `upsertEmailMessage.response.422.errors` (array<object>, optional)
  - `upsertEmailMessage.response.422.errors.path` (string, required) — RFC 6901 JSON Pointer into the request body.
  - `upsertEmailMessage.response.422.errors.code` (string, required)
  - `upsertEmailMessage.response.422.errors.detail` (string, required)
- `upsertEmailMessage.response.422.retry_after` (integer | null, optional)

### 429

A rate limit or a concurrency cap was reached. `Retry-After` says when to try again.

#### Example

```json
{
  "type": "http://example.com",
  "title": "string",
  "status": 0,
  "code": "string",
  "category": "validation",
  "detail": "string",
  "request_id": "string",
  "errors": [
    {
      "path": "string",
      "code": "string",
      "detail": "string"
    }
  ],
  "retry_after": 0,
  "docs_url": "http://example.com"
}
```

- `upsertEmailMessage.response.429.type` (string, required)
  - format `uri`
- `upsertEmailMessage.response.429.title` (string, required)
- `upsertEmailMessage.response.429.status` (integer, required)
- `upsertEmailMessage.response.429.code` (string, required)
- `upsertEmailMessage.response.429.category` (string, required)
  - one of `"validation"`, `"authentication"`, `"authorization"`, `"not_found"`, `"conflict"`, `"precondition"`, `"quota"`, `"rate_limit"`, `"upstream"`, `"internal"`
- `upsertEmailMessage.response.429.detail` (string, required)
- `upsertEmailMessage.response.429.request_id` (string, required)
- `upsertEmailMessage.response.429.docs_url` (string, required)
  - format `uri`
- `upsertEmailMessage.response.429.errors` (array<object>, optional)
  - `upsertEmailMessage.response.429.errors.path` (string, required) — RFC 6901 JSON Pointer into the request body.
  - `upsertEmailMessage.response.429.errors.code` (string, required)
  - `upsertEmailMessage.response.429.errors.detail` (string, required)
- `upsertEmailMessage.response.429.retry_after` (integer | null, optional)

### 500

Something failed at our end. Quote `request_id` when reporting it.

#### Example

```json
{
  "type": "http://example.com",
  "title": "string",
  "status": 0,
  "code": "string",
  "category": "validation",
  "detail": "string",
  "request_id": "string",
  "errors": [
    {
      "path": "string",
      "code": "string",
      "detail": "string"
    }
  ],
  "retry_after": 0,
  "docs_url": "http://example.com"
}
```

- `upsertEmailMessage.response.500.type` (string, required)
  - format `uri`
- `upsertEmailMessage.response.500.title` (string, required)
- `upsertEmailMessage.response.500.status` (integer, required)
- `upsertEmailMessage.response.500.code` (string, required)
- `upsertEmailMessage.response.500.category` (string, required)
  - one of `"validation"`, `"authentication"`, `"authorization"`, `"not_found"`, `"conflict"`, `"precondition"`, `"quota"`, `"rate_limit"`, `"upstream"`, `"internal"`
- `upsertEmailMessage.response.500.detail` (string, required)
- `upsertEmailMessage.response.500.request_id` (string, required)
- `upsertEmailMessage.response.500.docs_url` (string, required)
  - format `uri`
- `upsertEmailMessage.response.500.errors` (array<object>, optional)
  - `upsertEmailMessage.response.500.errors.path` (string, required) — RFC 6901 JSON Pointer into the request body.
  - `upsertEmailMessage.response.500.errors.code` (string, required)
  - `upsertEmailMessage.response.500.errors.detail` (string, required)
- `upsertEmailMessage.response.500.retry_after` (integer | null, optional)


Source: https://docs.quirelms.com/api/email/upsertEmailMessage/index.md
