create method

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

Creates a new API key.

NOTE: Key is a global resource; hence the only supported value for location is global.

request - The metadata request object.

Request parameters:

parent - Required. The project in which the API key is created. Value must have pattern ^projects/\[^/\]+/locations/\[^/\]+$.

keyId - User specified key id (optional). If specified, it will become the final component of the key resource name. The id must be unique within the project, must conform with RFC-1034, is restricted to lower-cased letters, and has a maximum length of 63 characters. In another word, the id must match the regular expression: [a-z]([a-z0-9-]{0,61}[a-z0-9])?. The id must NOT be a UUID-like string.

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

Completes with a Operation.

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

  final url_ = 'v2/' + core.Uri.encodeFull('$parent') + '/keys';

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