/v2/miniprogram/message/send
POST /v2/miniprogram/message/send
With this API call, a merchant can send a service notification to users via Mini Program Platform, such as payment result, order status, and so on.
Note: Before calling this API, you must add the Send_Message feature to your mini program in Mini Program Platform to access the API. For detailed instructions, refer to Add features.
Structure
A message consists of a header and body. The following sections are focused on the body structure. For the header structure, see:
Request parameters
Field | Data type | Required | Description | Example |
appId | String | Yes | Indicates the unique ID assigned by Mini Program Platform to identify a mini program.
Note: Obtain this field via the my.getAppIdSync JSAPI or Mini Program Platform. | "P000000000000001xxxx" |
accessToken | String | Yes | The access token is used to access user information. For the specific information that can be accessed, see the my.getAuthCode JSAPI.
Note: Obtain this field via the | "2019112719074101000700000077771xxxx" |
customerBelongsTo | String | Yes | Indicates the super app that the user uses. Valid values are:
| "TNG" |
requestId | String | Yes | Indicates the unique ID assigned by the merchant to identify a request of notification delivery. For example, when the user completes a payment on the mini program in the super app with payment capability, the value of the requestId can be tradeNo, which indicates the transaction ID. See Use tradeNo to pay for more information.
Note: This field is an API idempotency field. For the notifications that are sent with the same requestId and reach an | "20191127190741010007013213123xxxx" |
authClientId | String | Yes | Indicates the unique ID assigned by the super app to identify an authorized merchant.
| "202016726873874774774xxxx" |
templateCode | String | Yes | Indicates the unique code assigned by Mini Program Platform to identify a template.
| "TP_5800000001xxxx" |
templates | Array<ContentTemplate> | Yes | Templates are created by the super app for the merchant to customize the content and layouts of notifications.
|
copy
copy
copy
|
extendInfo | String | No | Indicates the extended information about this API.
| "This is additional information" |
Response parameters
Field | Data type | Required | Description | Example |
result | Yes | Indicates the request result such as status and error codes. | copy
| |
messageId | String | Yes | Indicates the unique ID assigned by Mini Program Platform to identify a notification.
| "000demo163853607887602123986120" |
entendInfo | String | No | Indicates the extended information about this API.
| "This is additional information" |
Result process logic
In the response, the result.resultStatus field indicates the result of processing a request. The following table describes each result status:
Result status | Description |
S | The request of the notification delivery is successful. When the request is successful, the resultStatus is The corresponding result.resultCode is |
U | The status of the notification delivery request is unknown. The corresponding result.resultCode is |
F | The request of the notification delivery is failed. The corresponding result.resultCode and result.resultMessage are various based on different situations. For details, see the following Error codes section. |
Error codes
Error codes are usually classified into the following categories:
- Common error codes are common for all mini program OpenAPIs in V2.
- API-specific error codes are listed in the following table.
Error code | Result status | Error message | Further action |
TEMPLATE_NOT_EXIST | F | The template does not exist. | Check whether the template ID is correct. |
USER_NOT_SUBSCRIBED | F | The user does not subscribe to this channel. | - |
MESSAGE_SEND_EXCEED_LIMIT | F | The delivery frequency of the notification exceeds the limits set by the super app. | - |
Samples
The data flow below illustrates how a merchant sends notifications to a user:
- The merchant gets the templateCode from Mini Program Platform. With the templateCode, the merchant calls this API to send a request of notification delivery to Mini Program Platform.
- Mini Program Platform processes the request and replaces the content of variables in the notification.
- Mini Program Platform sends the final notification to the super app via the corresponding channel of the template.
- The super app returns the result of the notification delivery request to Mini Program Platform.
- Mini Program Platform forwards the result to the merchant server.
Request
Check the following request samples of notification delivery based on different channels, including Push, SMS, and Inbox:
- Push
{
"appId": "P000000000000001xxxx",
"authClientId": "202016726873874774774xxxx",
"requestId": "20191129872100000777719901212",
"accessToken": "2019112719074101000700000077771xxxx",
"templateCode": "TP_5800000001xxxx",
"customerBelongsTo": "GCASH",
"templates": [
{
"templateParameters": {
"pushContentUrl": "http://region.demo.com/app/1092?appId=28972",
"customTitle": "test title",
"customContent": "test content"
},
"language": "en-US"
}
]
}
- SMS
{
"appId": "P000000000000001xxxx",
"authClientId": "202016726873874774774xxxx",
"requestId": "20191129872100000777719901212",
"accessToken": "2019112719074101000700000077771xxxx",
"templateCode": "TP_5800000001xxxx",
"customerBelongsTo": "GCASH",
"templates": [
{
"templateParameters": {
"customContent": "test content"
},
"language": "en-US"
}
]
}
- Inbox
{
"appId": "P000000000000001xxxx",
"authClientId": "202016726873874774774xxxx",
"requestId": "20191129872100000777719901212",
"accessToken": "2019112719074101000700000077771xxxx",
"templateCode": "TP_5800000001xxxx",
"customerBelongsTo": "GCASH",
"templates": [
{
"templateParameters": {
"headerLink": "http://region.demo.com/cdn?sourceId=90801",
"bodyUrl": "http://region.demo.com/cdn/index.htm?id=90801",
"firstLinkName": "hello",
"firstLinkUrl": "http://region.demo.com/cdn/index.htm?id=9876542",
"customTitle": "test title",
"customContent": "test content"
},
"language": "en-US"
}
]
}
Response
{
"result": {
"resultCode":"SUCCESS",
"resultStatus":"S",
"resultMessage":"success"
}
}