目录

Request Example

Notification Message

// Request URL
POST "https://push-api.cloud.huawei.com/v3/3158882***52863/messages:send"

// Request Header
Content-Type: application/json
Authorization: Bearer eyJr*****OiIx---****.eyJh*****iJodHR--***.QRod*****4Gp---****
push-type:0
 
// Request Body
{
  "payload": {
    "notification": {
      "category": "xxxxxx", // Set it to the actual notification message type.
      "title": "Common title,"
      "body": "Common content,"
      "clickAction": {
        "actionType": 0
      },
      "style": 0,
      "image":"https://lf*******246.png"
    }
  },
  "target": {
    "token": ["MAAALgE4G98BAAAAst*******jg"]
  }
}

[h2]Receiving Notification Messages When the App is Running in the Foreground

Notifications are displayed only when the app is in the background. When an app is in the foreground, notifications will not be displayed, but the app can receive the message content to handle its own service logic. For details, please refer to Processing Notification Messages When the App is Running in the Foreground.

// Request URL
POST "https://push-api.cloud.huawei.com/v3/3158882***52863/messages:send"

// Request Header
Content-Type: application/json
Authorization: Bearer eyJr*****OiIx---****.eyJh*****iJodHR--***.QRod*****4Gp---****
push-type:0

// Request Body
{
  "payload": {
    "notification": {
      "category": "MARKETING",
      "title": "Common notification title",
      "body": "Common notification content",
      "clickAction": {
        "actionType": 0
      },
      "foregroundShow": false // When this parameter is set to false, notification messages are not displayed when the app is running in the foreground. The default value is true, indicating that notification messages are displayed no matter whether the app is running in the foreground or background.
    }
  },
  "target": {
    "token": ["MAMzLg**********lPW"]
  },
  "pushOptions": {
    "testMessage": true,
    "ttl": 86400
  }
}

Badge Update Message

You can send standalone badge update messages containing the badge parameter to specify a badge number. Upon receiving this message, the app icon on the home screen will display a numeric badge to remind users to check their messages in a timely manner.

// Request URL
POST "https://push-api.cloud.huawei.com/v3/3158882***52863/messages:send"

// Request Header
Content-Type: application/json
Authorization: Bearer eyJr*****OiIx---****.eyJh*****iJodHR--***.QRod*****4Gp---****
push-type:0

// Request Body
{
  "payload": {
    "notification": {
      "badge": {
        "setNum": 99
      }
    }
  },
 "pushOptions": {
    "biTag": "this is biTag",
    "ttl": 600
  },
  "target": {
    "token": ["MAAALgE4G98BAAAAst************jq"]
  }
}

Widget Update Message

// Request URL
POST "https://push-api.cloud.huawei.com/v3/3158882***52863/messages:send"

// Request Header
Content-Type: application/json
Authorization: Bearer eyJr*****OiIx---****.eyJh*****iJodHR--***.QRod*****4Gp---****
push-type:1
 
// Request Body
{
  "payload": {
    "formData": {
      "textKey": "Service data of the widget to be updated"
    },
    "version": 922337203,
    "images": [
      {
        "keyName": "imageKey",
        "url": "https://xxx.png",
        "require": 1
      }
    ],
    "formId": 0,
    "moduleName": "testName",
    "formName": "testFormName",
    "abilityName": "testAbilityName"
  },
  "pushOptions": {
    "biTag": "bi**62",
    "ttl": 86400
  },
  "target": {
    "token": [
      "MAAALgE4G98BAAAAst************ttQd4Tw"
    ]
  }
}

Text-to-Speech Message

// Request URL
POST "https://push-api.cloud.huawei.com/v3/3158882***52863/messages:send"

// Request Header
Content-Type: application/json
Authorization: Bearer eyJr*****OiIx---****.eyJh*****iJodHR--***.QRod*****4Gp---****
push-type:2
 
// Request Body
{
  "payload": {
    "extraData": "Extension extra data",
    "notification": {
      "category": "PLAY_VOICE",
      "title": "Common title,"
      "body": "Common content,"
      "clickAction": {
        "actionType": 0
      },
      "style": 0,
      "image":"https://lf*******246.png"
    }
  },
  "target": {
    "token": ["MAAALgE4G98BAAAAst*******jg"]
  }
}

Background Message

// Request URL
POST "https://push-api.cloud.huawei.com/v3/3158882***52863/messages:send"

