# Data and messages

Check a token, read and update a customer, post a message into a live conversation, publish to a connected page, and bind a signed-in user's token to their chat.

Source: https://docs.omazy.ai/reference/core-api/data-and-messages/

The routes on this page act on things that already exist in your workspace: a
customer, a conversation, a connected page. Each is scoped to the token's
workspace. An id from another workspace answers `404`, exactly as if it did not
exist.

| Route | Scope | Does |
|---|---|---|
| `GET /whoami` | None | Says what a token is and what it may do |
| `GET /customers/{id}` | `core:read` | Reads one customer |
| `PATCH /customers/{id}` | `memory:write` | Merges custom fields onto a customer |
| `POST /conversations/{id}/messages` | `core:write` | Posts a message as the agent |
| `POST /channels/linkedin/publish` | `channels:publish` | Publishes to a connected LinkedIn Page |
| `PUT /sessions/{sid}/mcp-credentials/{server}` | `sessions:credentials` | Binds a signed-in user's token to their chat |
| `DELETE /sessions/{sid}/mcp-credentials/{server}` | `sessions:credentials` | Removes it |

## Who am I

```
GET /whoami
```

Works with any valid token. Use it in a health check, and when a call is
refused and you want to see the scopes the token really holds.

`token` is `current`, or `previous` while your server is still on a token that
was [rotated](/reference/core-api/authentication/#expiry-and-rotation).
`token_expires_at` is there only when the token has a deadline.

`plan` is the plan the workspace is on and what it allows: the calls per
minute that size each [rate limit](/reference/core-api/errors-and-limits/#rate-limits),
and the [AI turns](/reference/core-api/errors-and-limits/#your-plans-ai-turns)
and [voice minutes](/reference/core-api/errors-and-limits/#your-plans-voice-minutes)
used and included this period.

```json
{
  "success": true,
  "data": {
    "install_id": "0d6c3a7e-3f3f-4b1b-9d0c-1f5a2f1c9a11",
    "workspace_id": "5b0c1c5e-8f0e-4a55-9a51-2f6d1f3f6a10",
    "app_slug": "backoffice",
    "scopes": ["core:read", "memory:write"],
    "status": "active",
    "token": "current",
    "token_expires_at": "2027-02-17T12:14:11Z",
    "plan": {
      "sku": "free",
      "rate_per_minute": 60,
      "ai_turns": { "used": 412, "limit": 6000, "resets_at": "2026-12-07T10:40:52Z" },
      "voice_minutes": { "used": 37, "limit": 2000, "resets_at": "2026-12-07T10:40:52Z" }
    }
  }
}
```

`app_slug` is the name the token was issued under. It identifies your
integration. It is not the handle of an app in the workspace, and it is not
what you pass as `app` on other routes.

## Read a customer

```
GET /customers/{id}
```

Scope: `core:read`. `{id}` is the customer's id, a UUID.

```json
{
  "success": true,
  "data": {
    "id": "a3d1c1b2-7f6e-4d7a-9a0b-1c2d3e4f5a6b",
    "external_id": "crm-4410",
    "email": "sam@example.com",
    "phone": "+447700900123",
    "name": "Sam Rivera",
    "tags": ["wholesale"],
    "custom_fields": { "tier": "gold" }
  }
}
```

`external_id`, `email`, `phone` and `name` are left out when the customer has
none. `tags` and `custom_fields` are always present.

There is no route here to list or search customers. You need the id already.

## Update a customer's custom fields

```
PATCH /customers/{id}
```

Scope: `memory:write`. This is how your backend teaches Omazy something about a
person: a plan tier, an account number, the result of a quiz.

```sh
curl -X PATCH https://mw.omazy.ai/api/v1/core/customers/a3d1c1b2-7f6e-4d7a-9a0b-1c2d3e4f5a6b \
  -H "Authorization: Bearer $OMAZY_CORE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "custom_fields": { "tier": "platinum", "renewal": "2027-03-01" } }'
```

The body is `{ "custom_fields": { ... } }` and `custom_fields` must be a JSON
object. It is merged into what is already there: keys you send replace the keys
of the same name, and keys you do not send are left alone.

The merge is one level deep. Send a nested object and it replaces the whole
value under that key. It is not combined with the nested object that was there
before.

The response is the customer's id and the merged result:

```json
{
  "success": true,
  "data": {
    "id": "a3d1c1b2-7f6e-4d7a-9a0b-1c2d3e4f5a6b",
    "custom_fields": { "tier": "platinum", "renewal": "2027-03-01" }
  }
}
```

Only `custom_fields` can be written. A customer's name, email, phone and tags
cannot be changed from this API.

## Post a message into a conversation

```
POST /conversations/{id}/messages
```

Scope: `core:write`. The message appears in the conversation as your agent
speaking, and reaches an open widget straight away. Use it when your backend
learns something the visitor is waiting for: a payment cleared, a report
finished, a slot was held.

A message sent twice appears twice. Send an
[`Idempotency-Key`](/reference/core-api/errors-and-limits/#sending-a-request-again)
header and a repeat with the same key posts nothing and returns the first
answer.

```sh
curl https://mw.omazy.ai/api/v1/core/conversations/9c1e2d3f-4a5b-4c6d-8e7f-0a1b2c3d4e5f/messages \
  -H "Authorization: Bearer $OMAZY_CORE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "blocks": [
      { "type": "text", "markdown": "Your report is ready." },
      { "type": "buttons", "buttons": [
        { "kind": "url", "label": "Open the report", "url": "https://app.example.com/reports/88" }
      ] }
    ]
  }'
```

The body is `{ "blocks": [ ... ] }`, with between `1` and `12` blocks. A block
is the same thing the agent itself sends, described in
[Message blocks](/how-to/widget/message-blocks/). Every block needs a `type`.

Success is `201 Created`:

```json
{ "success": true, "data": { "message_id": "6e5d4c3b-2a19-4f08-b7c6-d5e4f3a2b1c0" } }
```

`{id}` is the conversation's id. On your own site the widget hands it to the
page: its `session` event carries `conversationId` as soon as a conversation
exists, new or resumed. Subscribe the way the widget's
[host API](/how-to/widget/host-api/#events) describes, and send the value to
your server.

The message is posted as the agent, not as a teammate and not as the visitor.
There is no route here to read a conversation's messages.

## Publish to a LinkedIn Page

```
POST /channels/linkedin/publish
```

Scope: `channels:publish`. Your backend hands Omazy the text and Omazy
publishes it as the Page. Your server never holds the Page's LinkedIn
credential, which stays in one place.

The route takes an
[`Idempotency-Key`](/reference/core-api/errors-and-limits/#sending-a-request-again),
so a request sent twice publishes one post.

:::caution[This needs a connected LinkedIn Page]
The route answers today, but it publishes only when a LinkedIn Page is
connected to an app in your workspace. The LinkedIn Page channel is not
generally available yet. Without a connected Page, the route answers `404`
with `no LinkedIn Page is connected in this workspace`.
:::

```json
{ "text": "We now deliver on Fridays.", "app": "nordwell" }
```

| Field | Type | Notes |
|---|---|---|
| `text` | string | Required. At most `3000` characters, LinkedIn's own limit for a post. |
| `app` | string | The handle of the app whose Page to publish to. |

`app` is needed only when more than one app in the workspace has a connected
Page. Then it is required, and the `400` lists the handles to choose from.
Publishing a company's words to the wrong company's Page is not something a
retry fixes, so the route will not guess.

Success is `201 Created`:

```json
{
  "success": true,
  "data": {
    "ext_id": "urn:li:share:7300000000000000000",
    "permalink_url": "https://www.linkedin.com/feed/update/urn:li:share:7300000000000000000/"
  }
}
```

`ext_id` is LinkedIn's id for the post. A refusal from LinkedIn itself comes
back as `400 BAD_REQUEST` with LinkedIn's reason in the message.

This is a separate scope from `core:write` on purpose. Posting in public as a
brand is not the same permission as posting into one conversation.

## Bind a signed-in user's token to their chat

```
PUT    /sessions/{sid}/mcp-credentials/{server}
DELETE /sessions/{sid}/mcp-credentials/{server}
```

Scope: `sessions:credentials`.

This is for one specific arrangement. You have embedded the widget in your own
product, where people are signed in. Your agent is connected to your product's
MCP server, and that server is set to **Per signed-in user** in the console. You
want the agent to see what this user may see, and nothing more.

Your backend makes that true. When a signed-in user opens the chat, your server
mints a short-lived token for that user on your own system and hands it to
Omazy for that one conversation. From then on, every call the agent makes to
your MCP server in that conversation carries the user's token.

`{sid}` is the conversation's id, the same one the widget's `session` event
reports. `{server}` is the name of the MCP server as it is set up on the app. It
is matched without regard to case.

```sh
curl -X PUT https://mw.omazy.ai/api/v1/core/sessions/9c1e2d3f-4a5b-4c6d-8e7f-0a1b2c3d4e5f/mcp-credentials/backoffice \
  -H "Authorization: Bearer $OMAZY_CORE_TOKEN" \
  -H "Content-Type: application/json" \
  -d @bind.json
```

`bind.json` holds three fields:

```json
{
  "token": "<the user's token for your MCP server>",
  "expires_at": "2026-11-19T15:00:00Z",
  "subject": { "id": "4410", "login": "sam", "name": "Sam Rivera" }
}
```

| Field | Type | Notes |
|---|---|---|
| `token` | string | Required. The user's token for your MCP server. At most `4096` characters. |
| `expires_at` | string | Required. An RFC 3339 time in the future, at most `24` hours ahead. |
| `subject.id` | string | Required. Your id for the user the token belongs to. |
| `subject.login`, `subject.name` | string | Optional. Kept for your own audit trail. |

```json
{
  "success": true,
  "data": {
    "bound": true,
    "subject_key": "4410",
    "expires_at": "2026-11-19T15:00:00Z",
    "verified": "whoami"
  }
}
```

Three checks happen before anything is stored, and each has its own failure.

**The token must belong to the user you named.** Omazy calls your MCP server's
`whoami` tool with the token and compares the `user.id` it reports with
`subject.id`. A mismatch is `403 FORBIDDEN`. Your MCP server must offer a
`whoami` tool that returns `{ "user": { "id": ... } }` for this to work.

A hosted server you do not run, such as Notion's, Slack's or Microsoft 365's,
has no `whoami`. For one of those, set the server's `subject_check` to `host`
(`PATCH /agent/mcp-servers/{id}`). Your backend ran the person's own sign-in
with that service, so it knows whose token it holds, and Omazy takes your word
for it: no call is made, and the answer's `verified` is `host`. Bind each
person's token to their own conversation only. The other two checks still
apply.

**A conversation belongs to one user for good.** The first bind locks the
conversation to that `subject.id`. Binding a different user's token later is
`409 CONFLICT`, even after the first token was removed. A chat that began as
one person cannot become another.

**Your MCP server must answer.** If it cannot be reached, or it rejects the
token, the bind fails with `502 UPSTREAM_REJECTED`. On a `host` server this
check is not made at bind time: a token the server refuses on the first call
is dropped, and the agent goes without that server's tools until you bind
again.

Mint short tokens. An hour is a good length. Bind again with a fresh token and
the same `subject.id` before the old one runs out.

`DELETE` removes the token, for example when the user signs out of your
product. It answers `200` with `{ "revoked": true }` whether or not a token was
bound, so you can call it on every sign-out without checking first.

| Status | Code | When |
|---|---|---|
| `400` | `BAD_REQUEST` | `token` or `subject.id` is missing, or `expires_at` is past or more than 24 hours ahead |
| `403` | `FORBIDDEN` | The token belongs to a different user than `subject.id` |
| `404` | `NOT_FOUND` | No such conversation in this workspace, or no per-user MCP server by that name on its app |
| `409` | `CONFLICT` | The conversation is already bound to another user |
| `502` | `UPSTREAM_REJECTED` | Your MCP server could not verify the token |
| `501` | `NOT_IMPLEMENTED` | Stored credentials are not enabled on this deployment |

The token is encrypted where it is stored and is never written to a log.
Connecting an MCP server to your agent in the first place is done in the
console.
