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

# Set Player Consent

> Record the tracking consent of one player: none, anonymous or full, with its source. Manalens stores the record and leaves enforcement to you.

Records the tracking consent of one player. When a player answers your consent banner or changes the choice in your settings, call it from your backend. A new call replaces the record.

**Manalens does not enforce consent.** It stores the record so that you can read it back and show it in an audit. You decide what your SDKs and servers send for each level:

| Status | Send |
| - | - |
| `none` | Nothing. See [consent mode](https://docs.manalens.dev/guides/consent.md) for the SDK opt-out calls. |
| `anonymous` | Events without a user ID and without personal data |
| `full` | Everything |

## Authentication

Use an API key (`mana_api_...`) with the **`consent: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.
* It works on every plan. The workspace needs an active subscription or trial.
* Call it from a server. A request with a browser `Origin` header gets `403`.
* The demo project is read-only: `403`.

Give the key only `consent:write`. Use a separate key for [player deletes](https://docs.manalens.dev/api/players/delete-player.md).

## Path parameters

| Parameter | Rule |
| - | - |
| `projectId` | The project ID |
| `playerKey` | `user:<user_id>`, where `user_id` is the ID that you send with `identify`, or `anon:<anonymous_id>` for a player that never identified. URL-encode the whole key, for example `user%3Aplayer_42`. An anonymous ID is stored in lowercase. |

You can record consent before the player has any data in Manalens.

## Body

| Field | Rule |
| - | - |
| `status` | Required. `none`, `anonymous` or `full`. |
| `source` | Required. Where the player chose, for example `cookie-banner-v1`. 1 to 128 characters, no control characters. |

```json theme={null}
{ "status": "anonymous", "source": "cookie-banner-v1" }
```

## Response

`200` with the stored record:

```json theme={null}
{
  "player_key": "user:player_42",
  "status": "anonymous",
  "source": "cookie-banner-v1",
  "updated_at": "2026-12-03T10:00:00.000Z"
}
```

## Example

```bash theme={null}
curl -sS -X PUT \
  -H "Authorization: Bearer $MANALENS_CONSENT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"status":"anonymous","source":"cookie-banner-v1"}' \
  "https://api.manalens.dev/v0/projects/$PROJECT_ID/players/user%3Aplayer_42/consent"
```

## Deleting the record

[Deleting the player](https://docs.manalens.dev/api/players/delete-player.md) deletes the record of the user key and of every anonymous ID that the delete covers. Deleting the project also deletes the record. The audit log has a `player.consent_set` row for each write. The row holds a hash of the player key, the status and the source, never the player's IDs.

## Errors

| Status | Code | Meaning |
| - | - | - |
| `400` | `INVALID_PLAYER_KEY` | The player key is not `user:<user_id>` or `anon:<anonymous_id>` |
| `400` | `VALIDATION_ERROR` | `status` or `source` is missing or invalid |
| `401` | `UNAUTHORIZED` | The key is missing, malformed, unknown or revoked |
| `402` | `SUBSCRIPTION_REQUIRED` | The workspace has no active subscription or trial |
| `403` | `FORBIDDEN` | The key has no `consent:write` scope. Or its creator is not an owner, admin or editor. Or the request came from a browser. Or the project is the demo project. |
| `403` | `WORKSPACE_SUSPENDED` | The workspace is suspended |
| `404` | `NOT_FOUND` | The key belongs to another project |
| `429` | `RATE_LIMITED` | The project sent more than 600 consent requests this minute. Wait for `Retry-After` seconds. |

See [Errors](https://docs.manalens.dev/api/errors.md) for the error format.


## OpenAPI

````yaml PUT /v0/projects/{projectId}/players/{playerKey}/consent
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, player deletes 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}/consent:
    put:
      tags:
        - Players
      summary: Set player consent
      description: >-
        Record the tracking consent of one player: none, anonymous or full, with
        the source of the choice. A new call replaces the record. Manalens
        stores the record and does not enforce it.
      operationId: setPlayerConsent
      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: `user:` and the user ID that you send with identify
            (1 to 255 characters), or `anon:` and an anonymous ID (a UUID) for a
            player that never identified. URL-encode it, for example
            `user%3Aplayer-42`.
          schema:
            type: string
            minLength: 6
            maxLength: 260
            pattern: '^(user|anon):'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                status:
                  type: string
                  enum:
                    - none
                    - anonymous
                    - full
                  description: >-
                    `none`: no tracking. `anonymous`: tracking without identity
                    or personal data. `full`: all tracking.
                source:
                  type: string
                  minLength: 1
                  maxLength: 128
                  description: >-
                    Where the player chose, for example `cookie-banner-v1`. 1 to
                    128 characters.
              required:
                - status
                - source
            example:
              status: anonymous
              source: cookie-banner-v1
      responses:
        '200':
          description: The record was written
          content:
            application/json:
              schema:
                type: object
                properties:
                  player_key:
                    type: string
                    description: The player key, with an anonymous ID in lowercase
                  status:
                    type: string
                    enum:
                      - not_set
                      - none
                      - anonymous
                      - full
                    description: >-
                      `none`: the player declined tracking. `anonymous`: the
                      player allows tracking without identity. `full`: the
                      player allows full tracking. `not_set`: no record exists,
                      so treat it as `none`.
                  source:
                    description: >-
                      Where the consent was given, as you sent it, for example
                      `cookie-banner-v1`. `null` for `not_set`.
                    type:
                      - string
                      - 'null'
                  updated_at:
                    description: >-
                      When the record was last written (ISO 8601). `null` for
                      `not_set`.
                    type:
                      - string
                      - 'null'
                required:
                  - player_key
                  - status
                  - source
                  - updated_at
              example:
                player_key: user:player_42
                status: anonymous
                source: cookie-banner-v1
                updated_at: '2026-12-03T10:00:00.000Z'
        '400':
          description: >-
            `INVALID_PLAYER_KEY`: the player key is not `user:<user_id>` or
            `anon:<anonymous_id>`. `VALIDATION_ERROR`: `status` or `source` is
            missing or invalid.
          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. Consent records work on every plan.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: >-
            `FORBIDDEN`: the key has no `consent:write` scope, its creator is
            not an owner, admin or editor, the request came from a browser, or
            (PUT) the project is the demo project. `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'
        '429':
          description: >-
            `TOO_MANY_REQUESTS`: the key or workspace budget is used up.
            `RATE_LIMITED`: the project sent more than 600 consent requests 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.