Send a batch of notifications using a CSV file
This API is used to send a notification to multiple users through either a Feed or Chat notification channel. You should call this API if you have more than one and up to 100,000 target users. By setting mode
to batch
, you can send a notification at once without running into rate limit issues. When batch
is specified, you can use either the targets
property for up to 10,000 target users or the targets_filename
property for up to 100,000 target users. See the guide below on how to use targets_filename
to send a notification.
For real-time notifications, refer to this page.
Get started
In order to send a batch of notifications using a CSV file, you need to first generate a pre-signed URL and upload a CSV file containing all the user IDs. Follow the steps below.
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
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 key of the template that's 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 name of a CSV file containing target user IDs to send the notification to. You can only use this property when the |
Optional | Type | Description |
---|---|---|
push_template | nested object | Specifies the template for a push notification that overrides the default push notification settings in Sendbird Dashboard. |
push_template.title | string | Specifies the title in the push notification template. This is a required property if you wish to configure |
push_template.body | string | Specifies the body in the push notification template. This is a required property if you wish to configure |
push_template.enable_push | bool | Determines whether to send a push notification. This is a required property if you wish to configure |
fallback_message | string | Specifies a message that's used as the last notification when displaying the notification preview in a channel list. It's also used as an alternative text when a notification could not be displayed properly. |
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. |
How to create a CSV file
You can send notifications to multiple recipients by importing a CSV file containing user information. The maximum number of users you can have in a single CSV file is 100,000. See the following CSV file formatting requirements:
- The first row in the file must have column names.
- Only alphabets, numbers, underscores, hyphens, and periods are allowed in column names.
- One column must be named
user_id
and it must contain user IDs of the target recipients.
You can add more columns to the file that contain user information such as user name, nickname, or even image URLs. These additional user information need to be the value for each variable key that you set in the template. If you wish to import images, each image must have the same width and height in order to be displayed properly.
Response
If successful, this action returns an empty body. In the case of an error, an error object is returned. A detailed list of error codes is available here.