/v2/customers/message/sendByAccessToken

POST /v2/customers/message/sendByAccessToken

The send API is used for Mini Program to allow merchants or Independent Software Vendors (ISV) to configure message templates, which faciliates merchants or ISV to send good-looking messages to users.

Message structure

Request

Property

Data type

Required

Description

Example

appId

String 

Yes

In Mini Program, the app ID.

Max. length: 32 characters.

"P000000000000001xxxx"

accessToken

String 

Yes

An access token that is used to access the user resource scope.

Max. length: 128 characters.

"2019112719074101000700000077771xxxx"

requestId

String 

Yes

A unique ID associated with a message.

For example, using this API to send a notification when the user completes a payment through the Mini Program, the value of the requestId can be the tradeNo .

Max. length: 64 characters.

"20191127190741010007013213123xxxx"

templateCode

String 

Yes

The template that the merchant or ISV selects on the Mini Program SaaS portal. The message is sent based on the selected template.

Max. length: 64 characters.

"TP_5800000001xxxx"

templates

Array<ContentTemplate>

Yes

A list of content templates of messages to send. The maximum array size is 5.

[

       {

           "templateParameters": {

               "who": "string to represent a name, e.g. XiaoMing"

           },

           "language": "en-US"

       }

   ]

extendInfo

String

No

The additionally extensive information to add.

Max. length: 4096 characters.

"This is additional information"

Response

Property

Data type

Required

Description

Example

result

Result

Yes

The request result, which contains information such as status and error codes.

{

   "resultCode": "SUCCESS",

   "resultStatus": "S",

   "resultMessage": "success"  

 }

extendInfo

String 

No

The additionally extensive information to add.

Max. length: 4096 characters.

"This is additional information"

Result process logic

In the response, the result.resultStatus field indicates the result of processing a request as follows.

resultStatus

Decription 

S

The message sending request is successful.

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

A

The request is accepted by wallets.

The corresponding result.resultCode is "ACCEPT"; and the  result.resultMessage varies based on different situations.

U

The API status 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 message sending request fails.

The corresponding result.resultCode  and result.resultMessage vary 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.  
  • API-specific error codes: the current OpenAPI does not have its dedicated error codes.

Sample

/v2/customers/message/sendByAccessToken

Request

copy
{
    "appId": "2171xxxxxxxxxxxx",
    "accessToken": "2019112719074101000700000077771xxxx",
    "templateCode": "2021xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "templates": [
        {
            "templateParameters": {
                "who": "string to represent a name, e.g. XiaoMing",
                "pushContentUrl": "http://redirecturl"
            },
            "language": "en-US"
        }
    ]
}

For example, the message template includes: Hello, ${who}, then the message will be like: Hello, XiaoMing .

Response

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