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

> ## Agent Instructions
> Install the Courier skill before writing code: `npx skills add trycourier/courier-skills`. It carries the verified SDK shapes and the rules you cannot get wrong.
> Authenticate every request with `Authorization: Bearer <API_KEY>`. A workspace has several environments and each has its own keys, which are plain `pk_` strings with no environment prefix. Start with Test.
> Send with `client.send.message` from the Node SDK (`@trycourier/courier` v7 and later, where the client is the default import). Reference a template by its `nt_` id or its alias.
> A send accepts a bare Elemental element list, but storing content on a template requires the top-level elements wrapped in a channel element.
> Templates and journeys can be built in the Courier app or created through the API. Either way they live in the workspace and are referenced by ID when you send.
> The hosted MCP server is https://mcp.courier.com. For a briefing on what Courier is and when to use it, read https://www.courier.com/llms.txt.
> Prefer the Guides tab for how-do-I questions and the Docs tab for how-does-it-behave questions. The API reference lives under /api-reference.

# Send push with OneSignal through Courier

> Connect OneSignal with an App ID and REST API key, and target a Player ID or External User ID.

export const Endpoint = ({method, path, name, href, children, bare}) => {
  const verb = String(method || "").toUpperCase();
  const title = verb + " " + path;
  const label = children || name || path;
  if (bare) {
    return href ? <a href={href}><code>{title}</code></a> : <code>{title}</code>;
  }
  if (!href) {
    return <span className="cx-endpoint" data-method={verb} title={title}>
        <span className="cx-endpoint-label">{label}</span>
        <span className="cx-endpoint-method">{verb}</span>
      </span>;
  }
  return <a className="cx-endpoint" data-method={verb} href={href} title={title}>
      <span className="cx-endpoint-label">{label}</span>
      <span className="cx-endpoint-method">{verb}</span>
    </a>;
};

export const AppLink = ({href, children, name, bare}) => {
  const label = children || name || "Open in Courier";
  if (bare) {
    return <a href={href} target="_blank" rel="noreferrer">{label}</a>;
  }
  return <a className="cx-endpoint" data-kind="app" href={href} target="_blank" rel="noreferrer">
      <span className="cx-endpoint-label">{label}</span>
      <span className="cx-endpoint-method" aria-hidden="true">↗</span>
    </a>;
};

export const Doc = ({href, children, name, bare}) => {
  const label = children || name || href;
  if (bare) {
    return <a href={href}>{label}</a>;
  }
  return <a className="cx-endpoint" data-kind="doc" href={href}>
      <span className="cx-endpoint-label">{label}</span>
      <span className="cx-endpoint-method">DOC</span>
    </a>;
};

## Prerequisites