// Request Header
Content-Type: application/json
Authorization: Bearer eyJr*****OiIx---****.eyJh*****iJodHR--***.QRod*****4Gp---****
push-type:6
 
// Request Body
{
  "payload": {
    "extraData": "Data to be carried"
  },
  "target": {
    "token": ["MAAALgE4G98BAAAAst************jq"]
  }
}

Live View Creation Message

[h2]Flight Scenario (event: FLIGHT)

Planned departure, using the left-right text template.

// Request URL
POST "https://push-api.cloud.huawei.com/v3/3158882***52863/messages:send"
 
// Request Header
Content-Type: application/json
Authorization: Bearer eyJr*****OiIx---****.eyJh*****iJodHR--***.QRod*****4Gp---****
push-type:7

// Request Body
{
  "pushOptions": {
    "ttl": 1000,
    "biTag": "biTag"
  },
  "payload": {
    "activityId": 1,
    "operation": 0,
    "event": "FLIGHT",
    "status": "DEPART", // Planned departure.
    "activityData": {
      "notificationData": {
        "keywords": {
          "flightNo": "MU1471"
        },
        "type": 5,
        "contentTitle": "Flight {{status}}", // Planned flight departure.
        "contentText": [
          {
            "text": "Flight No.:"
          },
          {
            "text": "{{flightNo}}", // MU1471
            "foregroundColor": "#FF317AF7"
          }
        ],
        "clickAction": {
          "actionType": 0
        },
        "firstTextBlock": {
          "firstLine": "12:00",
          "secondLine": "Shanghai Hongqiao"
        },
        "lastTextBlock": {
          "firstLine": "14:20",
          "secondLine": "Chengdu Tianfu"
        },
        "displayHorizontalLine": true,
        "spaceIcon": "space.png", // The value is a file name in /resources/rawfile.
        "extend": {
          "type": 3,
          "pic": "flight.png", // The value is a file name in /resources/rawfile.
          "clickAction": {
            "actionType": 1,
            "action": "xxxxxxx"
          }
        }
      },
      "capsuleData": {
        "type": 1,
        "status": 1,
        "icon": "icon.svg", // The value is a file name in /resources/rawfile.
        "bgColor": "#FF317AF7",
        "remind": "EXPAND",
        "title": "About to depart",
        "content": "Please head to the airport as soon as possible."
      }
    }
  },
  "target": {
    "token": [
      "MAAALgE4G98BAAAAst************jq"
    ]
  }
}

[h2]Ride Hailing Scenario (event: TAXI)

Driver on the way, using the progress visualization template.

// Request URL
POST "https://push-api.cloud.huawei.com/v3/3158882***52863/messages:send"

// Request Header
Content-Type: application/json
Authorization: Bearer eyJr*****OiIx---****.eyJh*****iJodHR--***.QRod*****4Gp---****
push-type:7

// Request Body
{
  "pushOptions": {
    "ttl": 1000,
    "biTag": "biTag"
  },
  "payload": {
    "activityId": 2,
    "operation": 0,
    "event": "TAXI",
    "status": "DRIVER_ON_THE_WAY", // Driver on the way.
    "activityData": {
      "notificationData": {
        "type": 3,
        "contentTitle": "{{status}}", // Driver on the way.
        "contentText": [
          {
            "text": "1.2 km"
          },
          {
            "text": "away",
            "foregroundColor": "#FF317AF7"
          },
          {
            "text": " | "
          },
          {
            "text": "5 minutes",
            "foregroundColor": "#FF317AF7"
          }
        ],
        "clickAction": {
          "actionType": 1, // Launch the custom app page.
          "action": "xxxxxx" // Action corresponding to the ability of the in-app page.
        },
        "richProgress": {
          "type": 0,
          "nodeIcons": ["icon1.png", "icon2.png", "icon3.png"], // The value is file names in resources/rawfile.
          "indicatorIcon": "taxi.png", // The value is a file name in /resources/rawfile.
          "progress": 40,
          "indicatorType": 1,
          "color": "#FF317AF7",
          "bgColor": "#19000000"
        },
        "extend": {
          "type": 3,
          "pic": "phone.png", // The value is a file name in /resources/rawfile.
          "clickAction": {
            "actionType": 5, // Open the dialer screen.
            "data": {
              "tel": "138xxxxxxxx" // Phone number carried through the tel field.
            }
          }
        }
      },
      "capsuleData": {
        "type": 1,
        "status": 1,
        "icon": "icon.svg", // The value is a file name in /resources/rawfile.
        "bgColor": "#FF317AF7",
        "remind": "EXPAND",
        "title": "Picking up",
        "content": "About 5 minutes"
      }
    }
  },
  "target": {
    "token": [
      "MAAALgE4G98BAAAAst************jq"
    ]
  }
}

