# Assign or Remove Tags Beta

> Attach or detach tags on up to 1,000 resources.

> Documentation index: https://www.foxreach.io/docs/llms.txt lists every page of these docs. Each page is also served as Markdown: add `.md` to its URL.

`POST` https://api.foxreach.io/api/v1/tags/toggle

> **Note:** **Beta.** This endpoint is new and may change.

Requires an API key with the `write` scope.

Attaches (`assign: true`) or detaches (`assign: false`) up to 10 tags on up to 1,000 leads, campaigns or email accounts in one call. Every tag must be of the matching type: `lead` tags for `lead`, `campaign` tags for `campaign`, `account` tags for `email_account`. A warmup tag, a tag of another workspace or a tag of the wrong type returns `422` and nothing changes. Resource ids that are not in the workspace (or are deleted leads) do not fail the call: they are listed in `notFound` and the rest apply. Attaching a tag that is already on a resource changes nothing. For more than 1,000 leads use [Bulk Tag Leads](https://www.foxreach.io/docs/api-reference/leads/bulk-tag). An `audit.tag.assigned` or `audit.tag.unassigned` entry records the tags and the counts.

## Request Body

- `tagIds` string[] body required: 1 to 10 tag ids.
- `resourceType` string body required: `lead`, `campaign` or `email_account`.
- `resourceIds` string[] body required: 1 to 1,000 ids.
- `assign` boolean body required: `true` attaches, `false` detaches.

## Response

`assigned` (or `unassigned`) is how many tag and resource pairs changed, `matched` how many of the ids were found, `notFound` the ids that were not.

**Request example**

```bash cURL
curl -X POST "https://api.foxreach.io/api/v1/tags/toggle" \
  -H "X-API-Key: otr_your_key" \
  -H "Content-Type: application/json" \
  -d '{"tagIds": ["tag_abc123"], "resourceType": "campaign", "resourceIds": ["cmp_1", "cmp_2"], "assign": true}'
```

```python Python SDK (beta)
from foxreach import FoxReach

client = FoxReach(api_key="otr_your_key")
result = client.tags.assign(["tag_abc123"], "campaign", ["cmp_1", "cmp_2"])
```

```typescript TypeScript SDK (beta)
import { FoxReach } from "foxreach";

const client = new FoxReach({ apiKey: "otr_your_key" });
const result = await client.tags.assign(["tag_abc123"], "campaign", ["cmp_1", "cmp_2"]);
```

**Response example**

```json
{
  "data": { "assigned": 2, "matched": 2, "notFound": [] }
}
```

## Errors

| Status | Description |
|--------|-------------|
| `401` | Missing, invalid, revoked or expired API key |
| `403` | API key does not have the required scope: `write` |
| `422` | A tag is not a tag of this type in the workspace, a list is empty, or more than 1,000 resource ids were sent |

## Rate Limit

- **120 requests per minute, shared by every `write` call in your workspace.** Fixed 60-second window.
- Every response includes `X-RateLimit-Limit`, `X-RateLimit-Remaining`, `X-RateLimit-Reset` (unix epoch seconds) and `X-RateLimit-Bucket` (`write`).
- A `429` response includes a `Retry-After` header (seconds until the bucket resets).

For client-side patterns, see [Rate Limiting](https://www.foxreach.io/docs/rate-limiting).
