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

# Add a token to a user

> Registers one device token for a user against a provider key, overwriting the token if it already exists. Push sends resolve tokens per user.



## OpenAPI

````yaml /openapi-specs/openapi.documented.yml put /users/{user_id}/tokens/{token}
openapi: 3.0.1
info:
  title: Courier
  description: The Courier REST API for sending and managing notifications across channels.
  version: 0.0.1
servers:
  - url: https://api.courier.com
    description: Production
security: []
tags:
  - name: Send
    description: >-
      Send a message to one or more recipients — users, lists, audiences, or
      tenants — across every channel you have configured.
  - name: Templates
    description: >-
      Create, update, version, publish, and localize notification templates and
      their content.
  - name: Brands
    description: >-
      Manage the logos, colors, and layout that give the templates you send a
      consistent look.
  - name: Routing Strategies
    description: >-
      Define reusable channel routing and failover strategies, and see which
      templates use them.
  - name: Journeys
    description: >-
      Build, version, publish, invoke, and cancel multi-step notification
      workflows, along with the templates scoped to them.
  - name: Broadcasts
    description: >-
      Create a one-off send to a list or audience, author its content, then send
      it immediately or schedule it for later.
  - name: User Profiles
    description: >-
      Store the contact information Courier delivers to for each user — email,
      phone number, push tokens, and any custom data you send to.
  - name: Tenants
    description: >-
      Manage tenants — the organizations, teams, or accounts your users belong
      to — along with their users and default preferences.
  - name: Audiences
    description: >-
      Define filter-based groups whose membership Courier recalculates as user
      profiles change.
  - name: Lists
    description: >-
      Manage static groups of users that you subscribe explicitly, and send to
      them by list id or list pattern.
  - name: Providers
    description: >-
      Configure the channel providers Courier delivers through, and browse the
      provider types it supports.
  - name: Preference Topics
    description: >-
      Manage the workspace catalog of subscription topics, the sections that
      group them, and publishing the preference page.
  - name: User Preferences
    description: >-
      Read and write a single user's notification preferences, per topic and per
      channel.
  - name: Messages
    description: >-
      Look up the messages Courier has accepted, inspect their delivery history
      and rendered output, and cancel, resend, or archive them.
  - name: Device Tokens
    description: >-
      Register and manage the APNS and FCM device tokens Courier delivers push
      notifications to.
  - name: Tenant Memberships
    description: >-
      Associate a user with one or more tenants, and read or remove those
      associations.
  - name: Tenant Templates
    description: >-
      Manage the templates and template versions scoped to a single tenant,
      including the ones authored in the embedded designer.
  - name: Automations
    description: >-
      Invoke a stored automation template or an ad hoc automation defined in the
      request.
  - name: Digests
    description: >-
      Inspect what has accumulated in a digest schedule and release a digest
      ahead of its next scheduled delivery.
  - name: Translations
    description: >-
      Store and retrieve the translation strings Courier uses to render
      localized template content.
  - name: Track Events
    description: >-
      Record an inbound event that triggers the journeys and automations mapped
      to it.
  - name: Audit Events
    description: >-
      Read the audit trail of configuration and access changes in your
      workspace.
  - name: Authentication
    description: >-
      Issue scoped, short-lived JWTs so client-side SDKs — Inbox, Preferences,
      and the embedded designer — can call Courier as a single user. Server-side
      requests authenticate with your workspace API key instead.
