---
docId: doc_cec21127b5ec488397e0a9a350ae178e
title: Tag contacts
description: Add or remove tags on many contacts at once, by id, phone number or the result of a search.
api:
  group: clientes
  auth: bearer
  operations:
    - operationId: tagClients
      method: POST
      path: /v1/clients/tags
      postmanName: Tag Clients
---

<script>
  import { Ways, Collapsible } from '$lib/components';
</script>

# Tag contacts

Add or remove tags on up to 500 contacts per call. Identify them by ID or phone number in `clientIds`, or use the `searchId` of a [search](/api-reference/contacts/search).

## Example

<Ways tabs="api,sdk,asistente">
<Ways.Way name="api">

```bash
curl -X POST https://api.platic.ai/v1/clients/tags \
  -H "Authorization: Bearer $PLATIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "tags": ["spring_sale"], "searchId": "'"$SEARCH_ID"'" }'
```

</Ways.Way>
<Ways.Way name="sdk">

```ts
const result = await platic.clients.tag({ tags: ["spring_sale"], searchId: "search_123" });
console.log(result.updatedCount, result.notFound);
```

</Ways.Way>
<Ways.Way name="asistente">
<Ways.Say>

Tag the VIP customers in Mexico City with spring_sale.

</Ways.Say>

Your assistant searches with `search_clients` and tags with `tag_clients`.

</Ways.Way>
</Ways>

Tags must exist in the workspace ([create a tag](/api-reference/tags/create)). To remove them, send `"operation": "remove"`. If the contact does not have the tag, nothing changes.

## Request body

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `operation` | string | — | `add` (default) or `remove` |
| `tags` | string[] | ✓ | The tag names, from 1 to 20 |
| `clientIds` | string[] | one of the two | Contact ids or phone numbers, up to 500 |
| `searchId` | string | one of the two | The `searchId` of a search: it applies to all its results |
| `topN` | number | — | With `searchId`, only the first N results |

You can send `clientIds` and `searchId` together; between the two they cannot exceed 500 contacts.

## Response

```json
{
  "status": "success",
  "data": {
    "operation": "add",
    "tags": ["spring_sale"],
    "updatedCount": 310,
    "unchangedCount": 2,
    "notFound": []
  }
}
```

| Field | Description |
|-------|-------------|
| `updatedCount` | Contacts that changed |
| `unchangedCount` | Contacts that were already as you asked. Repeating the call changes nothing |
| `notFound` | The ids or phone numbers that belong to no contact |

Each contact that changes sends [`client.tags.updated`](/api-reference/webhooks/payloads#customers) with `source` `api.clients.tagged` or `api.clients.untagged`.

## Errors

<Collapsible summary="Show error codes and fixes">

| Status | `details.code` | When it happens |
|--------|----------------|-----------------|
| `400` | `INVALID_REQUEST` | A field is not valid: `operation`, `tags`, `clientIds`, `searchId` or `topN`. If you send neither `clientIds` nor `searchId`, `details.issues` points at `clientIds`; `topN` without `searchId` points at `topN` |
| `400` | `INVALID_REQUEST` | The credential covers several workspaces and `?workspace=` is missing, or the supplied workspace is not authorized. `details.available` lists the available ones and `details.requested` shows the one you sent |
| `400` | `TAG_NOT_FOUND` | When adding, a tag does not exist. `details.invalidTags` says which |
| `400` | `TOO_MANY_CLIENTS` | More than 500 contacts. Use `topN` or split the list |
| `400` | `NO_CLIENTS` | The search returned no contacts |
| `401` | `UNAUTHENTICATED` | The credential is missing or invalid |
| `403` | `FORBIDDEN` | The credential does not have the Contacts module (`Missing contacts permission`), or the user's role is read-only |
| `403` | `INSUFFICIENT_SCOPE` | An OAuth token without the `platica:write` scope tried to write. `details.requiredScope` says which one is missing |
| `404` | `SEARCH_NOT_FOUND` | The `searchId` does not exist |
| `410` | `SEARCH_EXPIRED` | The `searchId` expired: search again |
| `4xx` | `UPSTREAM_REFUSED` | Platica refused the operation. The status is the one it answered and `details.message` carries its text |
| `502` | `UPSTREAM_ERROR` | Platica failed to complete the operation. Try again |

The general error format is in [Errors](/api-reference/errors).

</Collapsible>
