Push API

Last updated: 2021-09-02 17:43:17

    API Description

    Request method: POST.

    Service URL/v3/push/app
    

    API service URLs correspond to service access points one to one. Please select the service URL corresponding to the service access point of your application.

    Feature: Push API is the general term for all push APIs. Push API supports different push targets, as described below.
    All request parameters are JSON encapsulated and uploaded to the backend, which differentiates push targets based on the request parameters. If an error code is returned, see Server-Side Error Codes.

    Required Parameters

    The required push parameters refer to the parameters that must be carried in a push message.

    Parameter Type Required Description
    audience_type String Yes Push target. Valid values:
  • all: push to all devices
  • tag: push to devices with specified tags
  • token: push to a single device
  • token_list: push to a list of devices
  • account: push to a single account
  • account_list: push to a list of accounts
  • package_account_push: push by account package
  • package_token_push: push by token package
  • message Object Yes Message body. For more information, please see [message body type](#message body type).
    message_type String Yes Message type. Valid values:
  • notify: notification
  • message: in-app message/silent message
  • environment String Yes (only for iOS) Push environment (only available for pushes on iOS). Valid values:
  • product: production environment
  • dev: development environment
  • upload_id Integer Yes (only available for push by account/token package) Account/Token package upload ID

    audience_type: push target

    Push target indicates which devices a push can be delivered to.
    Push API supports a variety of push targets. For example, you can push to all devices, devices with specified tags, a single device, a list of devices, a single account, or a list of accounts.

    Push Target Description Required Parameters and Instructions
    all Push to all devices None
    tag Push to devices with specified tags tag_rules (recommended):
  • Push by a combination of tags. You can set 'AND', 'OR' and 'NOT' rules.
  • Note: if both tag_rules and tag_list are specified, tag_list becomes invalid automatically. For parameter descriptions, see Tag combination rules.
    tag_list (no further updates):
  • Push to devices with tag1 and tag2 {"tags":["tag1","tag2"],"op":"AND"}
  • Push to devices with tag1 or tag2 {"tags":["tag1","tag2"],"op":"OR"}
  • A tag list cannot exceed 512 characters.
  • token Push to a single device token_list
  • If the parameter contains multiple tokens, messages are pushed only to the first token.
  • Format example: ["token1"]
  • A token string cannot exceed 36 characters.
  • token_list Push to a list of devices token_list
  • Up to 1,000 tokens
  • Format example: ["token1","token2"]
  • A token string cannot exceed 36 characters.
  • Note: if the token list contains more than 1,000 tokens, the push will fail. To push messages to more than 1,000 tokens, you are recommended to use the Token Package Upload API.
    account Push to a single account account_list
  • If the parameter contains multiple accounts, messages are pushed only to the first account.
  • Format example: ["account1"]
  • account_list Push to a list of accounts account_list
  • Up to 1,000 accounts
  • Format example: ["account1","account2"]
  • Note: if the account list contains more than 1,000 accounts, the push will fail. To push messages to more than 1,000 accounts, you are recommended to use the Account Package Upload API.
    package_account_push Push by account package Required for uploading the account package to push
    package_token_push Push by token package Required for uploading the token package to push
    • Push to all devices

       {
       "audience_type": "all"
      }
      
    • Push to devices with specified tags (using tag_rules): push to male users who were active on April 8, 2020 in Guangdong or Hunan province

      {
      "audience_type": "tag",
      "tag_rules": [
           {
               "tag_items": [
                   {
                       "tags": [
                           "guangdong",
                           "hunan"
                       ],
                       "is_not": false,   
                       "tags_operator": "OR",  
                       "items_operator": "OR", 
                       "tag_type": "xg_auto_province" 
                   },
                   {
                       "tags": [
                           "20200408"
                       ],
                       "is_not": false,
                       "tags_operator": "OR",
                       "items_operator": "AND",
                       "tag_type": "xg_auto_active"
                   },
                   {
                       "tags": [
                           "male"
                       ],
                       "is_not": false,
                       "tags_operator": "OR",
                       "items_operator": "AND",
                       "tag_type": "xg_user_define"
                   }
               ],
               "operator": "OR", 
               "is_not": false  
           }
       ]
      }
      
    • Push to a single device: push to the device with token1 as the token

       {
       "audience_type": "token",
       "token_list": [
           "token1"
       ]
      }
      
    • Push to a list of devices: push to devices with token1 and token2 as their tokens

       {
       "audience_type": "token_list",
       "token_list": [
           "token1",
           "token2"
       ]
      }
      
    • Push to a single account: push to the device bound to account1

       {
       "audience_type": "account",
       "account_list": [
           "account1"
       ]
      }
      
    • Push to a list of accounts: push to devices bound to account1 and account2

       {
       "audience_type": "account_list",
       "account_list": [
           "account1",
           "account2"
       ]
      }
      

    message_type: message type

    The message types may vary slightly depending on the platform. For more information, see the table below:

    Message Type Description Supported Platform Feature Description
    notify Notification bar message Android and iOS Messages are displayed in the notification bar.
    Note: this parameter is mutually exclusive with content-available: 1. Do not use them at the same time.
    message In-app message or silent message Android (in-app message)
    iOS (silent message)
    Messages are not displayed in the notification bar.
    Note: due to vendor restrictions, Android in-app messages can be delivered only through the TPNS channel, but not vendor channels.

    message: message body

    The message body is the message delivered to the client.
    Push API handles messages on iOS and Android differently, so you need to implement message pushes for the two platforms separately. The push message body is in JSON format.

    General message on Android

    The table below specifies parameters for the Android platform:

    Parameter Type Parent Project Default Value Required Description
    title String message Empty Yes Message title
    content String message Empty Yes Message content
    accept_time Array message Empty No The time period that allows pushes.
  • A single element is formed by a "start" time and an "end" time.
  • "start" and "end" are indicated by hour and minute. For more information, please see the samples.
    Note: this is valid only for the TPNS channel due to vendor restrictions.
  • thread_id String message Empty No Thread ID for collapsed notification in threaded display.
    Note: this is valid only for the TPNS channel due to vendor restrictions.
    thread_sumtext String message Empty No Summary displayed after the notification is collapsed in a thread, which is valid if thread_id is not empty.
    Note: this is valid only for the TPNS channel due to vendor restrictions.
    xg_media_resources String message Empty No URL of big image in the notification bar, which takes effect only for the TPNS and Mi channels.
    Note: to use the big image notification feature of the Mi channel, you need to call the Mi image uploading API to upload an image file, get the pic_url image address specified by Mi, and enter it in the xg_media_resources parameter of TPNS. For more information, see the image uploading API section in Rich Text Message in Mi Push.
    xg_media_audio_resources String message Empty No URL of audio rich media elements.
    It supports audio in MP3 format and the suggested size is within 5 MB.
    Note: this parameter is valid only for the TPNS channel and is unsupported by other channels.
    android Object message Empty No Structure of advanced settings for Android notification. For more information, please see Android structure description.

    Android structure description

    Parameter Type Parent Project Default Value Required Description
    n_ch_id String android Empty No Notification channel ID (valid only for the TPNS channel). For more information, see Creating a notification channel.
    n_ch_name String android Empty No Notification channel name (valid only for the TPNS channel). For more information, please see Creating a notification channel.
    xm_ch_id String android Empty No Mi channel ID (valid only for the Mi channel)
    fcm_ch_id String android Empty No FCM channel ID (valid only for the FCM channel)
    hw_biz_type Integer android 0 No Whether to enable notifications for Huawei quick apps. Valid values:
  • 1: enable
  • 0: disable
  • Note: this parameter takes effect only for the Huawei channel and you need to contact Huawei business team for activation.
    hw_ch_id String android Empty No Huawei channel ID (valid only for the Huawei channel)
    hw_importance Integer android 0 No Notification message type defined by Huawei, which determines the notification behavior of the user’s device. Valid values:
  • 1: information and marketing messages
  • 2: service and communication messages
  • oppo_ch_id String android Empty No OPPO channel ID (valid only for the OPPO channel)
    vivo_ch_id String android 0 No vivo channel ID (valid only for the vivo channel). Valid values: 0: operation message; 1: system message
    n_id Integer android 0 No (This parameter has been disused and will be unavailable in the future. If you need the override feature, please use the overriding parameter collapse_id.)
    Unique ID of the notification message object (valid only for the TPNS channel)
    (1) Greater than 0: overrides the previous message with the same ID
    (2) Equal to 0: displays this message without affecting other messages
    (3) Equal to -1: clears all previous messages and displays this message only.
    builder_id Integer android 0 No Local notification style identifier
    badge_type Integer android -1 No Notification badge:
  • -2: automatically increased by 1, valid only for Huawei devices
  • -1: unchanged, valid only for Huawei and vivo devices
  • [0, 100): direct configuration, valid only for Huawei and vivo devices
  • Note: the badge adaptation capabilities vary depending on the vendor device. For details about the implementation effect of each parameter value, see Badge Adaptation Guide.
    ring Integer android 1 No Whether there is a ringtone. Valid values:
  • 0: no
  • 1: yes
  • ring_raw String android Empty No Name of the ringtone file in the raw directory of the Android project; no extension is needed.
    Note: custom ringtones are supported only for the Huawei, Mi, FCM, and TPNS channels.
    vibrate Integer android 1 No Whether to enable vibration. Valid values:
  • 0: no
  • 1: yes
  • lights Integer android 1 No Whether to use the breathing light. Valid values:
  • 0: no
  • 1: yes
  • clearable Integer android 1 No Whether messages can be cleared from the notification bar. Valid values:
  • 0: no
  • 1: yes
  • icon_type Integer android 0 No Whether the notification bar thumbnail is an in-app icon or an uploaded icon. Valid values:
  • 0: in-app icon
  • 1: uploaded icon
  • This parameter is supported only for the TPNS, FCM, and Huawei channels.
    icon_res String android Empty No URL of the uploaded notification thumbnail. This parameter is supported only for the TPNS, FCM, and Huawei channels. For more information about the thumbnail formats, see Rich Media Notification.
    style_id Integer android 1 No Whether the notification style with the specified number will be overwritten
    small_icon String android Empty No The icon that the message displays in the status bar. If this parameter is not set, the application icon will be displayed.
    icon_color Integer android 0 No Color of the icon in the notification bar
  • This parameter takes effect only for the TPNS channel.
  • To use an RGB color such as #01e240, enter 123456.
  • action Object android Yes No The action after the notification bar is clicked; the default action is to open the app. For more information, see action parameter description.
    custom_content String android Empty No User-defined field (which should be serialized into a JSON string)
    Note:Huawei has officially notified that the "V2 protocol will be suspended from September 30, 2021." TPNS has upgraded the Huawei push protocol to V5. The V5 protocol does not support carrying custom parameters through the "Extra Parameters" parameter. If you have integrated the Huawei vendor channel, we recommend you use the Intent method to carry custom parameters, otherwise the custom parameters will not be successfully delivered through the Huawei push channel.
    show_type Integer android 2 No Whether to display the notification when the application is running in the foreground, which is displayed by default. This parameter takes effect only for the TPNS and FCM channels. Valid values:
  • 1: no
  • 2: yes
    Note: if the value is 1 and the application is running in the foreground, this push is imperceptible to end users, but arrival data will be reported.
  • action parameter description

    Parameter Type Parent Project Default Value Required Description
    action_type Integer action 1 No One-click actions. Valid values:
  • 1: open activity or the application
  • 2: open the browser
  • 3: open the application’s custom page (recommended; for more information, see here).
  • activity String action Empty Yes if action_type is 1 and an activity needs to be opened Full name of activity, such as com.x.y.PushActivity
    aty_attr Object action Empty No if action_type is 1 and an activity needs to be opened Activity attribute
  • if: Flag attribute of Intent in Integer type
  • pf: Flag attribute of PendingIntent in Integer type
  • browser Object action Empty Yes if action_type is 2 Action to open a browser
  • url: webpage URL in String type. Only HTTP and HTTPS URLs are supported
  • confirm: whether user's confirmation is required. The value is in Integer type.
  • 1: yes
    0: no
    intent String action Empty Yes if action_type is 3 Custom scheme, such as xgscheme://com.tpns.push/notify_detail

    Below is a sample of a complete message:

    {
      "title": "xxx",
      "content": "xxxxxxxxx",
      "xg_media_resources": "xxx" , // Enter the URL of rich media elements, such as `https://www.xx.com/img/bd_logo1.png?qua=high`
      "xg_media_audio_resources":"xxx", // Enter the URL of audio rich media elements, such as `http://sc1.111ttt.cn/2018/1/03/13/396131227447.mp3` 
      "thread_id":"Activity_id",
      "thread_sumtext":"Operational activity",
      "accept_time": [
          {
              "start": {// Period start time
                  "hour": "13",// Start time in hour. Value range: [0,24)
                  "min": "00"// Start time in minute. Value range: [0,60)
              },
              "end": {// Period end time
                  "hour": "14",// End time in hour. Value range: [0,24)
                  "min": "00" // End time in minute. Value range: [0,60)
               }
          },
          {
              "start": {
                  "hour": "00",
                  "min": "00"
              },
              "end": {
                  "hour": "09",
                  "min": "00"
              }
          }
      ],
      "android": {
            "n_ch_id": "default_message",
            "n_ch_name": "default notification",
            "n_id": 0,
            "builder_id": 0,
            "ring": 1,
            "ring_raw": "ring",
            "badge_type":-1, 
            "vibrate": 1,
            "lights": 1,
            "clearable": 1,
            "icon_type": 0,
            "icon_res": "xg",
            "style_id": 1,
            "small_icon": "xg",
            "action": {
                    "action_type": 1,// Action type; 1. Open activity or application; 2. Open browser; 3. Open Intent
                    "activity": "com.x.y.PushActivity",
                    "aty_attr": {// Activity attribute, only for action_type=1
                            "if": 0, // Intent's Flag attribute
                            "pf": 0  // PendingIntent's Flag attribute
                    },
                    "browser": {
                            "url": "https://cloud.tencent.com ", // Only HTTP and HTTPS URLs are supported
                            "confirm": 1 // Whether user's confirmation is required
                    },
                    "intent": "xgscheme://com.tpns.push/notify_detail" //The SDK must be version 1.0.9 or later. Configure the data tag in the client's Intent and set the scheme attribute
            },
            "custom_content":"{\"key\":\"value\"}"
        }
    }
    

    Notification message on iOS

    The table below specifies parameters for the iOS platform.

    Parameter Type Parent Project Default Value Required Description
    title String message Empty Yes Message title, which will override the content in title under alert.
    content String message Empty Yes Message content, which will override the content in body under alert.
    thread_id String message Empty No Thread ID for collapsed notification in threaded display
    ios Object message Empty Yes iOS message structure. See iOS parameter description for more information.
    show_type Integer message 2 No Whether to display the notification when the application is running in the foreground. Valid values:
  • 1: no
  • 2: yes
    Note: if the value is 1 and the application is running in the foreground, this push is imperceptible to end users, but arrival data will be reported.
  • xg_media_resources String message Empty No URL of rich media elements such as image, audio, and video

    iOS parameter description

    Parameter Type Parent Project Default Value Required Description
    aps Object ios Empty Yes APNs-specific parameter. For more information, see aps parameter description. For further information, see Payload.
    custom_content String ios Empty No Custom parameter for delivery, which must be serialized to a JSON string.

    aps parameter description

    Parameter Type Parent Project Default Value Required Description
    alert Object aps Empty Yes Contains the title and message content.
    badge_type Integer aps Empty No User-configured badge number. Valid values:
  • -1: the badge number does not change.
  • -2: the badge number automatically increases by 1.
  • >=0: a custom badge number is configured.
  • category String aps Empty No Action identifier displayed when the message is pulled down.
    mutable-content Integer aps 1 No This is an additional notification parameter that carries "mutable-content" during push.
  • 1 means that the Service Extension supports iOS 10.
  • Once enabled, the push details will include the arrival data report. Before using this feature, see Notification Service Extension to implement the Service Extension API. If mutable-content is not carried, arrival data will not be reported.
  • sound String aps Empty No Use instructions:
  • To play the system default ringtone, use "sound":"default"
  • To play local custom ringtone, use "sound":"chime.aiff"
  • To mute, use "sound":"" or remove the sound parameter. Note: if you want to use a custom ringtone, the ringtone must be in Linear PCM, MA4 (IMA/ADPCM), alaw, or μLaw format, saved in the bundle directory of the project, and last for 30 seconds at most; otherwise, the system default ringtone will be used.
  • Below is a sample of a complete message:

    {
      "title": "xxx",
      "content": "xxxxxxxxx",
      "thread_id":"Activity_id",
      "xg_media_resources":"https://www.xx.com/img/bd_logo1.png",
      "show_type":1,
      "ios":{
          "aps": {
              "alert": {
                  "subtitle": "my subtitle"
              },
              "badge_type": 5,
              "category": "INVITE_CATEGORY",
              "sound":"default",
              "mutable-content":1
          },
         "custom_content":"{\"key\":\"value\"}"
      }
    }
    

    In-app message on Android

    In-app message is unique to the Android platform and not displayed in the notification bar of the mobile phone. It can be used to deliver controlled messages to users imperceptibly.

    Note:

    Due to vendor restrictions, Android in-app messages can be delivered only through the TPNS channel, but not vendor channels.

    The table below specifies parameters for the Android platform:

    Parameter Type Parent Project Default Value Required Description
    title String message Empty Yes Command description
    content String message Empty Yes Command content
    android Object message Empty No Android message structure
    accept_time Array message Empty No The time period that allows pushes.
  • A single element is formed by a "start" time and an "end" time.
  • "start" and "end" are indicated by hour and minute. For more information, please see the samples.
  • Note: this is valid only for the TPNS channel due to vendor restrictions.
  • custom_content String android Empty No Custom content, which must be serialized to a JSON string

    Complete sample:

    {
      "title": "this is title",
      "content": "this is content",
      "android": {
        "custom_content":"{\"key\":\"value\"}"
      },
      "accept_time": [
          {
              "start": {
                  "hour": "13",
                  "min": "00"
              },
              "end": {
                  "hour": "14",
                  "min": "00"
              }
          },
          {
              "start": {
                  "hour": "00",
                  "min": "00"
              },
              "end": {
                  "hour": "09",
                  "min": "00"
              }
          }
      ]
    }
    

    iOS silent messages

    Similar to in-app messages on Android, silent messages are unique to the iOS platform and are not displayed. When a silent message arrives at the device, iOS wakes up the application for a period of time (less than 30 seconds) in the background to let the application handle the message logic.

    The specific parameters are as follows:

    Parameter Type Parent Project Default Value Required Description
    ios Object message Empty Yes iOS message structure
    aps Object ios Empty Yes APNs-specific parameter, where the most important key-value pair is as follows:
  • content-available: identifies the message type (which must be 1), in integer format.
  • The value cannot contain the alert, sound, or badge_type parameters. For more information, see Payload.
  • Note: content-available: 1 is mutually exclusive with [message_type:"notify"](#message body type). Do not use them at the same time.
    custom_content String ios Empty No Custom content, which must be serialized to a JSON string.

    Complete sample:

    {
      "ios":{
          "aps": {
              "content-available": 1
          },
        "custom_content":"{\"key\":\"value\"}"
      }
    }
    

    Optional Parameters

    Optional push API parameters refer to advanced parameters that can be carried in a push message, except audience_type, message_type, and message.

    Parameter Type Parent Project Required Default Value Description
    expire_time Integer None No 259200 (72 hours) Offline message retention duration (in seconds), up to 72 hours.
  • If expire_time is 0, it indicates a real-time message.
  • If expire_time is greater than 0 and less than 800 seconds, the system will reset it to 800 seconds.
  • If expire_time is greater than or equal to 800 seconds, the message will be retained according to the set value, up to 72 hours.
  • The value set cannot exceed 2147483647; otherwise, the push will fail.
  • send_time String None No Current system time Push time. You can specify a push time in the next 90 days.
  • The format is yyyy-MM-DD HH:MM:SS.
  • If the push time specified is earlier than the current server time, the push starts immediately.
  • This parameter is supported only for push to all devices, push by account package, or push to devices with specified tags.
  • multi_pkg Boolean None No false Multi-package name push: for an application that has multiple packages (such as for MyApp and Wandoujia), if you want the application in all channels to receive the push message, you can set this value to true.
    Note: this parameter controls the multi-package name push of the TPNS channel by default. To implement multi-package name push on vendor channels, see Configuring vendor channel for multi-package name.
    loop_param Object None No 0 Loop push parameters. This parameter is supported only for push to all devices, push by account package, or push to devices with specified tags. For more information about loop push parameters, see the loop_param parameter description below.
    group_id String None No tpns_yyyymmdd, where yyyymmdd indicates the push date This parameter has been disused and will be unavailable in the future. If you need to use the aggregate statistics feature, please use the push plan parameter (plan_id).
    plan_id String None No Empty Push plan ID. For more information about how to create and use the push plan, see Push Plan.
    tag_rules Array None Yes for tag push only Empty
  • For push based on a combination of tags, you can set 'AND', 'OR', and 'NOT' rules
  • Note: if both tag_rules and tag_list are specified, tag_list becomes invalid automatically. For parameter descriptions, please see tag_rules parameter description.
  • account_list Array None Yes for push to a single account or a list of accounts Empty For push to a single account:
  • audience_type must be account
  • Format: ["account1"]

  • For push to a list of accounts:
  • Format: ["account1","account2"]
  • Up to 1,000 accounts
  • account_push_type Integer None No for push by account 0 Push type. Valid values:
  • 0: push messages to the latest device of the account
  • 1: push messages to all devices associated with the account
  • account_type Integer None No 0 Account type, which must be consistent with that of the accounts to push to. For valid values, see Account Type Value Table.
    token_list Array None Yes for push to a single device or a list of devices Empty For push to a single device:
  • audience_type must be token
  • Format: ["token1"]
    For push to a list of devices:
  • Format: ["token1","token2"]
  • Up to 1,000 tokens
  • ignore_invalid_token int None No 0
  • 0: the API call will fail if there is an invalid token.
  • 1: ignore the invalid token and continue to deliver.
  • Note: this parameter takes effect only for push by a token or token list.
    push_speed Integer None No Empty
  • Push speed limit to X pushes per second. Value range of X: 1000-50000
  • This parameter is valid only for push to all devices, push by account package, and push to devices with specified tags.
  • collapse_id Integer None No System-assigned collapse_id
  • Message overriding parameter. After the first push task has been scheduled and delivered, if the second push task carries the same collapse_id, it will stop the TPNS channel data in the first push task that has not been delivered yet and will also overwrite the message in the first push task.
  • The collapse_id of a completed task can be obtained via the Querying Push Information for One Task API.
  • Currently, this is supported only for push to all devices, push to devices with specified tags, and push by account package.
  • channel_rules Array None No Empty Push channel selection policy.
  • You can select the channels through which a push can be delivered. Messages are pushed through all channels by default. For more information about the push policy, see Channel Policies.
  • For the data structure of single elements in the channel_rules array, see [channel_rules parameter description](#channel_rules parameter description 1) below.
  • tpns_online_push_type Integer None No 0 Whether to push the message to online devices through the TPNS channel. Valid values:
  • 0: yes
  • 1: no
  • force_collapse Boolean None No false Whether to deliver messages to OPPO or Vivo devices that do not support message overriding. Valid values:
  • false: no
  • true: yes
  • Note:

    The collapse_id parameter is subject to the following restrictions:

    • This parameter currently cannot be customized. Only collapse_id values generated by TPNS can be used.
    • This parameter is supported only for the TPNS channel, APNs channel, Mi channel, Meizu channel, and Huawei devices on EMUI 10 and above.
    • For the Huawei channel, you must use intent to carry custom parameters to implement message overriding. If you use custom_content, the API layer will block custom parameters.
    • Currently, the OPPO and vivo channels do not support message overriding. When an overriding message is created, delivery to the OPPO and vivo channels can be disabled by setting the force_collapse parameter to false.

    tag_rules parameter description

    Parameter Type Parent Project Required Description
    tag_items Array tag_rules Yes Tag rule. See tag_items description.
    operator String tag_rules Yes Operator between elements in the tag_rules array. The operator of the first tag_rules element is invalid data. The operator of the second tag_rules element is the operator between the first and second tag_rules elements, and so on. Valid values:
  • OR: OR operation
  • AND: AND operation
  • is_not Boolean tag_rules Yes Whether to perform "NOT" operation on the calculation result of the tag_items array.
  • true: yes
  • false: no
  • tag_items description

    Parameter Type Parent Project Required Description
    tags Array tag_items Yes Specific tag value in string type, such as tag1 and guangdong
    is_not Boolean tag_items Yes Whether to perform "NOT" operation on the calculation result of the tags array. Valid values:
  • true: yes
  • false: no
  • tags_operator String tag_items Yes Operator for tag in tags. Valid values:
  • OR: OR operation
  • AND: AND operation
  • items_operator String tag_items Yes Operator between elements in the tag_items array. The items_operator of the first tag_items element is invalid. The items_operator of the second tag_items element is the operator between the first and second tag_items elements, and so on. Valid values:
  • OR: OR operation
  • AND: AND operation
  • Note: between different rules, AND takes precedence over OR.
    tag_type String tag_items Yes See tag_type value table.

    tag_type value table

    Tag Name tag_type Value Sample Tag
    Custom tag xg_user_define tag1, tag2
    Application version xg_auto_version 1.1.0, 1.2.0.1
    Device district information xg_auto_province guangdong, shanghai
    Active information xg_auto_active 20200131, 20200201
    XG SDK version xg_auto_sdkversion 1.1.5.2, 1.1.5.3
    System language xg_auto_systemlanguage zh, en
    Mobile phone brand xg_auto_devicebrand Mi, vivo
    Mobile phone model xg_auto_deviceversion MI 9 SE, vivo X9Plus
    Country/Region xg_auto_country CN, SG
    Note:

    For more information about the usage, see Sample tag push.

    channel_rules parameter description

    Parameter Type Parent Project Required Description
    channel String channel_rules Yes Delivery push channel. Valid values:
  • hw: Huawei channel
  • xm: Mi channel
  • mz: Meizu channel
  • vivo: vivo channel
  • oppo: OPPO channel
  • apns: APNs channel
  • disable Boolean channel_rules Yes Whether to disable the channel specified in channel, which is enabled by default. Valid values:
  • true: disable
  • false: enable
  • loop_param parameter description

    Parameter Type Parent Project Required Description
    startDate String loop_param Yes Loop interval start date in YYYY-MM-DD format, such as 2019-07-01. You can choose a date in the next 90 days.
    endDate String loop_param Yes Loop interval end date in YYYY-MM-DD format, such as 2019-07-07. You can choose a date in the next 90 days.
    loopType Integer loop_param Yes Loop type. Valid values:
  • 1: daily
  • 2: weekly
  • 3: monthly
  • loopDayIndexs Array loop_param Yes For weekly loop, enter days [0-6] in a week. If the value is [0, 1, 2], it indicates that the push will be done on Monday, Tuesday, and Wednesday every week.
    dayTimes Array loop_param Yes Specific push time in HH:MM:SS format. If the value is ["19:00:00", "20:00:00"], it indicates that the push will be done at 19:00 and 20:00 every day.

    Response Parameters

    Parameter Type Description
    seq Integer Same as the request (if the request does not contain this parameter, this parameter returns 0).
    push_id String Push ID
    invalid_targe_list Array A value is returned only when the push target is token_list. This parameter stores filtered invalid tokens, and valid tokens will be delivered normally.
    ret_code Integer Error code. For more information, please see the error codes table.
    environment String Push environment specified by the user (only for iOS). Valid values:
  • product: production environment
  • dev: development environment
  • err_msg String Error message when a request error occurs
    result String When the request is correct:
  • If there is extra data to be returned, the result will be encapsulated in this parameter in JSON format.
  • If there is no extra data, this parameter may not exist.
  • Examples

    Android request message for push by account

    {
      "audience_type": "account",
      "account_list": [
        "account1"
    ],
    "multi_pkg":true,
    "push_speed":50000,
      "channel_rules": [
          {
              "channel": "mz",
              "disable": true
          },
          {
              "channel": "xm",
              "disable": false
          }
      ],
      "message_type": "notify",
      "message": {
      "title": "Test title",
      "content": "Test content",
      "xg_media_resources": "xxx1" , // Enter the URL of rich media elements, such as `https://www.xx.com/img/bd_logo1.png?qua=high`
      "xg_media_audio_resources":"xxx", // Enter the URL of audio rich media elements, such as `http://sc1.111ttt.cn/2018/1/03/13/396131227447.mp3` 
      "accept_time": [
          {
              "start": {// Period start time
                  "hour": "13",// Start time in hour. Value range: [0,24)
                  "min": "00"// Start time in minute. Value range: [0,60)
              },
              "end": {// Period end time
                  "hour": "14",// End time in hour. Value range: [0,24)
                  "min": "00" // End time in minute. Value range: [0,60)
               }
          },
          {
              "start": {
                  "hour": "00",
                  "min": "00"
              },
              "end": {
                  "hour": "09",
                  "min": "00"
              }
          }
      ],
      "android": {
            "n_ch_id": "default_message",
            "n_ch_name": "default notification",
            "n_id": 0,
            "builder_id": 0,
            "ring": 1,
            "ring_raw": "ring",
            "badge_type":-1,
            "vibrate": 1,
            "lights": 1,
            "clearable": 1,
            "icon_type": 0,
            "icon_res": "xg",
            "style_id": 1,
            "small_icon": "xg",
            "action": {
                    "action_type": 1,// Action type; 1. Open activity or application; 2. Open browser; 3. Open Intent
                    "activity": "xxx",
                    "aty_attr": {// activity attribute, only for action_type=1
                            "if": 0, // Intent's Flag attribute
                            "pf": 0  // PendingIntent's Flag attribute
                    },
                    "browser": {
                            "url": "xxxx ", // Only HTTP and HTTPS URLs are supported
                            "confirm": 1 // Whether user's confirmation is required
                    },
                    "intent": "xxx" // The SDK must be version 1.0.9 or later. Configure the data tag in the client's intent and set the scheme attribute
             },
             "custom_content":"{\"key\":\"value\"}"
            }
        }
    }
    

    Response message for push by account

    {
      "seq": 0,
      "environment": "product",
      "ret_code": 0,
      "push_id": "3895624686"
    }
    

    iOS request message for push to a single device

    {
      "audience_type": "token",
      "environment":"dev",
      "token_list": [ "05da87c0ae********fa9e08d884aada5bb2"],
      "message_type":"notify",
      "message":{
       "title": "Push title",
      "content": "Push content",
      "ios":{
          "aps": {
              "alert": {
                  "subtitle": "Push subtitle"
              },
              "badge_type": -2,
              "sound":"Tassel.wav",
              "category": "INVITE_CATEGORY"
           },
         "custom_content":"{\"key\":\"value\"}"
      }
    }
    }
    

    Response message for push to a single device

    {
      "seq": 0,
      "push_id": "427184209",
      "ret_code": 0,
      "environment": "dev",
      "err_msg": "",
      "result": "[0]"
    }
    

    Push by tag (using tag_rules)

    Sample 1: push messages to male users who were active on April 8, 2020 in Guangdong or Hunan province
    Expression: (xg_auto_province.guangdong OR xg_auto_province.hunan) AND xg_auto_active.20200408 AND xg_user_define.male

    {
    "audience_type": "tag",
    "tag_rules": [
          {
              "tag_items": [
                  {
                      "tags": [
                          "guangdong",
                          "hunan"
                      ],
                      "is_not": false,   //Whether to perform the "NOT" operation on the calculation result of the tags in `tags`. Valid values: `true`: yes; `false`: no
                      "tags_operator": "OR",  //Operator for tags in `tags`
                      "items_operator": "OR", //Operator between elements in `tag_items`. The `items_operator` of the first element is invalid data. The `items_operator` of the second element is the operator between the first and second elements, and so on.
                      "tag_type": "xg_auto_province" //Type of tags in `tags`
                  },
                  {
                      "tags": [
                          "20200408"
                      ],
                      "is_not": false,
                      "tags_operator": "OR",
                      "items_operator": "AND",
                      "tag_type": "xg_auto_active"
                  },
                  {
                      "tags": [
                          "male"
                      ],
                      "is_not": false,
                      "tags_operator": "OR",
                      "items_operator": "AND",
                      "tag_type": "xg_user_define"
                  }
              ],
              "operator": "OR", 
              "is_not": false  
          }
      ]
    }
    

    Sample 2: push messages to Huawei users who were active in the last 3 days on an application version other than 1.0.2
    Expression: (xg_auto_active.20200406 OR xg_auto_active.20200407 OR xg_auto_active.20200408) AND (NOT xg_auto_version.1.0.2) AND xg_auto_devicebrand.huawei

    {
    "audience_type": "tag",
    "tag_rules": [
          {
              "tag_items": [
                  {
                      "tags": [
                          "20200406",
                          "20200407",
                          "20200408"
                      ],
                      "is_not": false,   //Whether to perform the "NOT" operation on the calculation result of the tags in `tags`. Valid values: `true`: yes; `false`: no
                      "tags_operator": "OR",  //Operator for tags in `tags`
                      "items_operator": "OR", //Operator between elements in `tag_items`. The `items_operator` of the first element is invalid data. The `items_operator` of the second element is the operator between the first and second elements, and so on.
                      "tag_type": "xg_auto_active" //Type of tags in `tags`
                  },
                  {
                      "tags": [
                          "1.0.2"
                      ],
                      "is_not": true,
                      "tags_operator": "OR",
                      "items_operator": "AND",
                      "tag_type": "xg_auto_verison"
                  },
                  {
                      "tags": [
                          "huawei"
                      ],
                      "is_not": false,
                      "tags_operator": "OR",
                      "items_operator": "AND",
                      "tag_type": "xg_auto_devicebrand"
                  }
              ],
              "operator": "OR", 
              "is_not": false  
          }
      ]
    }