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

# Set a Test User's Tag

> Creates or replaces a tag on a test user, to test tag-driven behavior such as segments.

> [!NOTE]
>
> Please review proper request headers [here](https://docs.thanx.com/consumer/usage/headers.md).

<Snippet file="sandbox/auth.mdx" />

If the user already has a tag with this `key` that was set through this endpoint, its values are replaced. To read a user's tags, use [Look Up Test Users](https://docs.thanx.com/consumer/sandbox/get-users.md).

### Parameters

**user\_id** `string` *required*

The user's `id`. The user must be a member of your merchant.

**key** `string` *required*

The tag key. Reserved tag names are rejected.

**values** `array(string)` *required*

The tag values. At least one non-empty value, at most 50.

### Response

Returns `201 Created` with an empty JSON object (`{}`).

### Errors

| Status | Code | Message | When |
| - | - | - | - |
| `400` | `BAD_REQUEST` | `maximum of 50 tag values` | More than 50 values |
| `400` | `BAD_REQUEST` | `values must not be empty` | Every value is blank |
| `400` | `BAD_REQUEST` | `key is a reserved tag name` | The key is reserved |
| `400` | `BAD_REQUEST` | `key is already set by another source` | The user already has this key from another source, for example a partner integration. This endpoint only manages tags it set. |
| `400` | `CLIENT_ID_HEADER_INVALID` | `X-ClientId header is invalid` | The `X-ClientId` header is missing or doesn't match an app |
| `403` | `FORBIDDEN` | `You do not have access to this resource.` | Called in production, or your `X-ClientId` isn't tied to exactly one merchant |
| `404` | `RESOURCE_NOT_FOUND` | `User not found` | No active user with this `user_id` is a member of your merchant |

```bash Set Tag theme={null}
curl https://api.thanxsandbox.com/users/${user_id}/tags \
  -X PUT \
  -H "Content-Type: application/json" \
  -H "Accept-Version: v4.0" \
  -H "Accept: application/json" \
  -H "X-ClientId: ${client_id}" \
  -d '{
    "key": "allergens",
    "values": ["gluten", "soy"]
  }'
```

```json theme={null}
{}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.