[h2]High-Speed Rail or Common Train (event: TRAIN)

Planned departure, using the left-right text template.

// Request URL
POST "https://push-api.cloud.huawei.com/v3/3158882***52863/messages:send"

// Request Header
Content-Type: application/json
Authorization: Bearer eyJr*****OiIx---****.eyJh*****iJodHR--***.QRod*****4Gp---****
push-type:7

// Request Body
{
  "pushOptions": {
    "ttl": 1000,
    "biTag": "biTag"
  },
  "payload": {
    "activityId": 3,
    "operation": 0,
    "event": "TRAIN",
    "status": "DEPART", // Planned departure.
    "title": "About to depart",
    "content": "Please head to the high-speed railway station as soon as possible.",
    "activityData": {
      "notificationData": {
        "keywords": {
          "trainNo": "G1406"
        },
        "type": 5,
        "contentTitle": "Train {{status}}", // Planned train departure.
        "contentText": [
          {
            "text": "Train No.:"
          },
          {
            "text": "{{trainNo}}", // G1406
            "foregroundColor": "#FF317AF7"
          }
        ],
        "clickAction": {
          "actionType": 0
        },
        "firstTextBlock": {
          "firstLine": "13:00",
          "secondLine": "Shanghai Hongqiao"
        },
        "lastTextBlock": {
          "firstLine": "14:20",
          "secondLine": "Nanjing South Railway Station"
        },
        "displayHorizontalLine": true,
        "spaceIcon": "space.png", // The value is a file name in /resources/rawfile.
        "extend": {
          "type": 3,
          "pic": "train.png", // The value is a file name in /resources/rawfile.
          "clickAction": {
            "actionType": 1,
            "action": "xxxxxxx"
          }
        }
      },
      "capsuleData": {
        "type": 1,
        "status": 1,
        "icon": "icon.svg", // The value is a file name in /resources/rawfile.
        "bgColor": "#FF317AF7",
        "remind": "EXPAND",
        "title": "About to depart",
        "content": "Please head to the high-speed railway station as soon as possible."
      }
    }
  },
  "target": {
    "token": [
      "MAAALgE4G98BAAAAst************jq"
    ]
  }
}

Live View Update Message

[h2]Flight Scenario (event: FLIGHT)

Checked in, using the left-right text template.

// Request URL
POST "https://push-api.cloud.huawei.com/v3/3158882***52863/messages:send"
 
// Request Header
Content-Type: application/json
Authorization: Bearer eyJr*****OiIx---****.eyJh*****iJodHR--***.QRod*****4Gp---****
push-type:7

// Request Body
{
  "pushOptions": {
    "ttl": 1000,
    "biTag": "biTag"
  },
  "payload": {
    "activityId": 1,
    "operation": 1,
    "event": "FLIGHT",
    "status": "CHECKED_IN", // Checked in.
    "version": 1,
    "activityData": {
      "notificationData": {
        "keywords": {
          "flightNo": "MU1471"
        },
        "type": 5,
        "contentTitle": "Gate 88",
        "contentText": [
          {
            "text": "{{status}} | " // Checked in.
          },
          {
            "text": "{{flightNo}}", // MU1471
            "foregroundColor": "#FF317AF7"
          }
        ],
        "clickAction": {
          "actionType": 0
        },
        "firstTextBlock": {
          "firstLine": "12:00",
          "secondLine": "Shanghai Hongqiao"
        },
        "lastTextBlock": {
          "firstLine": "14:20",
          "secondLine": "Chengdu Tianfu"
        },
        "displayHorizontalLine": true,
        "spaceIcon": "space.png", // The value is a file name in /resources/rawfile.
        "extend": {
          "type": 3,
          "pic": "flight.png", // The value is a file name in /resources/rawfile.
          "clickAction": {
            "actionType": 1,
            "action": "xxxxxxx"
          }
        }
      },
      "capsuleData": {
        "type": 1,
        "status": 1,
        "icon": "icon.svg", // The value is a file name in /resources/rawfile.
        "bgColor": "#FF317AF7",
        "remind": "EXPAND",
        "title": "Gate 88",
        "content": "Please complete security check as soon as possible."
      }
    }
  },
  "target": {
    "token": [
      "MAAALgE4G98BAAAAst************jq"
    ]
  }
}

