create method

Future<CapacityCommitment> create(
  1. CapacityCommitment request,
  2. String parent, {
  3. String? capacityCommitmentId,
  4. bool? enforceSingleAdminProjectPerOrg,
  5. String? $fields,
})

Creates a new capacity commitment resource.

request - The metadata request object.

Request parameters:

parent - Required. Resource name of the parent reservation. E.g., projects/myproject/locations/US Value must have pattern ^projects/\[^/\]+/locations/\[^/\]+$.

capacityCommitmentId - The optional capacity commitment ID. Capacity commitment name will be generated automatically if this field is empty. This field must only contain lower case alphanumeric characters or dashes. The first and last character cannot be a dash. Max length is 64 characters. NOTE: this ID won't be kept if the capacity commitment is split or merged.

enforceSingleAdminProjectPerOrg - If true, fail the request if another project in the organization has a capacity commitment.

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

Completes with a CapacityCommitment.

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

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

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