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

# Delete Player Data

> Delete all data of one player with one DELETE request: the profile, traits, events of every browser and game install, labels, account links, and Steam data. Use it when a player deletes their account.

Deletes all data of one player. Call it from your backend when a player deletes their account or asks you to erase their data. You cannot undo it.

The delete removes:

* The player's profile and traits
* All events of all the player's browsers and game installs, and their stored sessions
* Labels, on every key of the player
* Account links (Steam, itch.io, Discord)
* Steam ownership, purchases, summaries, and wishlist and library data
* Revenue record links: the billing records of the player's Stripe and Paddle customer IDs. An itch.io payment keeps its record without the user ID.

Postgres rows go at once. The analytics deletes run as background jobs. They finish within minutes. Reports change after that.

Owners and admins can also delete a player in the dashboard: open the profile, open **Danger zone** at the bottom of the left panel, and click **Delete player data**.

## Authentication

Use an API key (`mana_api_...`) with the **`profiles:delete`** 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 or admin now. When the creator's role goes below admin, the key loses `profiles:delete`.
* API keys for the REST API need the Studio plan (or a Studio trial). On Indie and the Launch Pass the answer is `402` `PLAN_UPGRADE_REQUIRED`.
* Call it from a server. A request with a browser `Origin` header gets `403`.
* The demo project is read-only: `403`.

`profiles:delete` is a scope of its own. `profiles:write` (trait edits) does not include it, so a key that edits traits cannot erase players. Give the delete key only `profiles:delete`.

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

For an identified player, send the `user:` key. It covers every browser and game install that links to that user only. An anonymous ID that belongs to one identified player gets `409` `NOT_CANONICAL` with that player's key in `error.player_key`: delete that player.

## Response

`202`:

```json theme={null}
{
  "request_id": "0f6f4b8e-1c2d-4e5f-8a9b-0c1d2e3f4a5b",
  "player_key": "user:player_42",
  "status": "queued",
  "installs": {
    "count": 2,
    "anonymous_ids": ["6a2f41a2-7d36-4c8e-9a54-2b1f9b0f0c11", "b1c2d3e4-f5a6-4b7c-8d9e-0f1a2b3c4d5e"]
  },
  "deleted": { "account_links": 1, "player_products": 1, "player_purchases": 0, "steam_player_summaries": 1, "steam_library_state": 1, "alert_segment_members": 0, "install_match_keys": 2, "itch_claims": 0, "itch_user_checks": 0, "itch_payments_unlinked": 0 },
  "jobs": ["user_profiles_mv", "anon_profiles_mv", "identity_links", "labels", "raw_events", "session_days (rebuild)"],
  "message": "The delete runs as background jobs. It finishes within minutes."
}
```

| Field | Notes |
| - | - |
| `request_id` | The ID of the delete request. Keep it with your erasure record. |
| `status` | `queued`: this call started the delete. `pending`: an earlier request of this player still runs; nothing new was queued. `done`: an earlier request finished and Manalens has no new data of the player. `failed`: a job of the earlier request failed; contact [support@manalens.dev](mailto:support@manalens.dev) with the `request_id`. |
| `installs` | The browsers and game installs that the delete covers |
| `deleted` | The rows deleted at once, by table. Only on the call that started the delete; `null` on a repeated call. |
| `jobs` | The background jobs: one for each analytics datasource, `raw_events` last |

The call is idempotent. Retry it after a timeout or a `5xx`: a repeated call returns the same request while it runs. After it finished, a call for a player with new data starts a new delete.

## Example

```bash theme={null}
curl -sS -X DELETE \
  -H "Authorization: Bearer $MANALENS_DELETE_KEY" \
  "https://api.manalens.dev/v0/projects/$PROJECT_ID/players/user%3Aplayer_42"
```

In your account delete handler:

```js theme={null}
async function eraseFromManalens(userId) {
  const key = encodeURIComponent(`user:${userId}`);
  const response = await fetch(`${API}/v0/projects/${projectId}/players/${key}`, {
    method: 'DELETE',
    headers: { authorization: `Bearer ${process.env.MANALENS_DELETE_KEY}` },
  });
  // 404: Manalens has no data of this player, so there is nothing to delete.
  if (response.status === 404) return null;
  if (!response.ok) throw new Error(`Manalens delete failed: ${response.status}`);
  return (await response.json()).request_id;
}
```

Stop sending events for the player first. Otherwise new events make a new player.

## Errors

