目录

Adding Messages to an Offer Model

Function

Adds messages to an offer model based on modelId.

Scenario

This API is used to add one or more messages to an offer model based on modelId. After you modify a pass model, all passes using this model and claimed by users will be updated accordingly. For details about the update scenarios, please refer to Synchronous and Asynchronous Update.

Restrictions

You need to create an app in AppGallery Connect and apply for services corresponding to the passes. In addition, messages can be added only to a model that has been added to the Huawei server.

Prototype

Protocol

HTTPS POST

Direction

Developer server -> HUAWEI Account Kit server

URL

{url}/hmspass/v1/offer/model/{modelId}/addMessage

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

URL Parameters

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 (_).

Request Parameters

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

messageList

Mandatory

List<ValueObject>

Messages to be added.

Request Example

POST /hmspass/v1/offer/model/offerModelTest/addMessage 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
{
  "messageList": [
    {
      "key": "message[10]",
      "value": "Hello everyone!"
    }
  ]
}

Response Parameters

When the result code is 200:

Parameter

Type

Description

For details, please refer to the HwWalletObject Parameters.

HwWalletObject

Updated pass model.

Response Example

HTTP/1.1 200 OK
Content-Type: application/json
{
  "passVersion": "2.0",
  "passTypeIdentifier": "hwpass.com.huawei.wallet.offer.test",
  "passStyleIdentifier": "offerModelTest",
  "organizationName": "Huawei",
  "fields": {
    "countryCode": "CN",
    "locationList": [
      {
        "longitude": "114.0679603815",
        "latitude": "22.6592051284"
      }
    ],
    "commonFields": [
      {
        "key": "logo",
        "value": "https://www.huawei.com/new_image_url.png"
      },
      {
        "key": "name",
        "value": "70%-Off Coupon",
        "localizedValue": "nameI18N"
      },
      {
        "key": "providerName",
        "value": "YYY Producer"
      },
      {
        "key": "merchantName",
        "value": "HUAWEI Vmall",
        "localizedValue": "merchantNameI18N"
      }
    ],
    "appendFields": [
      {
        "key": "details",
        "value": "Detail information of this coupon.",
        "localizedValue": "detailsI18N"
      },
      {
        "key": "declaration",
        "value": "Coupon disclaimer provided by merchant.",
        "localizedValue": "declarationI18N"
      },
      {
        "key": "backgroundColor",
        "value": "#FF1C2635"
      }
    ],
    "messageList": [
      {
        "key": "message[0]",
        "value": "Don't miss this great offer!",
        "label": "Important!",
        "localizedValue": "message[0]I18N"
      },
      {
        "key": "message[10]",
        "value": "Hello everyone!"
      }
    ],
    "imageList": [
      {
        "key": "mainImage[0]",
        "value": "https://www.huawei.com/XXX0.png"
      },
      {
        "key": "mainImage[1]",
        "value": "https://www.huawei.com/XXX1.png"
      },
      {
        "key": "mainImage[2]",
        "value": "https://www.huawei.com/XXX2.png"
      }
    ],
    "localized": [
      {
        "key": "merchantNameI18N",
        "language": "zh-cn",
        "value":"HUAWEI Vmall"
      },
      {
        "key": "merchantNameI18N",
        "language": "en",
        "value": "HUAWEI Vmall"
      },
      {
        "key": "message[0]I18N",
        "language": "zh-cn",
        "value": "Don't miss this great offer!"
      },
      {
        "key": "message[0]I18N",
        "language": "en",
        "value": "Don't miss this great offer!"
      }
    ]
  }
}

Result Codes

For details, please refer to Result Codes.

Call Example

public HwWalletObject addMessageToHwWalletObject(String url, String resourceId, String body) {
    // Construct the HTTP header.
    HttpHeaders header = constructHttpHeaders();
    // Construct the HTTP URL.
    String baseUrl = ConfigHelper.instants().getValue("walletServerBaseUrl");
    String walletServerUrl = baseUrl + url.replace("addMessage", "") + resourceId + "/addMessage";
    // Construct the HTTP body.
    JSONObject jsonObj = JSONObject.parseObject(body);

    // Send the HTTP request and obtain the response.
    HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObj, header);
    ResponseEntity<HwWalletObject> response =
        REST_TEMPLATE.exchange(walletServerUrl, HttpMethod.POST, entity, HwWalletObject.class);

    // Return the updated HwWalletObject.
    return response.getBody();
}