[h2]Ride Hailing Scenario (event: TAXI)

Heading to the destination, using the progress visualization template.

// Request URL
POST "https://push-api.cloud.huawei.com/v3/3158882***52863/messages:send"

// Request Header
Content-Type: application/json
Authorization: Bearer eyJr*****OiIx---****.eyJh*****iJodHR--***.QRod*****4Gp---****
push-type:7

// Request Body
{
  "pushOptions": {
    "ttl": 1000,
    "biTag": "biTag"
  },
  "payload": {
    "activityId": 2,
    "operation": 1,
    "event": "TAXI",
    "status": "HEADING_TO_DESTINATION", // Heading to the destination.
    "version": 1,
    "activityData": {
      "notificationData": {
        "type": 3,
        "contentTitle": "{{status}}", // Heading to the destination.
        "contentText": [
          {
            "text": "Remaining distance:"
          },
          {
            "text": "7.2 km",
            "foregroundColor": "#FF317AF7"
          },
          {
            "text": " | About"
          },
          {
            "text": "27 minutes",
            "foregroundColor": "#FF317AF7"
          }
        ],
        "clickAction": {
          "actionType": 1,
          "action": "xxxxxx"
        },
        "richProgress": {
          "type": 0,
          "nodeIcons": ["icon1.png", "icon2.png", "icon3.png"], // The value is file names in resources/rawfile.
          "indicatorIcon": "taxi.png", // The value is a file name in /resources/rawfile.
          "progress": 60,
          "indicatorType": 1,
          "color": "#FF317AF7",
          "bgColor": "#19000000"
        },
        "extend": {
          "type": 0
        }
      },
      "capsuleData": {
        "type": 1,
        "status": 1,
        "icon": "icon.svg", // The value is a file name in /resources/rawfile.
        "bgColor": "#FF317AF7",
        "title": "27 minutes",
        "content": "Remaining distance: 7.2 km"
      }
    }
  },
  "target": {
    "token": [
      "MAAALgE4G98BAAAAst************jq"
    ]
  }
}

Trip completed, using the emphasized text template.

// Request URL
POST "https://push-api.cloud.huawei.com/v3/3158882***52863/messages:send"

// Request Header
Content-Type: application/json
Authorization: Bearer eyJr*****OiIx---****.eyJh*****iJodHR--***.QRod*****4Gp---****
push-type:7

// Request Body
{
  "pushOptions": {
    "ttl": 1000,
    "biTag": "biTag"
  },
  "payload": {
    "activityId": 2,
    "operation": 1,
    "event": "TAXI",
    "status": "COMPLETED", // The trip is complete.
    "version": 2,
    "activityData": {
      "notificationData": {
        "type": 4,
        "contentTitle": "{{status}}. Please pay.", // The trip is complete. Please pay.
        "contentText": [
          {
            "text": "Total:"
          },
          {
            "text": "10 km",
            "foregroundColor": "#FF317AF7"
          },
          {
            "text": " | Duration:"
          },
          {
            "text": "30 minutes",
            "foregroundColor": "#FF317AF7"
          }
        ],
        "clickAction": {
          "actionType": 1,
          "action": "xxxxxx"
        },
        "singleTextBlock": {
          "firstLine": "Total fee:",
          "secondLine": "35.2 yuan",
          "underlineColor": "#FF317AF7"
        },
        "descPic": "payment.png", // The value is a file name in /resources/rawfile.
        "extend": {
          "type": 0
        }
      },
      "capsuleData": {
        "type": 1,
        "status": 1,
        "icon": "icon.svg", // The value is a file name in /resources/rawfile.
        "bgColor": "#FF317AF7",
        "title": "Pending payment",
        "content": "The fee is 35.2 yuan."
      }
    }
  },
  "target": {
    "token": [
      "MAAALgE4G98BAAAAst************jq"
    ]
  }
}

[h2]High-Speed Rail or Common Train (event: TRAIN)

Train heading to the destination, using the left-right text template.