| Status | Code | Meaning |
| - | - | - |
| `400` | `INVALID_PLAYER_KEY` | The player key is not `user:<user_id>` or `anon:<anonymous_id>` |
| `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. API keys for the REST API need the Studio plan. |
| `403` | `FORBIDDEN` | The key has no `profiles:delete` scope, its creator is not an owner or admin, 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 |
| `404` | `PLAYER_NOT_FOUND` | The project has no data of this player |
| `409` | `NOT_CANONICAL` | The anonymous ID belongs to an identified player. `error.player_key` is that player's key. |
| `422` | `PLAYER_TOO_LARGE` | The player has more than 1000 IDs of one kind. Contact support. |
| `429` | `TOO_MANY_REQUESTS` | The key or workspace budget is used up. Wait for `Retry-After`. |
| `429` | `RATE_LIMITED` | The project sent more than 60 player deletes this minute, or 5,000 this day |


## OpenAPI

````yaml DELETE /v0/projects/{projectId}/players/{playerKey}
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}:
    delete:
      tags:
        - Players
      summary: Delete player data
      description: >-
        Delete all data of one player: the profile and traits, the events of
        every browser and game install of the player, labels, account links
        (Steam, itch.io, Discord), Steam ownership, purchases, summaries,
        wishlist and library data, and the links of revenue records. Use it when
        a player deletes their account or asks for erasure. Postgres rows go at
        once; the analytics deletes run as background jobs and finish within
        minutes. It cannot be undone. A repeated call while the request runs
        returns the same request and queues nothing. Stop sending events for the
        player first: new events make a new player.
      operationId: deletePlayer
      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):'
      responses:
        '202':
          description: >-
            The delete is queued, or an earlier request of this player is
            returned
          content:
            application/json:
              schema:
                type: object
                properties:
                  request_id:
                    type: string
                    description: >-
                      The ID of the delete request. A repeated call returns the
                      same ID while the request runs.
                  player_key:
                    type: string
                    description: The player key
                  status:
                    type: string
                    enum:
                      - queued
                      - pending
                      - done
                      - failed
                    description: >-
                      `queued`: this call started the delete. `pending`: an
                      earlier request of this player still runs, and nothing new
                      was queued. `done`: an earlier request finished, and
                      Manalens has no new data of the player. `failed`: a job of
                      the earlier request failed; contact support.
                  installs:
                    type: object
                    properties:
                      count:
                        type: integer
                        minimum: -9007199254740991
                        maximum: 9007199254740991
                        description: >-
                          The number of browsers and game installs that the
                          delete covers
                      anonymous_ids:
                        type: array
                        items:
                          type: string
                        description: Their anonymous IDs
                    required:
                      - count
                      - anonymous_ids
                  deleted:
                    anyOf:
                      - type: object
                        propertyNames:
                          type: string
                        additionalProperties:
                          type: integer
                          minimum: -9007199254740991
                          maximum: 9007199254740991
                      - type: 'null'
                    description: >-
                      The rows deleted at once (account links, owned products,
                      purchases, Steam summaries and library state, itch.io
                      matches, segment alert members, install match keys). Only
                      on the call that started the delete; null on a repeated
                      call.
                  jobs:
                    type: array
                    items:
                      type: string
                    description: >-
                      The background jobs of the request: one per analytics
                      datasource, raw_events last
                  message:
                    type: string
                required:
                  - request_id
                  - player_key
                  - status
                  - installs
                  - deleted
                  - jobs
                  - message
              example:
                request_id: 0f6f4b8e-1c2d-4e5f-8a9b-0c1d2e3f4a5b
                player_key: user:player_42
                status: queued
                installs:
                  count: 2
                  anonymous_ids:
                    - 6a2f41a2-7d36-4c8e-9a54-2b1f9b0f0c11
                    - b1c2d3e4-f5a6-4b7c-8d9e-0f1a2b3c4d5e
                deleted:
                  account_links: 1
                  player_products: 1
                  player_purchases: 0
                jobs:
                  - user_profiles_mv
                  - labels
                  - raw_events
                message: >-
                  The delete runs as background jobs. It finishes within
                  minutes.
        '400':
          description: >-
            `INVALID_PLAYER_KEY`: the player key is not `user:<user_id>` or
            `anon:<anonymous_id>`
          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:delete` scope, its creator is
            not an owner or admin, the request came from a browser, or 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. `PLAYER_NOT_FOUND`:
            the project has no data of this player.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: >-
            `NOT_CANONICAL`: the anonymous ID belongs to an identified player.
            Delete that player: `error.player_key` is its key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '422':
          description: >-
            `PLAYER_TOO_LARGE`: the player has more than 1000 IDs of one kind.
            Contact support.
          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 60 player deletes this
            minute or 5000 this day.
          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.