create method

Future<AlertPolicy> create(
  1. AlertPolicy request,
  2. String name, {
  3. String? $fields,
})

Creates a new alerting policy.Design your application to single-thread API calls that modify the state of alerting policies in a single project.

This includes calls to CreateAlertPolicy, DeleteAlertPolicy and UpdateAlertPolicy.

request - The metadata request object.

Request parameters:

name - Required. The project (https://cloud.google.com/monitoring/api/v3#project_name) in which to create the alerting policy. The format is: projects/[PROJECT_ID_OR_NUMBER] Note that this field names the parent container in which the alerting policy will be written, not the name of the created policy. |name| must be a host project of a Metrics Scope, otherwise INVALID_ARGUMENT error will return. The alerting policy that is returned will have a name that contains a normalized representation of this name as a prefix but adds a suffix of the form /alertPolicies/[ALERT_POLICY_ID], identifying the policy in the container. Value must have pattern ^projects/\[^/\]+$.

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

Completes with a AlertPolicy.

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

  final url_ = 'v3/' + core.Uri.encodeFull('$name') + '/alertPolicies';

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