update method

Future<Product> update(
  1. Product request,
  2. String merchantId,
  3. String productId, {
  4. String? updateMask,
  5. String? $fields,
})

Updates an existing product in your Merchant Center account.

Only updates attributes provided in the request.

request - The metadata request object.

Request parameters:

merchantId - The ID of the account that contains the product. This account cannot be a multi-client account.

productId - The REST ID of the product for which to update.

updateMask - The comma-separated list of product attributes to be updated. Example: "title,salePrice". Attributes specified in the update mask without a value specified in the body will be deleted from the product. You must specify the update mask to delete attributes. Only top-level product attributes can be updated. If not defined, product attributes with set values will be updated and other attributes will stay unchanged.

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

Completes with a Product.

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<Product> update(
  Product request,
  core.String merchantId,
  core.String productId, {
  core.String? updateMask,
  core.String? $fields,
}) async {
  final body_ = convert.json.encode(request);
  final queryParams_ = <core.String, core.List<core.String>>{
    if (updateMask != null) 'updateMask': [updateMask],
    if ($fields != null) 'fields': [$fields],
  };

  final url_ = commons.escapeVariable('$merchantId') +
      '/products/' +
      commons.escapeVariable('$productId');

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