The message body cannot exceed 4096 bytes (excluding the token). When messages are sent by token, the maximum number of tokens cannot exceed 1000 (specified by the current system parameter).
Protocol | HTTPS POST |
|---|---|
Direction | Your server -> Push Kit server |
URL | https://push-api.cloud.huawei.com/v1/appid/messages:send NOTE: For details about appid, please refer to Path Parameter. |
URL | https://push-api.cloud.huawei.com/v2/projectid/messages:send NOTE:
|
Data Format | Request: Content-Type: application/json Response: Content-Type: application/json |
Parameter | Description | Example |
|---|---|---|
Authorization | For details, please refer to Client Credentials. NOTE: This parameter value is Bearer followed by a space character and then the value of access_token. | Bearer CF3Xl2XV6jMKZgqYSZFws9IPlgDvxqOfFSmrlmtkTRupbU2VklvhX9kC9JCnKVSDX2VrDgAPuzvNm3WccUIaDg== |
Request Body
Parameter | Mandatory (M)/Optional (O) | Type | Description |
|---|---|---|---|
validate_only | O | boolean | Indicates whether a message is a test message. The test message is only used to verify format validity and is not pushed to user devices. The options are as follows:
The default value is false. |
message | M | object | Message structure, which must contain the valid message payload and valid sending object. For details about the parameters, please refer to the definition in Message Structure. |
Message Structure
Mandatory (M)/Optional (O) | Type | Description | |
|---|---|---|---|
O | string | Custom message payload. The value can be a JSON string for notification messages, and can be a common string or JSON string for data messages. Example: "your data" or "{'param1':'value1','param2':'value2'}"
| |
notification | O | object | Notification message content. For details about the parameters, please refer to the definition in Notification Structure. |
android | O | object | Android message push control. For details about the parameters, please refer to the definition in AndroidConfig Structure. This parameter is mandatory for Android notification messages. |
apns | O | object | iOS message push control. For details about the parameters, please refer to the definition in ApnsConfig Structure. This parameter is mandatory for iOS messages. |
webpush | O | object | Web app message push control. For details about the parameters, please refer to the definition in WebPushConfig Structure. This parameter is mandatory for web app notification messages. |
token | O | list | Push token of the target user of a message. You must and only can set one of token, topic, and condition. Example: "token":["token1","token2"] NOTE: If the same token is added to the array, the user will receive the same message. Do not enter a duplicate token. |
topic | O | string | Topic subscribed by the target user of a message. (Currently, this parameter applies only to Android apps.) You must and can only set one of token, topic, and condition. |
O | string |
|
Notification Structure
Mandatory (M)/Optional (O) | Type | Description | |
|---|---|---|---|
M | string | Notification message title. | |
M | string | Notification message content. | |
image | O | string | URL of the custom large icon on the right of a notification message. If this parameter is not set, the icon is not displayed. The URL must be an HTTPS URL. Example: https://example.com/image.png NOTE: The icon file size must be less than 512 KB. The recommended icon size is 40 x 40 dp and corner radiuses are 8 dp. Beyond the recommended specifications, the image may be compressed or displayed incompletely. |
AndroidConfig Structure
Mandatory (M)/Optional (O) | Type | Description | |
|---|---|---|---|
O | integer | Mode for the Push Kit server to cache messages sent to an offline device. These cached messages will be delivered once the device goes online again. The options are as follows:
The default value is -1. | |
O | string | Message cache time, in seconds. When a user device is offline, the Push Kit server caches messages. If the user device goes online within the message cache time, the messages are delivered. Otherwise, the messages are discarded. The default value is 86400 (1 day), and the maximum value is 1296000 (15 days). | |
O | string | Tag of a message in a batch delivery task. The tag is returned to your server when Push Kit sends the message receipt. Your server can analyze message delivery statistics based on bi_tag. | |
receipt_id | O | string | Unique receipt ID that associates with the receipt URL and configuration of the downlink message. You can find the receipt ID in Message Receipt. |
fast_app_target | O | integer | State of a mini program when a quick app sends a data message. The options are as follows:
The default value is 2. |
O | string | Custom message payload. If the data parameter is set, the value of the message.data field is overwritten. | |
notification | O | object | Android notification message structure. For details about the parameters, please refer to the definition in AndroidNotification Structure. |
AndroidNotification Structure
Mandatory (M)/Optional (O) | Type | Description | |
|---|---|---|---|
M | string | Title of an Android notification message. If the title parameter is set, the value of the message.notification.title field is overwritten. Before a message is sent, you must set at least one of title and message.notification.title. | |
M | string | Body of an Android notification message. If the body parameter is set, the value of the message.notification.body field is overwritten. Before a message is sent, you must set at least one of body and message.notification.body. | |
icon | O | string | Custom small icon on the left of a notification message. The icon file must be stored in the /res/raw directory of an app. For example, the value /raw/ic_launcher indicates the local icon file ic_launcher.xxx stored in /res/raw. Currently, supported file formats include PNG and JPG. For details about the custom small icon, please refer to Notification Icon Specifications. |
color | O | string | Custom notification bar button color in #RRGGBB format, where RR indicates the red hexadecimal color, GG indicates the green hexadecimal color, and BB indicates the blue hexadecimal color. Example: #FFEEFF |
sound | O | string | Custom message notification ringtone, which is valid during channel creation. The ringtone file must be stored in the /res/raw directory of an app. For example, the value /raw/shake indicates the local ringtone file /res/raw/shake.xxx stored in /res/raw. Currently, various file formats such as MP3, WAV, and MPEG are supported. If this parameter is not set, the default system ringtone will be used. NOTE: The ringtone is an attribute of the notification channel. Therefore, a ringtone is valid only if it is set during channel creation. If a ringtone is set after the channel is created, it will not be played and the one set during channel creation is played instead. |
O | boolean | Indicates whether to use the default ringtone. The options are as follows:
| |
tag | O | string | Message tag. Messages that use the same message tag in the same app will be overwritten by the latest message. |
click_action | M | object | Message tapping action. For details about the parameters, please refer to the definition in ClickAction Structure. This parameter is mandatory for Android notification messages. |
body_loc_key | O | string | ID in a string format of the localized message body. For details, please refer to Notification Message Localization. |
O | list | Variables of the localized message body. For details, please refer to Notification Message Localization. Example: "body_loc_args":["1","2","3"] | |
title_loc_key | O | string | ID in a string format of the localized message title. For details, please refer to Notification Message Localization. |
O | list | Variables of the localized message title. For details, please refer to Notification Message Localization. Example: "title_loc_args":["1","2","3"] | |
O | object | Multi-language parameter. body_loc_key and title_loc_key are read from multi_lang_key first. If they are not read from multi_lang_key, they will be read from the local character string of the APK. For details, please refer to Notification Message Localization. A maximum of three languages can be set. | |
O | string | Custom channel for displaying notification messages. Custom channels are supported in the Android O version or later. For details, please refer to Notification Channel Customization. | |
notify_summary | O | string | Brief description of a notification message to an Android app. |
image | O | string | URL of the custom large icon on the right of a notification message. The function is the same as that of the message.notification.image field. If the image parameter is set, the value of the message.notification.image field is overwritten. The URL must be an HTTPS URL. Example: https://example.com/image.png NOTE: The icon file size must be less than 512 KB. The recommended icon size is 40 x 40 dp and corner radiuses are 8 dp. Beyond the recommended specifications, the image may be compressed or displayed incompletely. |
style | O | integer | Notification bar style. The options are as follows:
|
big_title | O | string | Android notification message title in large text style. This parameter is mandatory when style is set to 1. When the notification bar is displayed after big_title is set, big_title instead of title is used. |
big_body | O | string | Android notification message body in large text style. This parameter is mandatory when style is set to 1. When the notification bar is displayed after big_body is set, big_body instead of body is used. |
auto_clear | O | integer | Message display duration, in milliseconds. Messages are automatically deleted after the duration expires. |
notify_id | O | integer | Unique notification ID of a message. If a message does not contain the ID or the ID is -1, NC will generate a unique ID for the message. Different notification messages can use the same notification ID, so that new messages can overwrite old messages. |
group | O | string | Message group. For example, if 10 messages that contain the same value of group are sent to a device, the device displays only the latest message and the total number of messages received in the group, but does not display these 10 messages. |
badge | O | object | Android notification message badge control. For details about the parameters, please refer to the definition in BadgeNotification Structure. |
ticker | O | string | Content displayed on the status bar after the device receives a notification message. Due to the restrictions of the Android native mechanism, the content will not be displayed on the status bar on the device running Android 5.0 (API level 21) or later even if this field is set. |
when | O | string | Time when Android notification messages are delivered, in the UTC timestamp format. If you send multiple messages at the same time, they will be sorted based on this value and displayed in the Android notification panel. Example: 2014-10-02T15:01:23.045123456Z |
importance | O | string | Android notification message priority, which determines the message notification behavior of a user device. The options are as follows:
|
use_default_vibrate | O | boolean | Indicates whether to use the default vibration mode. |
O | boolean | Indicates whether to use the default breathing light mode. | |
O | list | Custom vibration mode for an Android notification message. Each array element adopts the format of [0-9]+|[0-9]+[sS]|[0-9]+[.][0-9]{1,9}|[0-9]+[.][0-9]{1,9}[sS], for example, ["3.5S","2S","1S","1.5S"]. A maximum of ten array elements are supported. The value of each element is an integer ranging from 1 to 60. EMUI 11 is not supported. Example: "vibrate_config":["1","3"] | |
O | string | Android notification message visibility. The options are as follows:
| |
light_settings | O | object | Custom breathing light color. For details about the parameters, please refer to the definition in LightSettings Structure. |
O | boolean | Indicates whether to display notification messages in the foreground when an app is running in the foreground. For details, please refer to Notification Message Display for Apps Running in the Foreground. | |
profile_id | O | string | ID of the user-app relationship. The value contains a maximum of 64 characters. |
O | list | Content in inbox style. A maximum number of five content records are supported and each record can contain at most 1024 characters. This parameter is mandatory when style is set to 3. For details about the display effect, please refer to Inbox Style. Example: "inbox_content":["content1","content2","content3"] | |
buttons | O | object | Action buttons of a notification message. A maximum of three buttons can be set. For details about the parameters, please refer to the definition in Button Structure. Example: "buttons":[{"name":"Open app","action_type":"1"}] |
Button Structure
Mandatory (M)/Optional (O) | Type | Description | |
|---|---|---|---|
name | M | string | Button name, which cannot exceed 40 characters. |
action_type | M | integer | Button action. The options are as follows:
|
intent_type | O | integer | Method of opening a custom app page. The options are as follows:
This parameter is mandatory when action_type is set to 1. |
O | string |
| |
data | O | string | The maximum length is 1024 characters.
|
ClickAction Structure
Mandatory (M)/Optional (O) | Type | Description | |
|---|---|---|---|
type | M | integer | Message tapping action type. The options are as follows:
|
intent | O | string | For details about intent implementation, please refer to Setting the intent Parameter. When type is set to 1, you must set at least one of intent and action. |
url | O | string |
|
action | O | string | Action corresponding to the activity of the page to be opened when the custom app page is opened through the action. When type is set to 1 (open a custom page), you must set at least one of intent and action. |
BadgeNotification Structure
Mandatory (M)/Optional (O) | Type | Description | |
|---|---|---|---|
add_num | O | integer | Accumulative badge number, which is an integer ranging from 1 to 99. For example, a user has N unread messages on an app. If add_num is set to 3, the number displayed on the app badge increases by 3 each time a message that contains add_num is received, that is, N+3. |
class | M | string | Full path of the app entry activity class. Example: com.example.hmstest.MainActivity |
set_num | O | integer | Badge number, which is an integer ranging from 0 to 99. For example, if set_num is set to 10, the number displayed on the app badge is 10 no matter how many messages are received. If both set_num and add_num are set, the value of set_num prevails. |
To display the badge number after messages are received, class is mandatory, and add_num and set_num are optional.
If both of add_num and set_num are left empty, the badge number increases by 1 by default.
LightSettings Structure
Mandatory (M)/Optional (O) | Type | Description | |
|---|---|---|---|
color | M | object | Breathing light color. This parameter is mandatory when light_settings is set. For details about the parameters, please refer to the definition in Color Structure. |
light_on_duration | M | string | Interval when a breathing light is on, in the format of \d+|\d+[sS]|\d+.\d{1,9}|\d+.\d{1,9}[sS]. This parameter is mandatory when light_settings is set. |
light_off_duration | M | string | Interval when a breathing light is off, in the format of \d+|\d+[sS]|\d+.\d{1,9}|\d+.\d{1,9}[sS]. This parameter is mandatory when light_settings is set. |
Color Structure
Mandatory (M)/Optional (O) | Type | Description | |
|---|---|---|---|
alpha | O | float | Alpha setting of the RGB color. The default value is 1, and the value range is [0, 1]. |
red | O | float | Red setting of the RGB color. The default value is 0, and the value range is [0, 1]. |
green | O | float | Green setting of the RGB color. The default value is 0, and the value range is [0, 1]. |
blue | O | float | Blue setting of the RGB color. The default value is 0, and the value range is [0, 1]. |
ApnsConfig Structure
Mandatory (M)/Optional (O) | Type | Description | |
|---|---|---|---|
headers | O | object | APNs message headers. For details about the parameters, visit the APPLE Developer website. |
payload | M | object | APNs message payload. If title and body are set in the message payload, the values of the message.notification.title and message.notification.body fields are overwritten. Before a message is sent, you must set at least one of title and body and at least one of message.notification.title and message.notification.body. For details about the parameters, visit the APPLE Developer website. |
hms_options | M | object | HMS parameter for APNs. For details about the parameter, please refer to the definition in ApnsConfig.HmsOptions Structure. |
ApnsConfig.HmsOptions Structure
Mandatory (M)/Optional (O) | Type | Description | |
|---|---|---|---|
target_user_type | M | integer | Target user type. The options are as follows:
|
WebPushConfig Structure
Mandatory (M)/Optional (O) | Type | Description | |
|---|---|---|---|
headers | O | object | Headers of a message sent through the WebPush agent. For details about the parameters, please refer to the definition in Headers Structure. |
notification | O | object | Structure of a notification message sent through the WebPush agent. For details about the parameters, please refer to the definition in WebNotification Structure. |
hms_options | O | object | WebPush agent parameter. For details about the parameter, please refer to the definition in WebPushConfig.HmsOptions Structure. |
Headers Structure
Mandatory (M)/Optional (O) | Type | Description | |
|---|---|---|---|
ttl | O | string | Message cache time, in seconds, for example, 20, 20s, or 20S. |
topic | O | string | Message ID, which can be used to overwrite undelivered messages. |
WebNotification Structure
Mandatory (M)/Optional (O) | Type | Description | |
|---|---|---|---|
title | O | string | Title of a web app notification message. If the title parameter is set, the value of the message.notification.title field is overwritten. Before a message is sent, you must set at least one of title and message.notification.title. |
body | O | string | Body of a web app notification message. If the body parameter is set, the value of the message.notification.body field is overwritten. Before a message is sent, you must set at least one of body and message.notification.body. |
icon | O | string | Small icon URL. |
image | O | string | Large image URL. |
lang | O | string | Language |
tag | O | string | Notification message group tag. Multiple same tags are collapsed and the latest one is displayed. This function is used only for mobile phone browsers. |
badge | O | string | Browser icon URL, which only applies to mobile phone browsers and is used to replace the default browser icon. |
dir | O | string | Text direction. The options are as follows:
|
vibrate[] | O | integer | Vibration interval, in milliseconds. Example: [100,200,300] |
renotify | O | boolean | Message reminding flag. |
require_interaction | O | boolean | Indicates that notification messages should remain active until a user taps or closes them. |
silent | O | boolean | Message sound-free and vibration-free reminding flag. |
timestamp | O | Long | Standard Unix timestamp. |
actions[] | O | object | Message action. For details about the parameters, please refer to the definition in WebActions Structure. |
WebActions Structure
Mandatory (M)/Optional (O) | Type | Description | |
|---|---|---|---|
action | O | string | Action name. |
icon | O | string | URL for the button icon of an action. |
title | O | string | Title of an action. |
WebPushConfig.HmsOptions Structure
Mandatory (M)/Optional (O) | Type | Description | |
|---|---|---|---|
link | O | string | Default URI for redirection when no action is performed. |
For details, please refer to Sample Code for Sending Downlink Messages Through HTTPS.
Response Body
Parameter | Type | Description |
|---|---|---|
code | string | Result code. |
msg | string | Result code description. |
requestId | string | Request ID. |
HTTP Status Code | Description | Solution |
|---|---|---|
200 | Success. | - |
400 | Incorrect parameter. | Rectify the fault based on the status code description. |
401 | Authentication failed. | Verify the access token in the Authorization parameter in the request HTTP header. |
404 | Service not found. | Verify that the request URI is correct. |
500 | Internal service error. | Contact Huawei technical support. |
502 | The connection request is abnormal, generally because the network is unstable. | Try again later or contact Huawei technical support. |
Traffic control. |
|
Service Result Code | Description | Solution |
|---|---|---|
80000000 | Success. | N/A |
80100000 | Some tokens are successfully sent. Tokens identified by illegal_tokens are those failed to be sent. Response example: {
"code": "80100000",
"msg": "{\"success\":3,\"failure\":1,\"illegal_tokens\":[\"xxx\"]}",
"requestId": ""
} | Verify these tokens in the return value. |
80100001 | Some request parameters are incorrect. Response example: {
"code": "80100001",
"msg": "UnSupported svc",
"requestId": ""
} | Verify the request parameters as prompted in the response. |
80100002 | The number of tokens must be 1 when a message is sent in synchronous mode. | Verify the token field in the request. |
80100003 | Incorrect message structure. | Verify the parameters in the message structure as prompted in the response. |
80100004 | The message expiration time is earlier than the current time. | Verify the message field ttl. |
80100013 | The collapse_key message field is invalid. | Verify the message field collapse_key. |
80100017 | A maximum of 100 topic-based messages can be sent at the same time. | Increase the interval for sending topic-based messages. |
80200001 | OAuth authentication error. | The access token in the Authorization parameter in the request HTTP header failed to be authenticated. Ensure that the access token is correct. |
80200003 | OAuth token expired. | The access token in the Authorization parameter in the request HTTP header expired. Obtain a new access token. |
80300002 | The current app does not have the permission to send messages. |
|
80300007 | All tokens are invalid. |
|
80300008 | The message body size exceeds the default value (4096 bytes). | Reduce the message body size. |
80300010 | The number of tokens in the message body exceeds the default value. | Reduce the number of tokens and send them in batches. |
80600003 | Failed to request the OAuth service. | Check the OAuth 2.0 client ID and client key. |
81000001 | An internal error of the system occurs. | Contact Huawei technical support. |