After an atomic service calls requestSubscribeNotification and obtains user authorization, it can call this REST API to deliver subscription messages.
The service notification capability is supported on phones and tablets.
Message delivery is based on the subscription count:
Currently, this API does not support the message receipt function.
Protocol: HTTPS POST
Direction: Your server -> Huawei Push Kit server
URL: https://push-api.cloud.huawei.com/v1/[projectId]/service_notification/send
Data format: Content-Type: application/json
[projectId]: project ID. To obtain the value, sign in to AppGallery Connect, click Development and services, click the desired project, and go to Project settings.
| Parameter | Description | Example |
|---|---|---|
| Authorization | Authentication method: JWT: For details, please refer to Generating a JWT Based on a Service Account. NOTE · The PS256 algorithm must be used to call the service notification API. · You are advised to set the JWT validity period to 3600 seconds, within which a JWT can be reused. · This parameter value is Bearer followed by a space character and then the obtained authentication information. | Bearer eyJr*****OiIx---****.eyJh*****iJodHR--***.QRod*****4Gp---**** |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| msgId | Yes | String | Message ID, which uniquely identifies a message. The value contains 1 to 64 characters. The message ID is generated by the atomic service. Ensure that the message ID is unique to facilitate fault locating. |
| toOpenId | Yes | String | OpenID of a sign-in user. Use the OpenId reported by the device or request user information from the Account Kit server. For details about how to design and integrate the HUAWEI ID sign-in function, please refer to the account usage specifications for atomic services. |
| appId | Yes | String | App ID of an atomic service. The value contains 1 to 64 characters. NOTE [appId]: app ID. Sign in to AppGallery Connect, click Apps/Atomic services, select the required atomic service, and obtain the app ID of the atomic service under Basic information on the App information page. |
| templateId | Yes | String | Subscription template ID for message delivery. The value contains 1 to 128 characters. |
| templateParams | Yes | TemplateParams Object | Template parameters, in the format of {"key_0": "value","key_1": "value","key_2": "value"}. The length limit of a single parameter is specified by TemplateParams. The total length of the template subtitle cannot exceed 1024 bytes. The value cannot be empty. |
| clickAction | No | ClickAction Object | Action to be triggered upon message tapping. If this parameter is not specified, the home page is displayed by default. |
Template parameters are determined by the parameters selected when you claim a service notification template. Check the parameters in your template on the Atomic Service Notification page. For details, please refer to Selecting a Subscription Template.
| Parameter | Type | Description |
|---|---|---|
| thing | String | The value can contain a maximum of 128 characters, including digits, letters, and special characters. The value cannot be empty. |
| numberdeprecated | String | A numeric string of up to 32 digits. The value cannot be empty. This parameter has been deprecated. |
| letterdeprecated | String | A string of up to 32 letters. The value cannot be empty. This parameter has been deprecated. |
| symboldeprecated | String | A string of up to 5 symbols. The value cannot be empty. This parameter has been deprecated. |
| characterdeprecated | String | A string of up to 32 characters, including digits, letters, and special characters. The value cannot be empty. This parameter has been deprecated. |
| time | String | Time. The value can be a date, a date plus 24-hour time, or a period, for example, January 1, 2023. Two time points are connected by a hyphen (-). The value cannot be empty. The following are some example values: · January 1, 2023 22:22 · January 1, 2023 22:22:00 · January 1, 2023 00:00 - January 2, 2023 23:59 · January 1, 2023 00:00:00 - January 2, 2023 23:59:59 · January 1, 2023 00:00-12:30 · January 1, 2023 00:00:00-12:30:00 · January 1, 2023 · January 1, 2023 - January 2, 2023 |
| datedeprecated | String | Date. The value can be a date, a date plus 24-hour time, or a period. Two time points are connected by a hyphen (-). The value cannot be empty. This parameter has been deprecated. |
| amountdeprecated | String | Amount. The value consists of a currency symbol and a maximum of 10 digits (decimals allowed), optionally ending with "yuan". The value cannot be empty. This parameter has been deprecated. |
| phone_number | String | Phone number. The value contains digits and special characters, for example, +86-025-85697456. The value cannot be empty. |
| car_number | String | License plate number. The value contains a maximum of eight characters. The first and last characters can be Chinese characters, and the other characters can be letters or digits, for example, HK9028. The value cannot be empty. |
| namedeprecated | String | Name. The value contains a maximum of 10 Chinese characters or 20 alphanumeric characters and spaces. The value cannot be empty. This parameter has been deprecated. |
| phrasedeprecated | String | The value contains a maximum of five words, for example, In transit. The value cannot be empty. This parameter has been deprecated. |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| actionType | Yes | Integer | Action to be triggered upon message tapping. The options are as follows: 0: Open the atomic service home page. 1: Open a specified page of an atomic service. NOTE When actionType is set to 1, set at least one of action and uri. If both of them are set, the app page specified by action is opened first. |
| action | No | String | Action corresponding to the ability of an in-app page. |
| uri | No | String | URI corresponding to the ability of an in-app page. |
| data | No | Object | When actionType is set to 0 or 1, this parameter is used to transfer data to an atomic service after a button is tapped. The value must be in the key-value format and contains a maximum of 1024 bytes. Example: {"key1": "value1", "key2": "value2"} |
// Request URL
POST "https://push-api.cloud.huawei.com/v1/[projectId]/service_notification/send"
// Request Header
Content-Type: application/json
Authorization: Bearer eyJr*****OiIx---****.eyJh*****iJodHR--***.QRod*****4Gp---****
// Request Body
{
"msgId": "2**********80",
"appId": "6**********972",
"toOpenId": "A**********O",
"templateId": "1**********2",
"templateParams": {
"thing_0": "N0001",
"time_1": "April 27, 2024 22:22",
"thing_2": "101 Software Avenue"
}
} | Parameter | Mandatory | Type | Description |
|---|---|---|---|
| code | Yes | String | Response code. |
| msg | Yes | String | Response code description. |
| requestId | Yes | String | Request ID. |
Success response example:
{
"code": "80000000",
"msg": "Success",
"requestId": "157*******006"
} Failure response example:
{
"code": "82500003",
"msg": "Template subscribe msg appId error",
"requestId": "157*******006"
} | HTTP Response Code | Description | Solution |
|---|---|---|
| 200 | Success. | - |
| 400 | Parameter error. | Check the service response code and locate the fault based on it. |
| 401 | Authentication failure. | Check the Authorization parameter in the HTTP header. |
| 404 | Service not found. | Check the request URL. |
| 500 | Internal service error. | Submit a ticket online. |
| 502 | Connection error. This typically occurs when network connectivity is unstable. | Try again later. If the fault persists, submit a ticket online. |
| 503 | Traffic control. | · Distribute the sending speed evenly. · Spread out push notification delivery to avoid peak sending times. NOTE A maximum of 100,000 service notifications can be sent for each project per day, and the traffic limit is 100 TPS. |
| 504 | Gateway timeout. | Try again later. If the fault persists, submit a ticket online. |
Message
Success.
Symptom
Sent successfully.
Possible causes
Sent successfully.
Solution
None
Message
Check Parameter Error.
Symptom
Some request parameters are invalid.
Possible causes
Some request parameters are invalid.
Solution
Verify the request parameters as prompted by the response.
Message
Inner Error.
Symptom
Internal system error.
Possible causes
An unknown error occurred.
Solution
Message
Service notification msg send template param check error.
Symptom
Invalid template parameter.
Possible causes
Invalid template parameter.
Solution
Verify the template parameters as prompted by the response.
Message
Service notification msg send template get error.
Symptom
Failed to obtain the template.
Possible causes
The template ID in the request is incorrect. As a result, the corresponding template information cannot be found.
Solution
Refer to Selecting a Subscription Template to check the template details, and change the template ID.
Message
Service notification msg send project info error.
Symptom
The project information is invalid.
Possible causes
No project information is found based on the project ID in the request URL.
The app ID is in the blocklist.
The service notification function is not enabled for the atomic service.
Solution
Sign in to AppGallery Connect and verify the request parameters as prompted by the response.
Ensure that the project ID in the URL is correct.
Ensure that the app ID is not in the blocklist.
Enable service notifications for the corresponding atomic service.
Message
Service notification msg send risk check error.
Symptom
Risk control error.
Possible causes
The template parameters contain prohibited parameters.
Solution
Verify that the template parameters do not contain prohibited parameters as prompted by the response.
Message
Service notification msg send push error.
Symptom
Failed to deliver the message.
Possible causes
The number of delivered messages exceeds the upper limit.
The request body size exceeds the default value.
The user has not subscribed to the message.
Push Kit is not enabled for the atomic service.
Solution
Rectify the fault as follows:
If the number of delivered messages exceeds the subscription count, increase the subscription count by referring to Initiating an Account-based Subscription Request.
If the request body size exceeds the default value, reduce the request body size and deliver the message again.
The user has not subscribed to any messages. For details, please refer to Initiating an Account-based Subscription Request.
Push Kit has not been enabled for the atomic service. Sign in to AppGallery Connect, and enable Push Kit.
Message
Service notification msg send openId check error.
Symptom
OpenID failed the verification.
Possible causes
The OpenID of the recipient is incorrect.
Solution
Use the OpenId reported by the client or the OpenId in the user information obtained from the Account Kit server, and delivery messages again.
Message
Service notification msg send subtitle build error.
Symptom
An exception occurred when constructing the subtitle.
Possible causes
The carried parameters do not match the template parameters.
Solution
Verify the template parameters as prompted by the response. For details, please refer to Selecting a Subscription Template.
Message
Service notification msg send msgBody build error.
Symptom
An exception occurred when constructing the template message.
Possible causes
The carried parameters do not match the template parameters.
Solution
Verify the template parameters as prompted by the response. For details, please refer to Selecting a Subscription Template.