paths:
  /users/{user_id}/tokens/{token}:
    put:
      tags:
        - Device Tokens
      summary: Add a token to a user
      description: >-
        Registers one device token for a user against a provider key,
        overwriting the token if it already exists. Push sends resolve tokens
        per user.
      operationId: users_tokens_add
      parameters:
        - name: user_id
          in: path
          description: The user's ID. This can be any uniquely identifiable string.
          required: true
          schema:
            type: string
        - name: token
          in: path
          description: The full token string.
          required: true
          schema:
            type: string
          x-stainless-param: token_id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UsersAddSingleTokenBody'
            examples:
              Example:
                value:
                  provider_key: firebase-fcm
                  device:
                    app_id: com.example.app
      responses:
        '204':
          description: ''
        '400':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BadRequest'
              examples:
                Example:
                  value:
                    message: Example message text
                    type: invalid_request_error
      security:
        - BearerAuth: []
      x-codeSamples:
        - lang: JavaScript
          source: |-
            import Courier from '@trycourier/courier';

            const client = new Courier({
              apiKey: process.env['COURIER_API_KEY'], // This is the default and can be omitted
            });

            await client.users.tokens.addSingle('token', {
              user_id: 'user_id',
              provider_key: 'firebase-fcm',
              device: { app_id: 'com.example.app' },
            });
        - lang: Python
          source: |-
            import os
            from courier import Courier

            client = Courier(
                api_key=os.environ.get("COURIER_API_KEY"),  # This is the default and can be omitted
            )
            client.users.tokens.add_single(
                token="token",
                user_id="user_id",
                provider_key="firebase-fcm",
                device={
                    "app_id": "com.example.app"
                },
            )
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\n\t\"github.com/trycourier/courier-go/v4\"\n\t\"github.com/trycourier/courier-go/v4/option\"\n)\n\nfunc main() {\n\tclient := courier.NewClient(\n\t\toption.WithAPIKey(\"My API Key\"),\n\t)\n\terr := client.Users.Tokens.AddSingle(\n\t\tcontext.TODO(),\n\t\t\"token\",\n\t\tcourier.UserTokenAddSingleParams{\n\t\t\tUserID:      \"user_id\",\n\t\t\tProviderKey: courier.UserTokenAddSingleParamsProviderKeyFirebaseFcm,\n\t\t\tDevice: courier.UserTokenAddSingleParamsDevice{\n\t\t\t\tAppID: courier.String(\"com.example.app\"),\n\t\t\t},\n\t\t},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n}\n"
        - lang: Java
          source: |-
            package com.courier.example;

            import com.courier.client.CourierClient;
            import com.courier.client.okhttp.CourierOkHttpClient;
            import com.courier.models.users.tokens.TokenAddSingleParams;

            public final class Main {
                private Main() {}

                public static void main(String[] args) {
                    CourierClient client = CourierOkHttpClient.fromEnv();

                    TokenAddSingleParams params = TokenAddSingleParams.builder()
                        .userId("user_id")
                        .token("token")
                        .providerKey(TokenAddSingleParams.ProviderKey.FIREBASE_FCM)
                        .build();
                    client.users().tokens().addSingle(params);
                }
            }
        - lang: Ruby
          source: >-
            require "courier"


            courier = Courier::Client.new(api_key: "My API Key")


            result = courier.users.tokens.add_single("token", user_id:
            "user_id", provider_key: :"firebase-fcm")


            puts(result)
        - lang: PHP
          source: >-
            <?php


            require_once dirname(__DIR__) . '/vendor/autoload.php';


            use Courier\Client;

            use Courier\Core\Exceptions\APIException;


            $client = new Client(apiKey: getenv('COURIER_API_KEY') ?: 'My API
            Key');


            try {
              $result = $client->users->tokens->addSingle(
                'token',
                userID: 'user_id',
                providerKey: 'firebase-fcm',
                device: [
                  'adID' => 'ad_id',
                  'appID' => 'com.example.app',
                  'deviceID' => 'device_id',
                  'manufacturer' => 'manufacturer',
                  'model' => 'model',
                  'platform' => 'platform',
                ],
                expiryDate: 'string',
                properties: (object) [],
                tracking: [
                  'ip' => 'ip',
                  'lat' => 'lat',
                  'long' => 'long',
                  'osVersion' => 'os_version',
                ],
              );

              var_dump($result);
            } catch (APIException $e) {
              echo $e->getMessage();
            }
        - lang: C#
          source: |-
            using TryCourier;
            using TryCourier.Models.Users.Tokens;

            CourierClient client = new();

            TokenAddSingleParams parameters = new()
            {
                UserID = "user_id",
                Token = "token",
                ProviderKey = ProviderKey.FirebaseFcm,
            };

            await client.Users.Tokens.AddSingle(parameters);
        - lang: CLI
          source: |-
            courier users:tokens add-single \
              --api-key 'My API Key' \
              --user-id user_id \
              --token token \
              --provider-key firebase-fcm
components:
  schemas:
    UsersAddSingleTokenBody:
      title: UsersAddSingleTokenBody
      type: object
      description: >-
        Request body for adding a single token. The token value itself is
        provided via the path parameter, so it is omitted from the body.
      properties:
        provider_key:
          $ref: '#/components/schemas/UsersProviderKey'
        expiry_date:
          $ref: '#/components/schemas/UsersExpiryDate'
          nullable: true
          description: >-
            ISO 8601 formatted date the token expires. Defaults to 2 months. Set
            to false to disable expiration.
        properties:
          nullable: true
          description: Properties about the token.
        device:
          $ref: '#/components/schemas/UsersDevice'
          nullable: true
          description: Information about the device the token came from.
        tracking:
          $ref: '#/components/schemas/UsersTracking'
          nullable: true
          description: Tracking information about the device the token came from.
      required:
        - provider_key
    BadRequest:
      title: BadRequest
      type: object
      properties:
        type:
          type: string
          enum:
            - invalid_request_error
      required:
        - type
      allOf:
        - $ref: '#/components/schemas/BaseError'
    UsersProviderKey:
      title: UsersProviderKey
      type: string
      enum:
        - firebase-fcm
        - apn
        - expo
        - onesignal
    UsersExpiryDate:
      title: UsersExpiryDate
      oneOf:
        - type: string
        - type: boolean
    UsersDevice:
      title: UsersDevice
      type: object
      properties:
        app_id:
          type: string
          nullable: true
          description: Id of the application the token is used for
        ad_id:
          type: string
          nullable: true
          description: Id of the advertising identifier
        device_id:
          type: string
          nullable: true
          description: Id of the device the token is associated with
        platform:
          type: string
          nullable: true
          description: The device platform i.e. android, ios, web
        manufacturer:
          type: string
          nullable: true
          description: The device manufacturer
        model:
          type: string
          nullable: true
          description: The device model
    UsersTracking:
      title: usersTracking
      type: object
      properties:
        os_version:
          type: string
          nullable: true
          description: The operating system version
        ip:
          type: string
          nullable: true
          description: The IP address of the device
        lat:
          type: string
          nullable: true
          description: The latitude of the device
        long:
          type: string
          nullable: true
          description: The longitude of the device
    BaseError:
      title: BaseError
      type: object
      properties:
        message:
          type: string
          description: A message describing the error that occurred.
      required:
        - message
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer

````