// Request URL
POST "https://push-api.cloud.huawei.com/v3/3158882***52863/messages:send"

// Request Header
Content-Type: application/json
Authorization: Bearer eyJr*****OiIx---****.eyJh*****iJodHR--***.QRod*****4Gp---****
push-type:7

// Request Body
{
  "pushOptions": {
    "ttl": 1000,
    "biTag": "biTag"
  },
  "payload": {
    "activityId": 3,
    "operation": 1,
    "event": "TRAIN",
    "status": "HEADING_TO_DESTINATION", // Train heading to the destination.
    "version": 1,
    "activityData": {
      "notificationData": {
        "keywords": {
          "trainNo": "G1406"
        },
        "type": 5,
        "contentTitle": "{{status}}", // Train heading to the destination.
        "contentText": [
          {
            "text": "Train No.:"
          },
          {
            "text": "{{trainNo}}", // G1406
            "foregroundColor": "#FF317AF7"
          }
        ],
        "clickAction": {
          "actionType": 0
        },
        "firstTextBlock": {
          "firstLine": "13:00",
          "secondLine": "Shanghai Hongqiao"
        },
        "lastTextBlock": {
          "firstLine": "14:20",
          "secondLine": "Nanjing South Railway Station"
        },
        "displayHorizontalLine": true,
        "spaceIcon": "space.png", // The value is a file name in /resources/rawfile.
        "extend": {
          "type": 3,
          "pic": "train.png", // The value is a file name in /resources/rawfile.
          "clickAction": {
            "actionType": 1,
            "action": "xxxxxxx"
          }
        }
      },
      "capsuleData": {
        "type": 1,
        "status": 1,
        "icon": "icon.svg", // The value is a file name in /resources/rawfile.
        "bgColor": "#FF317AF7",
        "title": "Heading to the destination",
        "content": "Estimated arrival time: 14:20"
      }
    }
  },
  "target": {
    "token": [
      "MAAALgE4G98BAAAAst************jq"
    ]
  }
}

[h2]Sports Score Scenario (event: SCORE)

Live score push, using the live scores template.

// Request URL
POST "https://push-api.cloud.huawei.com/v3/3158882***52863/messages:send"

// Request Header
Content-Type: application/json
Authorization: Bearer eyJr*****OiIx---****.eyJh*****iJodHR--***.QRod*****4Gp---****
push-type:7
 
// Request Body
{
  "pushOptions": {
    "ttl": 1000,
    "biTag": "biTag"
  },
  "payload": {
    "activityId": 4,
    "operation": 1,
    "event": "SCORE",
    "activityData": {
      "notificationData": {
        "type": 7,
        "contentTitle": "Fourth period",
        "contentText": [
          {
            "text": "XX",
            "foregroundColor": "#FF317AF7"
          },
          {
            "text": " VS "
          },
          {
            "text": "XX",
            "foregroundColor": "#FF317AF7"
          },
          {
            "text": " | Fifth period"
          }
        ],
         "game": {
            "host": {
              "icon":"host.png", // The value is a file name in /resources/rawfile.
              "name": "Team A",
              "score": "110"
            },
            "guest": {
              "icon":"guest.png", // The value is a file name in /resources/rawfile.
              "name": "Team B",
              "score": "102"
            },
            "competition": {
              "desc": "Q4",
              "time":"02:16"
            }
          },
        "displayHorizontalLine": true,
        "clickAction": {
          "actionType": 1,
          "action": "xxxxxxx"
        }
      },
      "capsuleData": {
        "type": 1,
        "status": 1,
        "icon": "icon.svg", // The value is a file name in /resources/rawfile.
        "bgColor": "#FF317AF7",
        "title": "110:102",
        "content": "Fourth period"
      }
    }
  },
  "target": {
    "token": ["MAAALgE4G98BAAAAst************jq"]
  }
}

In-app Call Message

// Request URL
POST "https://push-api.cloud.huawei.com/v3/3158882***52863/messages:send"

// Request Header
Content-Type: application/json
Authorization: Bearer eyJr*****OiIx---****.eyJh*****iJodHR--***.QRod*****4Gp---****
push-type:10
 
// Request Body
{
  "pushOptions": {
    "biTag": "biTag",
    "ttl": 30
  },
  "payload": {
    "extraData": "Data transferred to an app."
  },
  "target": {
    "token": [
      "MAAALgE4G98BAAAAst************jq"
    ]
  }
}