This API is used to add the loyalty card instance of a user to the Huawei server. After the instance is added using this API, a thin JWE should be used as well to link the instance to the user's HUAWEI ID. Alternatively, a JWE can be used, rather this API, to directly add the instance to the Huawei server and link it to the user's HUAWEI ID.
You need to create an app in AppGallery Connect and apply for services corresponding to the passes. In addition, the pass model of the instances to be obtained must have been added to the Huawei server.
Protocol |
HTTPS POST |
|---|---|
Direction |
Developer server -> Huawei server |
URL |
{url}/hmspass/v1/loyalty/instance Set the {url} variable based on the region where the server is located. For details, please refer to Wallet Server Addresses. |
Data Format |
Request: Content-Type: application/json Response: Content-Type: application/json |
Request Header
Parameter |
Mandatory/Optional |
Type |
Description |
|---|---|---|---|
Authorization |
Mandatory |
String |
Authorization code. For details about how to obtain the value, please refer to the Client Credentials mode in OAuth 2.0-based Authentication. In this mode, client_id and client_secret are respectively the App ID and App key of the app that you created in AppGallery Connect. Concatenate the value of access_token to the end of Bearer, with a space in between, to generate the value of Authorization. |
Content-Type |
Mandatory |
String |
The value is always application/json;charset=utf-8. |
Accept |
Mandatory |
String |
The value is always application/json;charset=utf-8. |
Request Body
Parameter |
Mandatory/Optional |
Type |
Description |
|---|---|---|---|
For details, please refer to the HwWalletObject Parameters. |
Mandatory |
Pass instance to be added. |
POST /hmspass/v1/loyalty/instance HTTP/1.1
Content-Type: application/json;charset=utf-8
Authorization: Bearer ***
Host: wallet-passentrust-drcn.cloud.huawei.com.cn
Accept: application/json;charset=utf-8
{
"passTypeIdentifier": "hwpass.com.huawei.wallet.loyalty.test",
"passStyleIdentifier": "loyaltyModelTest",
"organizationPassId": "356688115",
"serialNumber": "40001",
"fields": {
"status": {
"state": "active",
"effectTime": "2019-11-13T00:00:00.111Z",
"expireTime": "2028-11-20T00:00:00.111Z"
},
"barCode": {
"text": "1118466050",
"type": "codabar",
"value": "1118466050",
"encoding": "UTF-8"
},
"commonFields": [
{
"key": "cardNumber",
"value": "356688115",
"label": "Card Number"
},
{
"key": "balance",
"value": "$199",
"label": "Balance"
},
{
"key": "memberName",
"value": "Joe Wiley",
"label": "Name"
}
],
"appendFields": [
{
"key": "points",
"value": "2000",
"label": "Points"
}
]
}
}
When the result code is 200:
Parameter |
Type |
Description |
|---|---|---|
For details, please refer to the HwWalletObject Parameters. |
Added pass instance. |
HTTP/1.1 200 OK
Content-Type: application/json
{
"passTypeIdentifier": "hwpass.com.huawei.wallet.loyalty.test",
"passStyleIdentifier": "loyaltyModelTest",
"organizationPassId": "356688115",
"serialNumber": "40001",
"fields": {
"status": {
"state": "active",
"effectTime": "2019-11-13T00:00:00.111Z",
"expireTime": "2028-11-20T00:00:00.111Z"
},
"barCode": {
"text": "1118466050",
"type": "codabar",
"value": "1118466050",
"encoding": "UTF-8"
},
"commonFields": [
{
"key": "cardNumber",
"value": "356688115",
"label": "Card Number"
},
{
"key": "balance",
"value": "$199",
"label": "Balance"
},
{
"key": "memberName",
"value": "Joe Wiley",
"label": "Name"
}
],
"appendFields": [
{
"key": "points",
"value": "2000",
"label": "Points"
}
]
}
}
public HwWalletObject postHwWalletObjectToWalletServer(String url, HwWalletObject hwWalletObject) {
// Construct the HTTP header.
HttpHeaders header = constructHttpHeaders();
// Construct the HTTP body.
String body = CommonUtil.toJson(hwWalletObject);
JSONObject jsonObj = JSONObject.parseObject(body);
System.out.println("Request JSON : " + jsonObj);
// Construct the HTTP URL.
String baseUrl = ConfigHelper.instants().getValue("walletServerBaseUrl");
String walletServerUrl = baseUrl + url;
// Send the HTTP request and obtain the response.
HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObj, header);
ResponseEntity<HwWalletObject> exchange =
REST_TEMPLATE.exchange(walletServerUrl, HttpMethod.POST, entity, HwWalletObject.class);
// Return the pushed wallet model.
return exchange.getBody();
}