Send a notification through Platform API
These APIs are used to send a notification to either a single user or multiple users through an in-app notification channel. Depending on the number of recipients, the value of mode
should differ: realtime
and batch
.
Note: Sendbird Business Messaging supports both v1 and v2 APIs. The v2 API is used for sending notifications, while the v1 API is used for other RESTful APIs.
Notification mode
There are two types of notification mode, determined by the size of the recipients.
-
realtime
: This mode targets a single user and the notification message will be sent in real time. The notification will be sent in real-time to one target user by settingmode
torealtime
. -
batch
: This mode targets a large group of users, specified with their user ID or in a CSV file. You should usebatch
mode if you have more than one and up to 100,000 target users. By settingmode
tobatch
, you can send a notification at once without running into rate limit issues. Whenbatch
is specified, you can use either thetargets
property for up to 10,000 target users or upload a CSV file and specify its URL in thetargets_filename
property for up to 100,000 target users. To use a CSV file, you need to send a request to a separate endpoint. To learn more, refer to the dedicated set of instructions at the bottom of this page.
List of actions
Action | HTTP request |
---|---|
Sends a notification in real-time to a specific notification channel. | |
Sends a notification to multiple users using a CSV file. |
Send a notification
This API allows you to send a notification in either realtime
or batch
mode. If you wish to send a batch
notification with targets_filename
, see the Send a batch of notification messages with a CSV file section.
HTTP request
Note: This request should be made to API v2 while other RESTful APIs for Sendbird Business Messaging are supported in v1.
Request body
The following table lists the properties of an HTTP request that this action supports.
Properties
Required | Type | Description |
---|---|---|
template | nested object | Specifies the template used to send the notification. |
template.key | string | Specifies the unique key of the template that will be used to send the notification. |
mode | string | Specifies which mode is used to send the notification, depending on the number of recipients. |
targets | array of strings | Specifies the user IDs of target users to send the notification to. If the value of |
Optional | Type | Description |
---|---|---|
template.variables | nested object | Specifies the customizable variables in a template. |
template.variables.{user_id} | nested object | Specifies the user IDs to send the notification to and key-value items to store additional variables for each user ID. To learn more, refer to Template variables below. |
template.notification_push_data | nested object | Specifies the custom key-value pairs to be included in the push notification. This can contain a maximum of five pairs. |
priority | string | Specifies the delivery priority level of a batch notification. Acceptable values are |
title | string | Specifies the title used to send the notification. This field can be used as a label to organize and manage individual notifications. |
tag | string | Specifies a key that groups notifications together. This key is used in the Analytics page on Sendbird Dashboard to sort and categorize notifications. |
Template variables
The variables that you set in the template need to be specified as key-value items for each user ID in the template.variables.{user_id}
object. For every variable key, you need to assign the value in the request body. There are three types of variables: String, Image, and Action. See the table below on what variables you need to set in the request body.
Variable type | Description |
---|---|
String | Specifies the texts used in the body of the template and the text buttons. These texts are subject to change each time the notification is sent. |
Image | Specifies the images used in the template. These images are subject to change each time the notification is sent. Within the image variable, you need to assign values to the |
Action | Specifies the actions to execute when a UI component in the template is tapped on the mobile app. These actions are subject to change each time the notification is sent. Within the action variable, you need to assign values to the |
Response
If successful, this action returns the following:
Send a batch of notification messages with a CSV file
If you aim to send a notification to up to 100,000 target users, set the notification mode
to batch
and use a CSV file to list up the recipients. In order to do so, first, generate a pre-signed URL and upload a CSV file containing all the user IDs. Follow the steps below.
How to create a CSV file
You can send notifications to multiple recipients by importing a CSV file containing information on targets and template variables.
This CSV file must include the following information:
- The first row must contain column names, such as
user_id
and your variable keys. - A column named
user_id
must be included, containinguser_id
for all recipients. - Variable keys and values corresponding to each recipient. They must match the keys set in the template.
- Column names may only contain letters, numbers, underscores, hyphens, and periods.
- Each CSV file must contain all variable keys and their values for each user ID.
Note: The maximum number of users you can have in a single CSV file is 100,000.
Step 1 Generate a pre-signed URL
A CSV target file can only be uploaded when sending a notification in batch
mode and you must generate a pre-signed URL for every CSV file before uploading it to the Sendbird server and sending a notification.
HTTP request
Parameters
The following table lists the parameter that this action supports.
Required
Parameter name | Type | Description |
---|---|---|
file_key | string | Specifies the unique identifier of the file. |
Request body
The following table shows the property of an HTTP request that this action supports.
Properties
Optional | Type | Description |
---|---|---|
overwrite_duplicate_key | bool | Determines whether to overwrite the |
Response
If successful, this action returns the following response properties. In the case of an error, an error object is returned. A detailed list of error codes is available here.
List of response properties
Property name | Type | Description |
---|---|---|
url | string | The URL used to upload a file. |
fields | object | Additional fields in the form of key-value pairs. They can include properties such as |
file_key | string | The unique identifier of the file. |
In the case of an error, an error object is returned. A detailed list of error codes is available here.
Step 2 Upload a CSV file
Once you've generated a pre-signed URL, you can now upload your CSV file containing a list of user IDs to the URL. When uploading the file, you need to send a multipart request. To learn more about CSV file specifications, see How to create a CSV file below.
Headers
The multipart HTTP request to the Chat API must include the following header.
Multipart request
Since your request contains a file, you need to send the following multipart request. As shown in the example below, specify multipart/form-data
and boundary
, which is a delimiter string that separates each data field, in the Content-Type
header.
Step 3 Send a notification to users in the CSV file
Once the file's been uploaded to the server, you can use the targets_filename
property to send a notification to up to 100,000 users.
HTTP request
Note: This request should be made to API v2 while other RESTful APIs for Sendbird Business Messaging are supported in v1.
Request body
The following table lists the properties of an HTTP request that this action supports.
Properties
Required | Type | Description |
---|---|---|
template | nested object | Specifies the template used to send the notification. |
template.key | string | Specifies the unique key of the template that will be used to send the notification. |
mode | string | Specifies which mode is used to send the notification, depending on the number of recipients. |
targets_filename | string | Specifies the unique |
Optional | Type | Description |
---|---|---|
template.variables | nested object | Specifies the customizable variables in a template. |
template.variables.{user_id} | nested object | Specifies the user IDs to send the notification to and key-value items to store additional variables for each user ID. To learn more, refer to Template variables below. |
template.notification_push_data | nested object | Specifies the custom key-value pairs to be included in the push notification. This can contain a maximum of five pairs. |
priority | string | Specifies the delivery priority level of a batch notification. Acceptable values are |
title | string | Specifies the title used to send the notification. This field can be used as a label to organize and manage individual notifications. |
tag | string | Specifies a key that groups notifications together. This key is used in the Analytics page on Sendbird Dashboard to sort and categorize notifications. |
Response
If successful, this action returns a notification resource in the response body. In the case of an error, an error object is returned. A detailed list of error codes is available here.
List target files
You can retrieve a list of all uploaded target files in the Sendbird application using this API.
HTTP request
Parameters
The following table lists the parameters that this action supports.
Optional
Parameter name | Type | Description |
---|---|---|
token | string | Specifies a page token that indicates the starting index of results to retrieve. If not specified, the index is set to |
limit | int | Specifies the number of results to return per page. Acceptable values are |
Response
If successful, this action returns a list of files resources in the response body. In the case of an error, an error object is returned. A detailed list of error codes is available here.
List of response properties
Property name | Type | Description |
---|---|---|
files[] | array of objects | An array of file resources. |
files.file_key | string | Specifies the unique identifier of the file. |
files.file_size | number | Specifies the size of the target file. |
files.expires_at | long | The time at which the target file expires in Unix milliseconds format from the time of file uploading is complete. (Default: |
files.uploaded_at | long | The time at which the target file was uploaded through the pre-signed URL in Unix milliseconds format. |
next | string | The value that can be used in the |