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

# Update Traits

> Merge-update the traits of one identified player. Set a Discord ID, Steam ID, email, socials or any custom trait, or send null to delete a trait, in one PUT request.

Sets and deletes traits on the profile of one identified player. Traits are the data that describes a player; event data stays "properties". Keys that you do not send keep their values. The response returns the merged traits, so you do not need a second read.

## Authentication

Use an API key (`mana_api_...`) with the **`profiles:write`** scope. See [Authentication](https://docs.manalens.dev/api/authentication.md#api-keys).

* The key works on its own project only. Another project's key gets `404`.
* The key's creator must be an owner, admin or editor.
* Call it from a server. A request with a browser `Origin` header gets `403`.

Editors can also change traits on the profile's **Traits** tab.

## Path parameters

| Parameter | Rule |
| - | - |
| `projectId` | The project ID |
| `playerKey` | `user:<user_id>`, where `user_id` is the ID that you send with `identify` (1 to 255 characters). URL-encode the whole key, for example `user%3Aplayer_42`. |

This endpoint writes user traits only, so an `anon:` key gets `400`: identify the player first. Anonymous traits come from a [`traits` event](https://docs.manalens.dev/data/events/overview) without a `user_id`. If no profile exists for the `user_id`, the write creates it.

## Body

A flat object of traits. Send 1 to 50 keys, at most 8 KB as JSON. The whole body is at most 16 KB.

| Rule | Value |
| - | - |
| Key | Starts with a letter, then letters, digits, `_`, `.` or `-`. At most 100 characters. |
| Value | A string (at most 1024 characters), a number, a boolean, or `null` |
| `null` | Deletes the trait |
| Reserved keys | `user_id` (it is the profile key, so it cannot be set or unset here) |
| Reserved value | The string `_is_deleted` (an internal marker). Send `null` to delete. |

[Known traits](https://docs.manalens.dev/data/known-traits.md) such as `discord_id` and `steam_id` must be strings and pass a light format check. Any other key is a custom trait.

This endpoint is a trusted channel, so it can set the [protected traits](https://docs.manalens.dev/data/known-traits.md#protected-traits) (`email`, `itch_user_id`, `stripe_customer_id` and `paddle_customer_id`). A game or website cannot set them.

```json theme={null}
{
  "discord_id": "112233445566778899",
  "display_name": "Luca",
  "twitter": null,
  "level": 12
}
```

## Response

`200`:

```json theme={null}
{
  "player_key": "user:player_42",
  "user_id": "player_42",
  "traits": {
    "discord_id": "112233445566778899",
    "display_name": "Luca",
    "level": 12,
    "supporter": true
  },
  "set": ["discord_id", "display_name", "level"],
  "deleted": ["twitter"],
  "updated_at": "2026-11-15T12:00:00.000Z"
}
```

| Field | Notes |
| - | - |
| `traits` | The user traits after this write: the traits read before the write, with this update merged in |
| `set`, `deleted` | The keys that this request set and deleted |
| `updated_at` | The time of the write |

Reports, the Players page, and `GET` reads show the write after a few seconds.

## Delete a trait

Send `null`. Set and delete can go in the same request:

```bash theme={null}
curl -sS -X PUT \
  -H "Authorization: Bearer $MANALENS_PROJECT_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "discord_id": "112233445566778899", "twitter": null }' \
  "https://api.manalens.dev/v0/projects/$PROJECT_ID/players/user%3Aplayer_42/traits"
```

## Link a Discord account

A Discord bot or your website links a player to a Discord account with one call:

```js theme={null}
await fetch(`${API}/v0/projects/${projectId}/players/${encodeURIComponent(`user:${userId}`)}/traits`, {
  method: 'PUT',
  headers: { authorization: `Bearer ${process.env.MANALENS_PROJECT_KEY}`, 'content-type': 'application/json' },
  body: JSON.stringify({ discord_id: interaction.user.id, discord: interaction.user.username }),
});
```

To unlink, send `{ "discord_id": null, "discord": null }`. Keep the key in server-side secrets.

## Errors

| Status | Code | Meaning |
| - | - | - |
| `400` | `INVALID_TRAITS` | A key, a value, or the `playerKey` failed validation (for example, it does not start with `user:`). The message names the key, never the value. Nothing is written. |
| `401` | `UNAUTHORIZED` | The key is missing, unknown or revoked |
| `402` | `SUBSCRIPTION_REQUIRED` | The workspace has no active subscription or trial |
| `402` | `PLAN_UPGRADE_REQUIRED` | The workspace is on Indie or the Launch Pass. Player traits need the Studio plan. |
| `403` | `FORBIDDEN` | The key has no `profiles:write` scope, its creator is below editor, or the request came from a browser |
| `403` | `WORKSPACE_SUSPENDED` | The workspace is suspended. API keys of a suspended workspace get no access. |
| `404` | `NOT_FOUND` | The key belongs to another project |
| `413` | `TOO_LARGE` | The body is larger than 16 KB |
| `429` | `TOO_MANY_REQUESTS` | The key or workspace budget is used up. Wait for `Retry-After`. |
| `429` | `RATE_LIMITED` | The project sent too many server events and trait writes this minute |

`PUT` is idempotent: you can retry the same body after a `429` or a `5xx`.


## OpenAPI

````yaml PUT /v0/projects/{projectId}/players/{playerKey}/traits
openapi: 3.1.0
info:
  title: Manalens API
  version: 0.1.0
  description: >-
    The public API of Manalens: event ingestion, Steam account links, player
    traits and the Query API. Success bodies are the resource, with no envelope.
    Errors use the `Error` format. See https://docs.manalens.dev/api/overview.
servers:
  - url: https://api.manalens.dev
    description: API
  - url: https://events.manalens.dev
    description: Event ingestion
security: []
tags:
  - name: Events
    description: Send website, game and server events
  - name: Accounts
    description: Link the Steam account of a player to the game install
  - name: Players
    description: Set and delete the traits of identified players
  - name: Query
    description: Read analytics reports with an API key
paths:
  /v0/projects/{projectId}/players/{playerKey}/traits:
    put:
      tags:
        - Players
      summary: Update traits
      description: >-
        Merge-update the traits of one identified player. Keys that you do not
        send keep their values. null deletes a trait. The response has the
        merged traits. At most 50 traits and 8 KB of JSON in one call.
      operationId: updatePlayerTraits
      parameters:
        - name: projectId
          in: path
          required: true
          description: The project ID
          schema:
            type: string
            format: uuid
        - name: playerKey
          in: path
          required: true
          description: >-
            The player key of an identified player: `user:` and the user ID that
            you send with identify (1 to 255 characters). URL-encode it, for
            example `user%3Aplayer-42`.
          schema:
            type: string
            minLength: 6
            maxLength: 260
            pattern: '^user:'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              propertyNames:
                type: string
                pattern: ^[A-Za-z][A-Za-z0-9_.-]{0,99}$
              additionalProperties:
                anyOf:
                  - type: string
                    maxLength: 1024
                  - type: number
                  - type: boolean
                  - type: 'null'
              description: >-
                1 to 50 traits, at most 8 KB as JSON. A value is a string (at
                most 1024 characters), a number, a boolean, or null to delete
                the trait. user_id is reserved.
      responses:
        '200':
          description: The player traits after the write
          content:
            application/json:
              schema:
                type: object
                properties:
                  player_key:
                    type: string
                    description: 'user: and the user ID'
                  user_id:
                    type: string
                  traits:
                    type: object
                    propertyNames:
                      type: string
                    additionalProperties:
                      anyOf:
                        - type: string
                          maxLength: 1024
                        - type: number
                        - type: boolean
                        - type: 'null'
                    description: >-
                      The user traits read before the write, with this update
                      merged in
                  set:
                    type: array
                    items:
                      type: string
                    description: The keys that this request set
                  deleted:
                    type: array
                    items:
                      type: string
                    description: The keys that this request deleted
                  updated_at:
                    type: string
                    description: The time of the write (ISO 8601)
                required:
                  - player_key
                  - user_id
                  - traits
                  - set
                  - deleted
                  - updated_at
        '400':
          description: >-
            `INVALID_TRAITS`: a key, a value, the player key or the user ID
            failed validation, or the traits of a player are over 50 keys or 8
            KB. Nothing is written.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: >-
            `UNAUTHORIZED`: the API key is missing, malformed, unknown or
            revoked
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '402':
          description: >-
            `SUBSCRIPTION_REQUIRED`: the workspace has no active subscription or
            trial. `PLAN_UPGRADE_REQUIRED`: API keys need the Studio plan
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: >-
            `FORBIDDEN`: the key has no `profiles:write` scope, its creator is
            below editor, or the request came from a browser.
            `WORKSPACE_SUSPENDED`: the workspace is suspended.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: >-
            `NOT_FOUND`: the key belongs to another project, or the resource
            does not exist
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '413':
          description: >-
            `TOO_LARGE`: the body is larger than the limit (16 KB for one
            player, 200 KB for a batch)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: >-
            `TOO_MANY_REQUESTS`: the key or workspace budget is used up.
            `RATE_LIMITED`: the project sent too many server events and trait
            writes this minute.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          headers:
            Retry-After:
              description: Seconds to wait before a retry
              schema:
                type: integer
            RateLimit-Limit:
              description: The limit of the window, when it is known
              schema:
                type: integer
            RateLimit-Policy:
              description: '`<limit>;w=<window seconds>`, when the limit is known'
              schema:
                type: string
            RateLimit-Remaining:
              description: Always 0 on a 429
              schema:
                type: integer
            RateLimit-Reset:
              description: Seconds until the window resets (the same as Retry-After)
              schema:
                type: integer
        '500':
          description: '`INTERNAL`: an unexpected error. The body has a `request_id`.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - ApiKey: []
components:
  schemas:
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              description: A stable, machine-readable code. Branch on it.
            message:
              type: string
              description: A human-readable text. The wording can change.
            request_id:
              description: 'INTERNAL only: quote it when you contact support'
              type: string
            issues:
              description: 'INVALID_EVENT only: up to five validation issues'
              type: array
              items:
                type: object
                properties:
                  path:
                    type: string
                    description: Where the problem is, such as `events.0.properties`
                  message:
                    type: string
                    description: What is wrong, such as `at most 50 keys`
                required:
                  - path
                  - message
            refused:
              description: >-
                INVALID_EVENT when no event of the batch is accepted: each
                refused event (the same list as `errors`, kept for SDKs that
                read it here)
              type: array
              items:
                type: object
                properties:
                  index:
                    type: integer
                    minimum: -9007199254740991
                    maximum: 9007199254740991
                    description: The position of the event in the batch
                  message_id:
                    description: The message_id of the event, or null when it has none
                    type:
                      - string
                      - 'null'
                  code:
                    type: string
                    description: >-
                      The reason code, such as `INVALID_EVENT`,
                      `SESSION_ID_REQUIRED` or `FORBIDDEN`
                  message:
                    type: string
                    description: 'What is wrong, such as `properties: at most 50 keys`'
                required:
                  - index
                  - message_id
                  - code
                  - message
            results:
              description: 'INVALID_TRAITS of a batch trait update: the result of each item'
              type: array
              items:
                type: object
                properties:
                  index:
                    type: integer
                    minimum: -9007199254740991
                    maximum: 9007199254740991
                  user_id:
                    type: string
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                      message:
                        type: string
                    required:
                      - code
                      - message
                required:
                  - index
            feature:
              description: >-
                PLAN_UPGRADE_REQUIRED only: the plan feature that the request
                needs
              type: string
            billing_url:
              description: 'PLAN_UPGRADE_REQUIRED only: the billing page of the workspace'
              type: string
          required:
            - code
            - message
      required:
        - error
      description: >-
        The error format of every endpoint. See
        https://docs.manalens.dev/api/errors.
  securitySchemes:
    ApiKey:
      type: http
      scheme: bearer
      description: >-
        An API key (`mana_api_...`) with scopes. It reads reports and writes
        player traits.

````

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