This API is used to obtain all instances of an offer model. The instances can be returned by page, based on pageSize.
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 GET |
|---|---|
Direction |
Developer server -> Huawei server |
URL |
{url}/hmspass/v1/offer/instance?modelId={modelId}&session={session}&pageSize={pageSize} 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 |
Parameter |
Mandatory/Optional |
Type |
Description |
|---|---|---|---|
modelId |
Mandatory |
String |
Unique identifier of a pass model. It must be unique across all models sharing the same appId. The value contains only letters, digits, dots (.), hyphens (-), and underscores (_). |
pageSize |
Optional |
int |
Number of results to be returned on each page. The maximum value is 50. All results are returned if this parameter is not specified. |
session |
Optional |
String |
If pageSize is specified and the total number of objects to be returned is greater than the pageSize value, the nextSession parameter will be returned in response to the query request. When the query request is sent again, with the session parameter set to the value of nextSession previously obtained, the next group of objects will be returned. Note that the session parameter is not required when the query request is sent to obtain the first group of objects. |
Note: If pageSize and session are both absent, all objects will be returned. If pageSize is set but session is not, the first group of objects will be returned. If both pageSize and session are set, the next group of objects will be returned. When session is set, pageSize must be set as well. If the total number of objects exceeds 50, pageSize must be set. When session is used to obtain the next group of objects, the pageSize value must be the same as that used to obtain the previous group of objects.
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. |
GET /hmspass/v1/offer/instance?modelId=offerModelTest HTTP/1.1 Content-Type: application/json;charset=utf-8 Authorization: Bearer *** Accept: application/json;charset=utf-8 Host: wallet-passentrust-drcn.cloud.huawei.com.cn
When the result code is 200:
Parameter |
Type |
Description |
|---|---|---|
data |
List<HwWalletObject> |
Pass models. |
pageInfo |
PageInfo |
Page information. |
PageInfo:
Parameter |
Type |
Description |
|---|---|---|
pageSize |
int |
Number of results to be returned on this page. |
nextSession |
String |
Session that is used to obtain the next page of results. It is valid within five minutes. |
HTTP/1.1 200 OK
Content-Type: application/json
{
"data": [
{
"organizationPassId": "5623489234",
"passTypeIdentifier": "hwpass.com.huawei.wallet.offer.test",
"passStyleIdentifier": "offerModelTest",
"serialNumber": "50001",
"fields": {
"status": {
"state": "active",
"effectTime": "2019-11-13T00:00:00.111Z",
"expireTime": "2020-11-20T00:00:00.111Z"
},
"barCode": {
"text": "562348969211212",
"type": "codabar",
"value": "562348969211212",
"encoding": "UTF-8"
}
}
}
],
"pageInfo": {
"pageSize": 1
}
}
public List<HwWalletObject> listWalletInstance(String url, String modelId, Integer pageSize) {
// Construct the HTTP header.
HttpHeaders header = constructHttpHeaders();
// Construct the HTTP URL.
String baseUrl = ConfigHelper.instants().getValue("walletServerBaseUrl") + url;
HttpEntity entity = new HttpEntity(header);
if (pageSize == null) {
ResponseEntity<BatchGetHwWalletResult> response = REST_TEMPLATE.exchange(url + "?modelId=" + modelId, HttpMethod.GET, entity, BatchGetHwWalletResult.class);
BatchGetHwWalletResult batchGetHwWalletResult = response.getBody();
if (batchGetHwWalletResult == null) {
System.out.println("listWalletInstance failed. batchGetHwWalletResult is null.");
return null;
} else {
return batchGetHwWalletResult.getData();
}
} else {
List<HwWalletObject> walletInstanceList = new LinkedList<>();
String tempUrl = baseUrl + "?modelId=" + modelId + "&pageSize=" + pageSize;
String session = "";
while (true) {
String finalUrl = tempUrl;
if (!session.isEmpty()) {
finalUrl = finalUrl + "&session=" + session;
}
ResponseEntity<BatchGetHwWalletResult> response =
REST_TEMPLATE.exchange(finalUrl, HttpMethod.GET, entity, BatchGetHwWalletResult.class);
BatchGetHwWalletResult batchGetHwWalletResult = response.getBody();
if (batchGetHwWalletResult == null) {
System.out.println("listWalletInstance failed. batchGetHwWalletResult is null.");
return null;
}
List<HwWalletObject> data = batchGetHwWalletResult.getData();
if (data == null || data.isEmpty()) {
return walletInstanceList;
}
walletInstanceList.addAll(data);
PageInfo pageInfo = batchGetHwWalletResult.getPageInfo();
if (pageInfo == null) {
System.out.println("listWalletInstance failed. pageInfo is null.");
return null;
}
String nextSession = pageInfo.getNextSession();
if (nextSession == null || nextSession.isEmpty()) {
return walletInstanceList;
}
session = nextSession;
}
}
}