manage method

Manages (inserts, updates, or removes) a customer's loyalty tier information.

This method serves as a single interface for all changes to a customer's loyalty status. The specific action (insert, update, or remove) is determined by the current state of the merchant-to-customer association and the loyalty_tier value provided in the request. Operation Logic:

  • Upsert (Insert/Update): Providing any valid tier other than NON_MEMBER will associate the customer with that tier. If an association already exists, it will be updated; otherwise, a new one will be created.
  • Removal: Setting loyalty_tier to NON_MEMBER will remove any existing loyalty association for the customer. Privacy Note: To protect user privacy, this method consistently returns a 200 OK status with a default LoyaltyCustomer response if the customer's identifier cannot be matched to a Google account or if the user has not opted into loyalty personalization.

request - The metadata request object.

Request parameters:

parent - Required. The parent account where this loyalty customer will be handled. Format: accounts/{account} Value must have pattern ^accounts/\[^/\]+$.

$fields - Selector specifying which fields to include in a partial response.

Completes with a ManageLoyaltyCustomerMatchResponse.

Completes with a commons.ApiRequestError if the API endpoint returned an error.

If the used http.Client completes with an error when making a REST call, this method will complete with the same error.

Implementation

async.Future<ManageLoyaltyCustomerMatchResponse> manage(
  ManageLoyaltyCustomerMatchRequest request,
  core.String parent, {
  core.String? $fields,
}) async {
  final body_ = convert.json.encode(request);
  final queryParams_ = <core.String, core.List<core.String>>{
    'fields': ?$fields == null ? null : [$fields],
  };

  final url_ =
      'loyaltyCustomers/v1/' +
      core.Uri.encodeFull('$parent') +
      '/loyaltyCustomers:manage';

  final response_ = await _requester.request(
    url_,
    'POST',
    body: body_,
    queryParams: queryParams_,
  );
  return ManageLoyaltyCustomerMatchResponse.fromJson(
    response_ as core.Map<core.String, core.dynamic>,
  );
}