You can call this API to revoke sent messages. Currently, only notification messages and text-to-speech messages can be revoked. To avoid misinterpretation, "messages" in this section are referring to notification messages and text-to-speech messages.
The message body cannot exceed 4096 bytes (excluding the push token). Otherwise, error code 80300008 will be returned. The number of push tokens carried in a single request cannot exceed 1000 (the current system configuration value).
Protocol: HTTPS POST
Direction: Your server -> Huawei Push Kit server
URL: https://push-api.cloud.huawei.com/v1/[clientId]/messages:revoke
Data format: Request: Content-Type: application/json
Response: Content-Type: application/json
[clientId]: Replace it with the client ID of your app. (Refer to the relevant guide to obtain the ID.)
| Parameter | Description | Example |
|---|---|---|
| Authorization | Authentication method: JWT: For details, please refer to Generating a JWT Based on a Service Account. NOTE 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 eyJraWQiOiIx---xxx.eyJhdWQiOiJodHR---xxx.QRodgXa2xeXSt4Gp---xxx |
| push-type | Type of the message to be revoked. The options are as follows: 0: notification message 2: text-to-speech message | 0 |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| notifyId | Yes | Integer | notifyId carried when the message is sent. For details, please refer to notifyId. |
| token | Yes | Array [String] | Push token of the target user when a message is revoked. Example: "token": ["************"] NOTE A maximum of 1000 tokens can be carried each time. |
// Revoke messages based on notifyId and token.
{
"notifyId": 3114932,
"token": [
"pushToken1",
"pushToken2",
"pushToken3"
]
} | 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": "80100003",
"msg": "Illegal payload, The header does not contain valid push-type",
"requestId": "1690*******1701"
} | 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. |
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
Check and modify request parameters as prompted by the response.
Message
Illegal payload, {errorTips}.
Symptom
Incorrect message structure.
Possible causes
Incorrect message structure.
Solution
Check and modify the request body structure as prompted by the response.
Message
Check Parameter Partial Success.
Symptom
Some content in the message structure is incorrect.
Possible causes
Some content in the message structure is incorrect.
Solution
Verify the parameters in the message structure as prompted by the response.
Message
Authentication Error.
Symptom
Authentication error.
Possible causes
The request does not contain the Authorization parameter, or the Authorization parameter is left empty.
The project ID used for requesting the JWT and the client ID contained in the push request do not belong to the same project.
The JWT in the Authorization parameter does not match the app.
Solution
Rectify the authentication failure of the Authorization parameter in the request header as prompted by the response.
Verify that the request contains the Authorization parameter, and the Authorization parameter is not empty.
Verify that the value of clientId in the push request URL (https://push-api.cloud.huawei.com/v1/[clientId]/messages:revoke) matches the project to which your app belongs. For details, please refer to step 2 in Generating a JWT Based on a Service Account.
Verify that the JWT in the Authorization parameter matches the actual app. For details, please refer to Generating a JWT Based on a Service Account.
Generate a new JWT and then send the message.
Message
Access token expired.
Symptom
The access token has expired.
Possible causes
The access token has expired.
Solution
Generate a new JWT as prompted by the response and then send the request. For details, please refer to Generating a JWT Based on a Service Account.
Message
Jwt token expired.
Symptom
The JWT has expired.
Possible causes
The JWT has expired.
Solution
Generate a new JWT as prompted by the response and then send the request. For details, please refer to Generating a JWT Based on a Service Account.
Message
No permission to send message to these tmIDs.
Symptom
The current app does not have permission to send messages.
Possible causes
Push Kit has not been enabled.
ClientId is not an app-level client ID.
Solution
Sign in to AppGallery Connect and ensure that Push Kit has been enabled. For details, please refer to Enabling Push Kit.
Ensure that ClientId is an app-level client ID. For details, please refer to Guide.
Message
All the tokens are invalid.
Symptom
All tokens are invalid.
Possible causes
In principle, the tokens for different apps on the same device are distinct. However, the same token value might accidentally be passed during actual operations.
The app package name and app ID configured in the client app do not match those applied for in AppGallery Connect.
Devices are upgraded from HarmonyOS 4 or earlier (HarmonyOS for short) to HarmonyOS 5 or later (HarmonyOS NEXT for short). As a result, push tokens need to be re-obtained.
Solution
Rectify the sending failure based on the response, which might be one of the following:
Ensure that you do not pass push tokens belonging to other apps.
Ensure that the app package name and app ID configured in the client app match those applied for in AppGallery Connect.
After the device OS is upgraded to HarmonyOS NEXT, regenerate a push token and use request body parameters of the HarmonyOS NEXT version to send the message request.
Use the v1 request URL (https://push-api.cloud.huawei.com/v1/[clientId]/messages:revoke) to send the REST API request.
You are advised to call the getToken API upon app launch. If the push token of the device changes, report the change to your app server in a timely manner.
Message
token count should within {0} and {1}.
Symptom
The number of tokens in the message body exceeds the default value.
Possible causes
The number of tokens in the message body exceeds the default value (1000).
Solution
Check the number of tokens as prompted by the response. If the token count exceeds the single-request limit, split and send messages in batches.
Message
Token app count should not exceed 1.
Symptom
Tokens in the token list belong to multiple apps.
Possible causes
Tokens in the token list are generated by multiple apps.
Solution
Verify that the tokens in the token list are generated by the same app.
Message
Token app mismatch with specify app.
Symptom
The app corresponding to the token is different from that corresponding to ClientId.
Possible causes
In principle, the tokens for different apps on the same device are distinct. However, the same token value might accidentally be passed during actual operations.
The app package name and app ID configured in the client app do not match those applied for in AppGallery Connect.
Solution
Rectify the fault as prompted by the response:
Ensure that you do not pass push tokens belonging to other apps.
Ensure that the app package name and app ID configured in the client app match those applied for in AppGallery Connect.
Message
No permission to revoke messages.
Symptom
No permission to revoke messages.
Possible causes
No permission to revoke messages.
Solution
Revoke messages based on both the token and notifyId.