* [A OneSignal account with an app](https://onesignal.com/)
* [Your OneSignal `App ID` and `REST API Key`](https://documentation.onesignal.com/docs/accounts-and-keys)

## Setup

<Steps>
  <Step title="Get your OneSignal keys">
    In OneSignal, open [accounts and keys](https://documentation.onesignal.com/docs/accounts-and-keys) and copy your App ID and REST API Key.
  </Step>

  <Step title="Configure in Courier">
    Open the <AppLink href="https://app.courier.com/integrations/catalog/onesignal">OneSignal Integration</AppLink> in Courier, enter your `App ID` and `REST API Key`, then click "Save."
  </Step>
</Steps>

## Profile requirements

Device tokens live on the user profile rather than on the send, so one profile can hold tokens for several devices and every push provider reads them from the same place. <Doc href="/docs/send/push/overview">Send push</Doc> covers the model.

OneSignal addresses the recipient by [PlayerId](https://documentation.onesignal.com/docs/users#section-player-id) or [ExternalId](https://documentation.onesignal.com/docs/user-model-migration-guide#user-model). Store either one once with <Endpoint method="POST" path="/profiles/{user_id}" name="Create a Profile" href="/docs/api-reference/user-profiles/create-a-profile" />, which merges into the profile and creates it if it does not exist:

<Tabs>
  <Tab title="Player ID">
    The id OneSignal assigned the device.

    <CodeGroup>
      ```javascript Node.js highlight={3} theme={null}
      const profile = await client.profiles.create('user_123', {
        profile: {
          oneSignalPlayerID: 'YOUR_ONESIGNAL_PLAYER_ID',
        },
      });
      ```

      ```python Python highlight={4} theme={null}
      profile = client.profiles.create(
          user_id="user_123",
          profile={
              "oneSignalPlayerID": "YOUR_ONESIGNAL_PLAYER_ID",
          },
      )
      ```

      ```bash cURL highlight={7} theme={null}
      curl --request POST \
        --url https://api.courier.com/profiles/user_123 \
        --header "Authorization: Bearer $COURIER_API_KEY" \
        --header 'Content-Type: application/json' \
        --data '{
          "profile": {
            "oneSignalPlayerID": "YOUR_ONESIGNAL_PLAYER_ID"
          }
        }'
      ```

      ```ruby Ruby highlight={4} theme={null}
      profile = courier.profiles.create(
        "user_123",
        profile: {
          oneSignalPlayerID: "YOUR_ONESIGNAL_PLAYER_ID"
        }
      )
      ```

      ```go Go highlight={6} theme={null}
      profile, err := client.Profiles.New(
      	context.TODO(),
      	"user_123",
      	courier.ProfileNewParams{
      		Profile: map[string]any{
      			"oneSignalPlayerID": "YOUR_ONESIGNAL_PLAYER_ID",
      		},
      	},
      )
      ```

      ```java Java highlight={4} theme={null}
      ProfileCreateParams params = ProfileCreateParams.builder()
          .userId("user_123")
          .profile(ProfileCreateParams.Profile.builder()
              .putAdditionalProperty("oneSignalPlayerID", JsonValue.from("YOUR_ONESIGNAL_PLAYER_ID"))
              .build())
          .build();
      ProfileCreateResponse profile = client.profiles().create(params);
      ```

      ```php PHP highlight={2} theme={null}
      $profile = $client->profiles->create('user_123', profile: [
        'oneSignalPlayerID' => 'YOUR_ONESIGNAL_PLAYER_ID',
      ]);
      ```

      ```csharp C# highlight={6} theme={null}
      ProfileCreateParams parameters = new()
      {
          UserID = "user_123",
          Profile = new Dictionary<string, JsonElement>()
          {
              { "oneSignalPlayerID", JsonSerializer.SerializeToElement("YOUR_ONESIGNAL_PLAYER_ID") },
          },
      };
      var profile = await client.Profiles.Create(parameters);
      ```

      ```bash CLI highlight={4} wrap theme={null}
      courier profiles create \
        --api-key "$COURIER_API_KEY" \
        --user-id user_123 \
        --profile '{"oneSignalPlayerID":"YOUR_ONESIGNAL_PLAYER_ID"}'
      ```

      ```text MCP theme={null}
      With Courier MCP, save the OneSignal player id YOUR_ONESIGNAL_PLAYER_ID on user_123.
      ```
    </CodeGroup>
  </Tab>

  <Tab title="External ID">
    The id your own system uses, once you have set it in OneSignal.

    <CodeGroup>
      ```javascript Node.js highlight={3} theme={null}
      const profile = await client.profiles.create('user_123', {
        profile: {
          oneSignalExternalUserId: 'user_123',
        },
      });
      ```

      ```python Python highlight={4} theme={null}
      profile = client.profiles.create(
          user_id="user_123",
          profile={
              "oneSignalExternalUserId": "user_123",
          },
      )
      ```

      ```bash cURL highlight={7} theme={null}
      curl --request POST \
        --url https://api.courier.com/profiles/user_123 \
        --header "Authorization: Bearer $COURIER_API_KEY" \
        --header 'Content-Type: application/json' \
        --data '{
          "profile": {
            "oneSignalExternalUserId": "user_123"
          }
        }'
      ```

      ```ruby Ruby highlight={4} theme={null}
      profile = courier.profiles.create(
        "user_123",
        profile: {
          oneSignalExternalUserId: "user_123"
        }
      )
      ```

      ```go Go highlight={6} theme={null}
      profile, err := client.Profiles.New(
      	context.TODO(),
      	"user_123",
      	courier.ProfileNewParams{
      		Profile: map[string]any{
      			"oneSignalExternalUserId": "user_123",
      		},
      	},
      )
      ```

      ```java Java highlight={4} theme={null}
      ProfileCreateParams params = ProfileCreateParams.builder()
          .userId("user_123")
          .profile(ProfileCreateParams.Profile.builder()
              .putAdditionalProperty("oneSignalExternalUserId", JsonValue.from("user_123"))
              .build())
          .build();
      ProfileCreateResponse profile = client.profiles().create(params);
      ```

      ```php PHP highlight={2} theme={null}
      $profile = $client->profiles->create('user_123', profile: [
        'oneSignalExternalUserId' => 'user_123',
      ]);
      ```

      ```csharp C# highlight={6} theme={null}
      ProfileCreateParams parameters = new()
      {
          UserID = "user_123",
          Profile = new Dictionary<string, JsonElement>()
          {
              { "oneSignalExternalUserId", JsonSerializer.SerializeToElement("user_123") },
          },
      };
      var profile = await client.Profiles.Create(parameters);
      ```

      ```bash CLI highlight={4} wrap theme={null}
      courier profiles create \
        --api-key "$COURIER_API_KEY" \
        --user-id user_123 \
        --profile '{"oneSignalExternalUserId":"user_123"}'
      ```

      ```text MCP theme={null}
      With Courier MCP, save the OneSignal external user id user_123 on user_123.
      ```
    </CodeGroup>
  </Tab>
</Tabs>

Then send to `user_id` and Courier resolves the address.

For a one-off with no stored profile, pass it inline instead: `"to": { "oneSignalPlayerID": "YOUR_ONESIGNAL_PLAYER_ID" }`.

<CardGroup cols={1}>
  <Card title="Send by user id" icon="user" href="/docs/recipients/overview#send-by-user-id">
    The call in every language, and the rest of the profile object.
  </Card>
</CardGroup>

## Send to a recipient

<Tabs>
  <Tab title="Send to user id">
    Courier reads `oneSignalPlayerID` off the saved profile, so preferences apply and the value can change without touching this code.

    <CodeGroup>
      ```javascript Node.js highlight={4} theme={null}
      const { requestId } = await courier.send.message({
        message: {
          to: {
            user_id: "user_123",
          },
          template: "nt_01kx4h2jdafq8bk9aftxak4b40",
        },
      });
      ```

      ```python Python highlight={4} theme={null}
      response = client.send.message(
          message={
              "to": {
                  "user_id": "user_123",
              },
              "template": "nt_01kx4h2jdafq8bk9aftxak4b40",
          },
      )
      ```

      ```bash cURL highlight={7} wrap theme={null}
      curl -X POST https://api.courier.com/send \
        -H "Authorization: Bearer $COURIER_API_KEY" \
        -H "Content-Type: application/json" \
        -d '{
          "message": {
            "to": {
              "user_id": "user_123"
            },
            "template": "nt_01kx4h2jdafq8bk9aftxak4b40"
          }
        }'
      ```

      ```ruby Ruby highlight={4} theme={null}
      response = courier.send_.message(
        message: {
          to: {
            user_id: "user_123"
          },
          template: "nt_01kx4h2jdafq8bk9aftxak4b40"
        }
      )
      ```

      ```go Go highlight={5} theme={null}
      response, err := client.Send.Message(context.TODO(), courier.SendMessageParams{
      	Message: courier.SendMessageParamsMessage{
      		To: courier.SendMessageParamsMessageToUnion{
      			OfUserRecipient: &shared.UserRecipientParam{
      				UserID: courier.String("user_123"),
      			},
      		},
      		Template: courier.String("nt_01kx4h2jdafq8bk9aftxak4b40"),
      	},
      })
      ```

      ```java Java highlight={3} theme={null}
      SendMessageParams params = SendMessageParams.builder()
          .message(SendMessageParams.Message.builder()
              .to(UserRecipient.builder().userId("user_123").build())
              .template("nt_01kx4h2jdafq8bk9aftxak4b40")
              .build())
          .build();
      SendMessageResponse response = client.send().message(params);
      ```

      ```php PHP highlight={4} theme={null}
      $response = $client->send->message(
        message: [
          'to' => [
            'user_id' => 'user_123',
          ],
          'template' => 'nt_01kx4h2jdafq8bk9aftxak4b40',
        ],
      );
      ```

      ```csharp C# highlight={5} theme={null}
      SendMessageParams parameters = new()
      {
          Message = new()
          {
              To = new UserRecipient { UserID = "user_123" },
              Template = "nt_01kx4h2jdafq8bk9aftxak4b40",
          },
      };

      var response = await client.Send.Message(parameters);
      ```

      ```bash CLI highlight={3} wrap theme={null}
      courier send message \
        --api-key "$COURIER_API_KEY" \
        --message.to '{"user_id": "user_123"}' \
        --message.template nt_01kx4h2jdafq8bk9aftxak4b40
      ```

      ```text MCP theme={null}
      With Courier MCP, send my template to user_123 by email.
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Send to `oneSignalPlayerID`">
    Pass it inline instead and nothing is stored. Swap this `to` object into the call on the other tab.

    <CodeGroup>
      ```javascript Node.js highlight={5} theme={null}
      const { requestId } = await courier.send.message({
        message: {
          // A provider recipient is a profile field, so it sits outside the typed union.
          to: {
            oneSignalPlayerID: "...",
          } as any,
          template: "nt_01kx4h2jdafq8bk9aftxak4b40",
        },
      });
      ```

      ```python Python highlight={4} theme={null}
      response = client.send.message(
          message={
              "to": {
                  "oneSignalPlayerID": "...",
              },
              "template": "nt_01kx4h2jdafq8bk9aftxak4b40",
          },
      )
      ```

      ```bash cURL highlight={7} wrap theme={null}
      curl -X POST https://api.courier.com/send \
        -H "Authorization: Bearer $COURIER_API_KEY" \
        -H "Content-Type: application/json" \
        -d '{
          "message": {
            "to": {
              "oneSignalPlayerID": "..."
            },
            "template": "nt_01kx4h2jdafq8bk9aftxak4b40"
          }
        }'
      ```

      ```ruby Ruby highlight={4} theme={null}
      response = courier.send_.message(
        message: {
          to: {
            oneSignalPlayerID: "..."
          },
          template: "nt_01kx4h2jdafq8bk9aftxak4b40"
        }
      )
      ```

      ```go Go highlight={3} theme={null}
      // A provider recipient is a profile field, so it sits outside the typed union.
      to := param.Override[shared.UserRecipientParam](
      	json.RawMessage(`{"oneSignalPlayerID": "..."}`),
      )

      response, err := client.Send.Message(context.TODO(), courier.SendMessageParams{
      	Message: courier.SendMessageParamsMessage{
      		To: courier.SendMessageParamsMessageToUnion{OfUserRecipient: &to},
      		Template: courier.String("nt_01kx4h2jdafq8bk9aftxak4b40"),
      	},
      })
      ```

      ```java Java highlight={3} theme={null}
      // A provider recipient is a profile field, so it sits outside the typed union.
      UserRecipient to = UserRecipient.builder()
          .putAdditionalProperty("oneSignalPlayerID", JsonValue.from("..."))
          .build();

      client.send().message(SendMessageParams.builder()
          .message(SendMessageParams.Message.builder()
              .to(to)
              .template("nt_01kx4h2jdafq8bk9aftxak4b40")
              .build())
          .build());
      ```

      ```php PHP highlight={4} theme={null}
      $response = $client->send->message(
        message: [
          'to' => [
            'oneSignalPlayerID' => '...',
          ],
          'template' => 'nt_01kx4h2jdafq8bk9aftxak4b40',
        ],
      );
      ```

      ```csharp C# highlight={4} theme={null}
      // A provider recipient is a profile field, so it sits outside the typed union.
      UserRecipient to = UserRecipient.FromRawUnchecked(
          JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(
              """{"oneSignalPlayerID": "..."}"""
          )
      );

      var response = await client.Send.Message(new() { Message = new() { To = to, Template = "nt_01kx4h2jdafq8bk9aftxak4b40" } });
      ```

      ```bash CLI highlight={3} wrap theme={null}
      courier send message \
        --api-key "$COURIER_API_KEY" \
        --message.to '{"oneSignalPlayerID": "..."}' \
        --message.template nt_01kx4h2jdafq8bk9aftxak4b40
      ```

      ```text MCP theme={null}
      With Courier MCP, send my template to that OneSignal player id.
      ```
    </CodeGroup>
  </Tab>
</Tabs>

## Overrides

<Doc href="/docs/send/overrides#how-overrides-work">How overrides work</Doc> covers the two levels and which one wins. <Doc href="/docs/integrations/push/overview#channel-overrides">Push channel overrides</Doc> lists the fields every push provider takes.

A provider override changes the request body Courier sends to OneSignal's API, and takes any field supported by OneSignal's [Create notification](https://documentation.onesignal.com/reference/create-notification) endpoint.

<CodeGroup>
  ```javascript Node.js highlight={8-16} theme={null}
  const { requestId } = await courier.send.message({
    message: {
      template: "nt_01kx4h2jdafq8bk9aftxak4b40",
      to: {
        oneSignalPlayerID: "player-id-123",
      },
      providers: {
        onesignal: {
          override: {
            body: {
              priority: 10,
              ttl: 3600,
              small_icon: "ic_notification",
            },
          },
        },
      },
    },
  });
  ```

  ```python Python highlight={8-16} theme={null}
  response = client.send.message(
      message={
          "template": "nt_01kx4h2jdafq8bk9aftxak4b40",
          "to": {
              "oneSignalPlayerID": "player-id-123",
          },
          "providers": {
              "onesignal": {
                  "override": {
                      "body": {
                          "priority": 10,
                          "ttl": 3600,
                          "small_icon": "ic_notification",
                      },
                  },
              },
          },
      },
  )
  ```

  ```bash cURL highlight={11-19} wrap theme={null}
  curl -X POST https://api.courier.com/send \
    -H "Authorization: Bearer $COURIER_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "message": {
        "template": "nt_01kx4h2jdafq8bk9aftxak4b40",
        "to": {
          "oneSignalPlayerID": "player-id-123"
        },
        "providers": {
          "onesignal": {
            "override": {
              "body": {
                "priority": 10,
                "ttl": 3600,
                "small_icon": "ic_notification"
              }
            }
          }
        }
      }
    }'
  ```

  ```ruby Ruby highlight={8-16} theme={null}
  response = courier.send_.message(
    message: {
      template: "nt_01kx4h2jdafq8bk9aftxak4b40",
      to: {
        oneSignalPlayerID: "player-id-123"
      },
      providers: {
        onesignal: {
          override: {
            body: {
              priority: 10,
              ttl: 3600,
              small_icon: "ic_notification"
            }
          }
        }
      }
    }
  )
  ```

  ```go Go highlight={12-20} theme={null}
  // This provider addresses the recipient with fields outside the typed
  // UserRecipient model, so pass the recipient as raw JSON.
  to := param.Override[shared.UserRecipientParam](json.RawMessage(`{
    "oneSignalPlayerID": "player-id-123"
  }`))

  response, err := client.Send.Message(context.TODO(), courier.SendMessageParams{
  	Message: courier.SendMessageParamsMessage{
  		To: courier.SendMessageParamsMessageToUnion{OfUserRecipient: &to},
  		Template: courier.String("nt_01kx4h2jdafq8bk9aftxak4b40"),
  		Providers: shared.MessageProvidersParam{
  			"onesignal": shared.MessageProvidersTypeParam{
  				Override: map[string]any{
  					"body": map[string]any{
  						"priority": 10,
  						"ttl": 3600,
  						"small_icon": "ic_notification",
  					},
  				},
  			},
  		},
  	},
  })
  ```

  ```java Java highlight={10-16} theme={null}
  SendMessageParams params = SendMessageParams.builder()
      .message(SendMessageParams.Message.builder()
          // This provider addresses the recipient with fields outside the
          // typed UserRecipient model, so pass them as additional properties.
          .to(UserRecipient.builder()
              .putAdditionalProperty("oneSignalPlayerID", JsonValue.from("player-id-123"))
              .build())
          .template("nt_01kx4h2jdafq8bk9aftxak4b40")
          .providers(MessageProviders.builder()
              .putAdditionalProperty("onesignal", JsonValue.from(java.util.Map.of("override", java.util.Map.of(
                      "body", java.util.Map.of(
                          "priority", 10,
                          "ttl", 3600,
                          "small_icon", "ic_notification"
                      )
                  ))))
              .build())
          .build())
      .build();
  SendMessageResponse response = client.send().message(params);
  ```

  ```php PHP highlight={8-16} theme={null}
  $response = $client->send->message(
    message: [
      'template' => 'nt_01kx4h2jdafq8bk9aftxak4b40',
      'to' => [
        'oneSignalPlayerID' => 'player-id-123',
      ],
      'providers' => [
        'onesignal' => [
          'override' => [
            'body' => [
              'priority' => 10,
              'ttl' => 3600,
              'small_icon' => 'ic_notification',
            ],
          ],
        ],
      ],
    ],
  );
  ```

  ```csharp C# highlight={19-35} theme={null}
  SendMessageParams parameters = new()
  {
      Message = new()
      {
          // This provider addresses the recipient with fields outside the
          // typed UserRecipient model, so build it from raw JSON.
          To = UserRecipient.FromRawUnchecked(
              JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(
                  """
                  {
                    "oneSignalPlayerID": "player-id-123"
                  }
                  """
              )
          ),
          Template = "nt_01kx4h2jdafq8bk9aftxak4b40",
          Providers = new Dictionary<string, MessageProvidersType>()
          {
              {
                  "onesignal",
                  new()
                  {
                      Override = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(
                          """
                          {
                            "body": {
                              "priority": 10,
                              "ttl": 3600,
                              "small_icon": "ic_notification"
                            }
                          }
                          """
                      ),
                  }
              },
          },
      },
  };

  var response = await client.Send.Message(parameters);
  ```

  ```bash CLI highlight={5} wrap theme={null}
  courier send message \
    --api-key "$COURIER_API_KEY" \
    --message.to '{"oneSignalPlayerID": "player-id-123"}' \
    --message.template nt_01kx4h2jdafq8bk9aftxak4b40 \
    --message.providers '{"onesignal": {"override": {"body": {"priority": 10, "ttl": 3600, "small_icon": "ic_notification"}}}}'
  ```

  ```text MCP theme={null}
  With Courier MCP, send my template to this OneSignal player id with a body override.
  ```
</CodeGroup>

## Data mapping

OneSignal imposes a limit to push notification payloads. When sending push notifications through automated workflows that include batching, data payloads can become too large, which will result in a failed send.

Enable data mapping on the push channel to choose which fields reach the provider. <Doc href="/docs/design/templates/data-mapping">Data mapping</Doc> covers the template setting.

<Frame caption="OneSignal Data Mapping">
  <img src="https://mintcdn.com/courier-4f1f25dc/xDJPBS8EQ58X_0-v/assets/onesignal-data-map.webp?fit=max&auto=format&n=xDJPBS8EQ58X_0-v&q=85&s=cc318546a0407b6a72cf3622b169aa23" width="1025" height="601" data-path="assets/onesignal-data-map.webp" />
</Frame>

## Provider details

```text theme={null}
onesignal
```

Courier recommends routing to the channel. Naming this key in `routing.channels` instead is supported, and sends through just this provider.

<Card title="Send to a specific provider" icon="bullseye-arrow" href="/docs/send/send-to-a-provider" horizontal arrow="true">
  When that is worth doing, and what you give up: failover, channel priority, and providers you add later.
</Card>
