create method

Future<Product> create(
  1. Product request,
  2. String parent, {
  3. String? productId,
  4. String? $fields,
})

Creates and returns a new product resource.

Possible errors: * Returns INVALID_ARGUMENT if display_name is missing or longer than 4096 characters. * Returns INVALID_ARGUMENT if description is longer than 4096 characters. * Returns INVALID_ARGUMENT if product_category is missing or invalid.

request - The metadata request object.

Request parameters:

parent - Required. The project in which the Product should be created. Format is projects/PROJECT_ID/locations/LOC_ID. Value must have pattern ^projects/\[^/\]+/locations/\[^/\]+$.

productId - A user-supplied resource id for this Product. If set, the server will attempt to use this value as the resource id. If it is already in use, an error is returned with code ALREADY_EXISTS. Must be at most 128 characters long. It cannot contain the character /.

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

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

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