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

# Link a Steam account

> Link the Steam account that runs the game to the game install (`anonymous_id`) with a Steam ticket. The player does not sign in. Use the publishable key in `X-Publishable-Key`, or the secret key as `Authorization: Bearer` from a game server. With the publishable key, a web build must run on the project domain or an allowed origin. A game sends no Origin.

Manalens checks the ticket with Steam (`ISteamUserAuth/AuthenticateUserTicket`), with the project's Steam Web API key, the project's App ID and the fixed identity `manalens`. Then it reads which apps of the project the account owns (`ISteamUser/GetPublisherAppOwnership`): at the first link, and again when the last read is older than 15 days. When the ownership read fails, the link is still saved and the answer is 200. The response never contains the SteamID.

The checks run in this order: the body, the key, the Steam connection, the rate limits, then Steam. A request that fails a check before the rate limits does not count against them. Send it to the API host only: events.manalens.dev serves only `POST /v0/events`.



## OpenAPI

````yaml /api/openapi.json post /v0/link
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/link:
    post:
      tags:
        - Accounts
      summary: Link a Steam account
      description: >-
        Link the Steam account that runs the game to the game install
        (`anonymous_id`) with a Steam ticket. The player does not sign in. Use
        the publishable key in `X-Publishable-Key`, or the secret key as
        `Authorization: Bearer` from a game server. With the publishable key, a
        web build must run on the project domain or an allowed origin. A game
        sends no Origin.


        Manalens checks the ticket with Steam
        (`ISteamUserAuth/AuthenticateUserTicket`), with the project's Steam Web
        API key, the project's App ID and the fixed identity `manalens`. Then it
        reads which apps of the project the account owns
        (`ISteamUser/GetPublisherAppOwnership`): at the first link, and again
        when the last read is older than 15 days. When the ownership read fails,
        the link is still saved and the answer is 200. The response never
        contains the SteamID.


        The checks run in this order: the body, the key, the Steam connection,
        the rate limits, then Steam. A request that fails a check before the
        rate limits does not count against them. Send it to the API host only:
        events.manalens.dev serves only `POST /v0/events`.
      operationId: linkAccount
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                provider:
                  type: string
                  const: steam
                  description: The store. Only `steam` today.
                ticket:
                  type: string
                  pattern: ^(?:[0-9a-fA-F]{2}){16,2048}$
                  description: >-
                    The bytes of the Steam ticket from
                    `GetAuthTicketForWebApi("manalens")`, as a hex string: 32 to
                    4096 hex characters, an even number
                anonymous_id:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  description: The SDK anonymous ID of this game install (a UUID)
                user_id:
                  description: >-
                    Secret key only (a game server): the user ID to store with
                    the link. With the publishable key it is checked but not
                    stored. A stored user ID is never replaced.
                  type: string
                  minLength: 1
                  maxLength: 255
                  pattern: ^[^\u0000-\u001f]+$
              required:
                - provider
                - ticket
                - anonymous_id
              description: Fields that are not in this list are ignored.
            example:
              provider: steam
              ticket: 140000000a0b0c0d0e0f101112131415
              anonymous_id: 6a2f41a2-7d36-4c8e-9a54-2b1f9b0f0c11
      responses:
        '200':
          description: Steam accepted the ticket and the link is saved
          content:
            application/json:
              schema:
                type: object
                properties:
                  linked:
                    type: boolean
                    const: true
                  provider:
                    type: string
                    const: steam
                required:
                  - linked
                  - provider
              example:
                linked: true
                provider: steam
        '400':
          description: >-
            `INVALID_JSON`: the body is not valid JSON. `INVALID_BODY`: a field
            is missing or does not match the rules. The message names the field.
            `STEAM_TICKET_INVALID`: Steam did not accept the ticket (it is
            expired, for another app, or not made with the identity `manalens`).
            Get a new ticket and try again.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  code: STEAM_TICKET_INVALID
                  message: >-
                    Steam did not accept this ticket. Get a new ticket for the
                    identity "manalens" and try again.
        '401':
          description: >-
            `UNAUTHORIZED`: the key is missing, malformed, unknown or revoked,
            or in the wrong header, or the request has both keys
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: >-
            `FORBIDDEN`: the Origin does not match the project (publishable key
            only). `WORKSPACE_SUSPENDED`: the workspace takes no events.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: >-
            `STEAM_NOT_CONNECTED`: the project has no Steam Web API key or App
            ID on the Connect Steam card
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '413':
          description: '`TOO_LARGE`: the body is larger than 2 MB'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: >-
            `RATE_LIMITED`: more than 30 link calls from one IP address in 10
            minutes, more than 5 from one game install in 10 minutes, or more
            than 600 for the project in one minute. The headers give the limit
            that the request hit.
          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'
        '502':
          description: >-
            `STEAM_KEY_REFUSED`: Steam refused the project's Steam Web API key.
            Manalens does not use a refused key again until an owner saves a
            key. `STEAM_UNAVAILABLE`: Manalens could not reach Steam. Retry
            later.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '503':
          description: >-
            `NOT_CONFIGURED`: the server cannot read the saved Steam key, or
            integration encryption is not configured on the server
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - PublishableKey: []
        - SecretKey: []
      servers:
        - url: https://api.manalens.dev
          description: API
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:
    PublishableKey:
      type: apiKey
      in: header
      name: X-Publishable-Key
      description: >-
        The publishable key (`mana_pk_...`). It sends web and app events and
        links Steam accounts.
    SecretKey:
      type: http
      scheme: bearer
      description: >-
        The secret key (`mana_sk_...`), from your backend only. It sends server
        events and links Steam accounts.

````

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