> ## 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.

# Batch Update Traits

> Set or delete traits for up to 100 identified players in one request. Each item is a flat object with a required user_id. null deletes a trait. Each item gets its own result, so one bad item does not fail the batch.

Use this endpoint for a backfill or a sync, for example to link many players to their Discord accounts at once. Authentication and the trait rules are the same as for [Update Traits](https://docs.manalens.dev/api/players/update-traits.md).

## Body

An array of 1 to 100 items. Each item is a flat object: `user_id` plus the traits for that player. Items use the plain `user_id`, not the player key. The body is at most 200 KB.

```json theme={null}
[
  { "user_id": "player_42", "discord_id": "112233445566778899" },
  { "user_id": "player_43", "steam_id": "STEAM_0:1:12345", "twitter": null }
]
```

| Rule | Value |
| - | - |
| `user_id` | Required in each item. 1 to 255 characters. |
| Traits | 1 to 50 per item, at most 8 KB as JSON per item. The same key and value rules as the single endpoint. |
| Same `user_id` twice | The second item fails. Merge its traits into the first item. |

## Response

`200` when at least one item is valid. `results` has one entry per item, in request order:

```json theme={null}
{
  "updated": 1,
  "failed": 1,
  "updated_at": "2026-11-15T12:00:00.000Z",
  "results": [
    { "index": 0, "user_id": "player_42", "set": ["discord_id"], "deleted": [] },
    { "index": 1, "user_id": "player_43", "error": { "code": "INVALID_TRAITS", "message": "steam_id must be a SteamID64 (17 digits, 76561197960265729 to 76561202255233023)" } }
  ]
}
```

Valid items are written; failed items are not. When no item is valid, the response is `400` with `INVALID_TRAITS` and the same `results`. The batch response does not return the merged traits; read a player with [Get Player](https://docs.manalens.dev/api/query/player.md), with MCP `get_player`, or on the profile's **Traits** tab.

## Delete traits in a batch

Send `null`. Set and delete can mix in one item and across items:

```bash theme={null}
curl -sS -X PUT \
  -H "Authorization: Bearer $MANALENS_PROJECT_KEY" \
  -H "Content-Type: application/json" \
  -d '[
    { "user_id": "player_42", "discord_id": null, "discord": null },
    { "user_id": "player_43", "discord_id": "998877665544332211" }
  ]' \
  "https://api.manalens.dev/v0/projects/$PROJECT_ID/players/traits"
```

## Errors

Request errors are the same as for [Update Traits](https://docs.manalens.dev/api/players/update-traits.md#errors), with a 200 KB body limit. A request-level `400` (not an array, or more than 100 items) writes nothing.


## OpenAPI

````yaml PUT /v0/projects/{projectId}/players/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/traits:
    put:
      tags:
        - Players
      summary: Batch update traits
      description: >-
        Set or delete traits for 1 to 100 identified players. Each item has a
        user_id and the traits of that player (at most 50 traits and 8 KB of
        JSON). Each item gets its own result, so one bad item does not fail the
        batch. The body is at most 200 KB.
      operationId: batchUpdatePlayerTraits
      parameters:
        - name: projectId
          in: path
          required: true
          description: The project ID
          schema:
            type: string
            format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              minItems: 1
              maxItems: 100
              type: array
              items:
                type: object
                properties:
                  user_id:
                    type: string
                    minLength: 1
                    maxLength: 255
                required:
                  - user_id
                additionalProperties:
                  anyOf:
                    - type: string
                      maxLength: 1024
                    - type: number
                    - type: boolean
                    - type: 'null'
      responses:
        '200':
          description: >-
            At least one item is valid. `results` has one entry per item, in
            request order.
          content:
            application/json:
              schema:
                type: object
                properties:
                  updated:
                    type: integer
                    minimum: -9007199254740991
                    maximum: 9007199254740991
                  failed:
                    type: integer
                    minimum: -9007199254740991
                    maximum: 9007199254740991
                  updated_at:
                    type: string
                  results:
                    type: array
                    items:
                      type: object
                      properties:
                        index:
                          type: integer
                          minimum: -9007199254740991
                          maximum: 9007199254740991
                        user_id:
                          type: string
                        set:
                          type: array
                          items:
                            type: string
                        deleted:
                          type: array
                          items:
                            type: string
                        error:
                          type: object
                          properties:
                            code:
                              type: string
                            message:
                              type: string
                          required:
                            - code
                            - message
                      required:
                        - index
                required:
                  - updated
                  - failed
                  - updated_at
                  - results
        '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.