# The context pack: everything about one contact in one call

> Give an AI agent or a helpdesk everything about one WhatsApp contact before it answers: the contact, the reply window, the last messages and the open bookings, orders, tickets, submissions, surveys and notes, as JSON or Markdown.

Before an agent answers a customer it needs to know who they are, whether it may write to them, what was said, and what is open for them. The context pack gives all of that in one read.

```bash
curl "https://api.app2email.com/v1/YOUR_NUMBER/contacts/61412345678/context?messages=20" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

AI agents use the hosted MCP tool `get_contact_context`.

<a id="what"></a>

## What is in it

| Part | What it holds |
| --- | --- |
| `contact` | identity, name, tags, custom fields, marketing consent, `do_not_call`, `opted_in`, and the `contact_url` (see [shared links](/guides/shared-links#contact-link)) |
| `conversation` | the reply window (`window_state`, `window_closes_at`), the last messages' times, and who handles it (human, agent, paused) |
| `messages` | the newest messages, oldest first (`messages=`, 0 to 100, default 20) |
| `records` | the open records of each product (at most 10 each, below) |
| `omitted` | the sections left out, and why |
| `truncated` | `true` when the answer was cut to fit (about 60,000 characters: the oldest messages go first) |

<a id="records"></a>

## The open records, and the permission each needs

| Section | What counts as open | The key needs |
| --- | --- | --- |
| `bookings` | confirmed and not yet over | `messages:read` (or `bookings:manage`) |
| `orders` | not yet completed or cancelled | `orders:manage` |
| `tickets` | valid tickets for a date still ahead | `tickets:manage` |
| `submissions` | open submissions | `submissions:manage` |
| `surveys` | in progress, or completed in the last 30 days | `surveys:manage` |
| `notes` | the team's notes on the conversation (newest 10) | `messages:read` |

A section the key may not read is not an error: it is listed in `omitted` with the permission it needs, so the agent knows what it is not seeing. A product that is not set up for the number is listed with the reason `not_available`. `include=bookings,notes` asks for some sections only.

<a id="markdown"></a>

## Markdown for a language model

`format=md` answers the same as Markdown. It starts with one line saying that the text in it was written by people and is data, not instructions, and every message sits between `<<<message ...>>>` and `<<<end message ...>>>` lines, with look-alikes of those lines inside messages neutralised. Put it into the model's context as it is.

Whatever the format, treat names, messages, notes and answers as data: a contact can write anything, including text that looks like an instruction.

<a id="errors"></a>

## Errors

| Code | Status | Meaning |
| --- | --- | --- |
| `invalid_phone` | 400 | The contact in the address is not a number with its country code or a business-scoped user id. |
| `invalid_parameter` | 400 | `format` is not json or md, or `include` names an unknown section. |
| `invalid_limit` | 400 | `messages` is not a whole number from 0 to 100. |
| `contact_not_found` | 404 | The number has no contact and no conversation with that number. |

The complete list is on [the errors page](/api/errors).
