JavaScript
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' },
});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"
},
)package main
import (
"context"
"github.com/trycourier/courier-go/v4"
"github.com/trycourier/courier-go/v4/option"
)
func main() {
client := courier.NewClient(
option.WithAPIKey("My API Key"),
)
err := client.Users.Tokens.AddSingle(
context.TODO(),
"token",
courier.UserTokenAddSingleParams{
UserID: "user_id",
ProviderKey: courier.UserTokenAddSingleParamsProviderKeyFirebaseFcm,
Device: courier.UserTokenAddSingleParamsDevice{
AppID: courier.String("com.example.app"),
},
},
)
if err != nil {
panic(err.Error())
}
}
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);
}
}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)<?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();
}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);courier users:tokens add-single \
--api-key 'My API Key' \
--user-id user_id \
--token token \
--provider-key firebase-fcmcurl --request PUT \
--url https://api.courier.com/users/{user_id}/tokens/{token} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"provider_key": "firebase-fcm",
"device": {
"app_id": "com.example.app"
}
}
'{
"message": "Example message text",
"type": "invalid_request_error"
}Device Tokens
Add single token to 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.
PUT
/
users
/
{user_id}
/
tokens
/
{token}
JavaScript
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' },
});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"
},
)package main
import (
"context"
"github.com/trycourier/courier-go/v4"
"github.com/trycourier/courier-go/v4/option"
)
func main() {
client := courier.NewClient(
option.WithAPIKey("My API Key"),
)
err := client.Users.Tokens.AddSingle(
context.TODO(),
"token",
courier.UserTokenAddSingleParams{
UserID: "user_id",
ProviderKey: courier.UserTokenAddSingleParamsProviderKeyFirebaseFcm,
Device: courier.UserTokenAddSingleParamsDevice{
AppID: courier.String("com.example.app"),
},
},
)
if err != nil {
panic(err.Error())
}
}
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);
}
}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)<?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();
}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);courier users:tokens add-single \
--api-key 'My API Key' \
--user-id user_id \
--token token \
--provider-key firebase-fcmcurl --request PUT \
--url https://api.courier.com/users/{user_id}/tokens/{token} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"provider_key": "firebase-fcm",
"device": {
"app_id": "com.example.app"
}
}
'{
"message": "Example message text",
"type": "invalid_request_error"
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Path Parameters
The user's ID. This can be any uniquely identifiable string.
The full token string.
Body
application/json
Request body for adding a single token. The token value itself is provided via the path parameter, so it is omitted from the body.
Available options:
firebase-fcm, apn, expo, onesignal ISO 8601 formatted date the token expires. Defaults to 2 months. Set to false to disable expiration.
Properties about the token.
Information about the device the token came from.
Show child attributes
Show child attributes
Tracking information about the device the token came from.
Show child attributes
Show child attributes
Response
⌘I