/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.

  • Maximum length: 32 characters
  • Characters not allowed: special characters such as @ # ?

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.

  • Maximum length: 128 characters.
  • Characters not allowed: special characters such as @ # ?

Note: Obtain this field via the

/v2/authorizations/applyToken API.

"2019112719074101000700000077771xxxx"

customerBelongsTo

String 

Yes

Indicates the super app that the user uses. Valid values are:

  • ALIPAY_CN: Alipay CN
  • ALIPAY_HK: Alipay HK
  • ALIPAY_MO: Alipay MO
  • TNG: Touch 'n Go
  • GCASH: Gcash
  • DANA: Dana
  • KAKAOPAY: KakaoPay
  • BKASH: bKash
  • CHOPE: Chope
  • TRUEMONEY: TrueMoney

"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.

  • Maximum length: 64 characters
  • Characters not allowed: special characters such as @ # ?

Note: This field is an API idempotency field. For the notifications that are sent with the same requestId and reach an S status, the super app must return the same messageId. For more information, see the Idempotency.

"20191127190741010007013213123xxxx"

authClientId

String 

Yes

Indicates the unique ID assigned by the super app to identify an authorized merchant.

  • Maximum length: 128 characters
  • Characters not allowed: special characters such as @ # ?

"202016726873874774774xxxx"

templateCode

String 

Yes

Indicates the unique code assigned by Mini Program Platform to identify a template.

  • Maximum length: 64 characters
  • Characters not allowed: special characters such as @ # ?

"TP_5800000001xxxx"

templates

Array<ContentTemplate>

Yes

Templates are created by the super app for the merchant to customize the content and layouts of notifications.

  • Maximum size: 5 elements
  • Push
copy
[
  {
    "templateParameters": {
      // A Key is the variable predefined in the template. Each key has a value that can be defined by yourself.
      "pushContentUrl": "http://www.taobao.com",
      "customTitle": "test title",
      "customContent": "test content"
    },
    "language": "en-US"
  }
]
  • SMS
copy
[
  {
    "templateParameters": {
      // A Key is the variable predefined in the template. Each key has a value that can be defined by yourself.
      "customContent": "test content"
    },
    "language": "en-US"
  }
]
  • Inbox
copy
[
  {
    "templateParameters": {
      // A Key is the variable predefined in the template. Each key has a value that can be defined by yourself.
      "headerLink": "http://www.taobao.com",
      "bodyUrl": "http://www.taobao.com",
      "firstLinkName": "hello",
      "firstLinkUrl": "linkName",
      "customTitle": "test title",
      "customContent": "test content"
    },
    "language": "en-US"
  }
]

extendInfo

String 

No

Indicates the extended information about this API.

  • Maximum length: 4096 characters
  • Characters not allowed: special characters such as @ # ?
  • Can be Null.

"This is additional information"

Response parameters

Field

Data type

Required

Description

Example

result

Result

Yes

Indicates the request result such as status and error codes.

copy
{
    "resultCode": "SUCCESS",
    "resultStatus": "S",
    "resultMessage": "success" 
}

messageId

String

Yes

Indicates the unique ID assigned by Mini Program Platform to identify a notification.

  • Maximum length: 64 characters
  • Characters not allowed: special characters such as @ # ?

"000demo163853607887602123986120"

entendInfo

String

No

Indicates the extended information about this API.

  • Maximum length: 4096 characters
  • Characters not allowed: special characters such as @ # ?
  • Can be Null.

"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 S regardless of whether the notification is successfully sent to Mini Program Platform.

The corresponding result.resultCode is SUCCESS and the result.resultMessage is Success.

U

The status of the notification delivery request is unknown. 

The corresponding result.resultCode is UNKNOWN_EXCEPTION and result.resultMessage is "An API calling is failed, which is caused by unknown reasons.". For details, see the Common error codes section.

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:

image

  1. 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.
  2. Mini Program Platform processes the request and replaces the content of variables in the notification.
  3. Mini Program Platform sends the final notification to the super app via the corresponding channel of the template.
  4. The super app returns the result of the notification delivery request to Mini Program Platform.
  5. 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
copy
{
  "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
copy
{
  "appId": "P000000000000001xxxx",
  "authClientId": "202016726873874774774xxxx",
  "requestId": "20191129872100000777719901212",
  "accessToken": "2019112719074101000700000077771xxxx",
  "templateCode": "TP_5800000001xxxx",
  "customerBelongsTo": "GCASH",
  "templates": [
    {
      "templateParameters": {
        "customContent": "test content"
      },
      "language": "en-US"
    }
  ]
}
  • Inbox
copy
{
  "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

copy
{
 "result": {
    "resultCode":"SUCCESS",
    "resultStatus":"S",
    "resultMessage":"success"
  }
}

Related links

my.getAuthCode

my.getAppIdSync

/v2/authorizations/applyToken