Template message sending v1
API Overview
Function description
Template message sent API You need to create a general template in the official website console before you can send it.
The channel through which template messages are sent is determined by the channel selected when creating the template.
The advantage of using template message sending is that one variable value transfer takes effect on all channels.
Calling address
Broadcast sending:POST https://api.ums.jiguang.cn/v1/template/broadcast
Other ways to send:POST https://api.ums.jiguang.cn/v1/template/sent
Call verification
HTTP Header(Header) Add a field ( Key/Value right):
Authorization: Basic base64_auth_string
in base64_auth_string The generation algorithm is:base64(ChannelKey:MasterSecret)
That is, to ChannelKey Add a colon, add MasterSecret Assemble the string and then do base64 Convert.
message object
a message object to JSON Format expression represents all information related to a message.
| parameter | type | Options | illustrate |
|---|---|---|---|
| aud_xxx | String Array | Optional | 1. The destination of the message, when calling the broadcast API There is no need to pass this field. 2. xxx See below for details on the values of some parts. aud_xxx Send destination part. |
| template_id | int | Required | Template ID |
| template_para | JSON Object | Required | template parameters key-value,For example:{"user”:“xxx”,“url”:“xxx”} |
| app_para | JSON Object | Optional | App Channel related parameters, included in the template App Required for channel |
| rule_id | int | Optional | Send policy ID. If sending at the same time, 0 or not can be sent. This field has no effect when sending with a custom channel ID. |
| option | JSON Object | Optional | Optional parameters, used to fill in the blacklist ID, submitter and other information |
| callback | JSON Object | Optional | callback parameters |
Example description
Request example
curl --insecure -X POST -v https://api.ums.jiguang.cn/v1/sent -H "Content-Type: application/json" -u "7d431e42dfa6a6d693ac2d04:5e987ac6d2e04d95a9d8f0d1" -d '
{
"aud_userid": ["user1","user2"],
"template_id":10001,
"template_para":{"user":"xxx","url":"xxx"},
"app_para":{
"platform":"ios",
"time_to_live":9999,
"apns_production":true
},
"rule_id": 1001,
"option": {
"sendno": "test",
"owner":"admin",
"black_id":1234,
"priority":2
},
"callback": {
"url":"https://www.jiguang.cn/ums-portal",
"params":{
"name":"joe",
"age":26
}
}
}'
> POST /v3/push HTTP/1.1
> Authorization: Basic N2Q0MzFlNDJkZmE2YTZkNjkzYWMyZDA0OjVlOTg3YWM2ZDJlMDRkOTVhOWQ4ZjBkMQ==
Return parameters and examples
| parameter | type | Options | illustrate |
|---|---|---|---|
| code | int | Required | Business status code, 0 represents success, others represent failure, see call return code for details |
| msgid | String | Optional | Message unique ID, not returned on failure. |
| message | String | Optional | Reason for failure, returned on failure |
| sendno | String | Optional | API The identifier passed when calling will be returned unchanged when the request is successful. |
< HTTP/1.1 200 OK
< Content-Type: application/json
{"code":0,"sendno":"aeg-efd-0e","msgno":"v:1t:1603707455p:27133n:2"}
{"code":1015031,"message":"模板ID不存在"}
aud_xxx:Send target
UMS Currently supports "broadcast owner, label, user ID,user segment、Customized channel registration ID 》5 kinds of goals
broadcast
When broadcasting to everyone, call the broadcast-specific API https://api.ums.jiguang.cn/v1/template/broadcast, no need to pass Audience。
User class target
"Broadcast, tag, user ID,user segment” are based on UMS User system in, you need to use it firstUser management APIUpload the user, the registration ID of each channel, and the binding relationship between the user and the registration ID of each channel.
Use this method to send messages,UMS Before sending messages to each channel, the channel registration ID will be filtered out according to specific rules, as explained below:
- When sending a label, first filter out the ones that have the label set. userID(Priority is given to selecting the binding identifier for this label as this channel. Channelkey of userID, if this channel does not have this label, the binding identifier will be selected as global all of userID), and then filter the corresponding channel registration ID for distribution.
- for App,WeChatOfficial Account,WeChatMini-program, Alipay Life Account Channel,userID It is bound to the channel registration ID through the channel code, so select the channel registration ID bound to the "channel authorized by this channel" in the user information to issue it.
- For SMS and email channels, give priority to this channel in user information. Channelkey The bound mobile phone number and email address. If not available, select the globally bound mobile phone number and email address.
- For DingTalk channels, the ID is globally unique, so select the globally bound DingTalk registration ID in the user information for delivery.
For "label, user ID,user segment"The parameter description of " is as follows:
| parameter | type | Options | illustrate |
|---|---|---|---|
| aud_tag | String Array | Optional | Tag list, up to 20 sent at a time. Validity statement:
|
| aud_userid | String Array | Optional | User list, most sent at one time 1000 indivual. Validity statement:
|
| aud_segment | String Array | Optional | Created on pageuser segmentID. Defined as an array, but currently limited to pushing one at a time. |
Custom channel registration ID
If you do not upload users,UMS It also supports sending messages directly using the registration ID of each channel. Depending on the channel,xxx The value of the part is:
* App:app
* 微信公众号:wechatoa
* 微信小程序:wechatmp
* 短信:sms
* 邮箱:email
* 支付宝生活号:alipay_life
* 钉钉:dingtalk_cc
* 企业微信:wechatwk
* 企业微信互联企业:wechatwk_linkedcorp
Note: In one message, the custom channel registration ID and user class target (tag, user ID,user segment) are not allowed to exist simultaneously
Can send to multiple channels at the same time, each channel can send up to 1000 IDs
When sending a message using a custom channel ID,aud_xxx The type is Object Array, the description is as follows:
| parameter | type | Options | illustrate |
|---|---|---|---|
| instance | String | Optional | Target ID, reserved field, currently invalid |
| data | String Array | Required | List of channel registration IDs. Send most at one time 1000 indivual. The validity just needs to follow the requirements of each channel. |
Example
- Send with label
{
"aud_tag": ["tag1","tag2"]
}
- Send using user ID
{
"aud_userid": ["user1","user2"]
}
- useuser segmentsend
{
"aud_segment": ["1000"]
}
- Send using custom channel registration ID:
{
"aud_app": [{
"instance": "app",
"data": ["170976fa8a9277fac6e"]
}],
"aud_wechatoa": [{
"instance": "wechatoa",
"data": ["oMtZu6kApZYEPJJWwyIHpWQ2L_DI"]
}],
"aud_wechatmp": [{
"instance": "wechatmp",
"data": ["oXNQs5B3LGA3xkU7-g2SdK3SsUaw"]
}],
"aud_sms": [{
"instance": "sms",
"data": ["18866007799"]
}],
"aud_email": [{
"instance": "email",
"data": ["wujb@jpush.cn"]
}],
"aud_alipay_life": [{
"instance": "alipaylife",
"data": ["2088102733318286"]
}],
"aud_dingtalk_cc": [{
"instance": "dingtalkcc",
"data": ["a3c213779d163837895b30f47aaa94c3"]
}],
"aud_wechatwk": [{
"instance": "wechatwk",
"data": ["zhangsan"]
}],
"aud_wechatwk_linkedcorp": [{
"instance": "wechatwk_linkedcorp",
"data": ["CorpId1/userid1","CorpId2/userid2"]
}]
}
template_para:Template parameter
When creating a general template, you can set the same variable for multiple channels. When sending a message, you only need to pass the value to the same variable once and it will be automatically matched to each channel.
in template parameters key It depends on the variable value customized when creating the template. When passing the value, you need to be careful not to exceed the upper limit of the length of each channel.
{
"template_para":{"user":"xxx","url":"xxx"}
}
app_para:App parameter
When creating a template, only the sending channel and corresponding message content are defined. App For channels, special parameters such as the platform need to be specified when sending messages, so special app_para Fill in the fields and include them in the template App When using a channel, this field is required and the supported parameters are as follows:
| parameter | type | Options | illustrate |
|---|---|---|---|
| platform | String/Arry String | Required | App Push platform settings, value: "android","ios","quickapp","web", set to " when sending to all platformsall”, used by some platforms json array |
| time_to_live | int | Optional | Offline message retention time (seconds), default 86400 (1 day), up to 10 days. |
| apns_production | boolean | Optional | APNs Whether it is a production environment,True Indicates pushing to the production environment,False Indicates that the development environment is to be pushed; if not specified, the production environment is pushed. |
{
"app_para":{
"platform":"ios",
"time_to_live":9999,
"apns_production":true
}
}
rule_id:Send policy
If reissuance is not required and only single-channel or multi-channel simultaneous transmission is required, there is no need to fill in the policy ID, or set it to 0.
After creating a reissue strategy in the official website console-channel-sending strategy, adjust API This can be specified using the policy ID.
- When sending using a custom channel registration ID, the sending policy does not take effect.
- If a sending policy is used, the channels and msg_xxx The channel information in needs to be consistent.
option: Optional parameter
Currently it contains the following optional parameters:
| parameter | type | Options | illustrate |
|---|---|---|---|
| sendno | String | Optional | Used purely as API call identifier,API is returned unchanged for convenience API The caller matches the request with the return. |
| owner | String | Optional | Submitter username, when the channel is opened api Required for message review |
| black_id | int | Optional | Blacklist ID, blacklist ID and whitelist ID are not allowed to exist at the same time |
| white_id | int | Optional | Whitelist ID, blacklist ID and whitelist ID are not allowed to exist at the same time |
| priority | int | Optional | Message priority, values: 1 (high), 2 (medium), 3 (low) |
callback: callback parameters
tune API When sending a message, you can specify callback Parameters to facilitate users to temporarily change callbacks URL Or the callback can bring its own custom parameters to meet its daily business needs. Please read detailed instructions for useMessage callback settings
This feature is only forJiguang VIP Provided by the user, 9 message statuses are provided: "Target valid/invalid, submission successful/failed, delivery successful/failed, click, withdrawal successful/failed", and the required callback status needs to be set in the official website console.
If you need to activate this function, please contact:Business customer service
Example:
{
"aud_userid": ["user1","user2"],
"msg_app": [{"platform":"android", "notification":{"android":{"alert":"Hi,JPush !"}}}],
"rule_id": 1001,
"option": {
"sendno": "test",
"owner":"admin",
"black_id":1234,
"priority":2
},
"callback": {
"url":"https://www.jiguang.cn/ums-portal",
"params":{
"name":"joe",
"age":26
}
}
}
callback Contains the following fields:
| Keywords | type | Options | meaning |
|---|---|---|---|
| url | string | Optional | The data temporary callback address is only valid for this message sending request. The address must be inJiguangIt can be used only if the background verification is passed; if not specified, it will be usedJiguangThe default address configured in the background shall prevail. |
| params | JSON Object | Optional | Custom parameters that need to be called back to the user |
call return
call API Please refer to the return code afterBusiness return code
refer to
- HTTP Return code:HTTP-Status-Code
- HTTP Specification reference:HTTP basic authentication