create method

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

Creates a TopicSubscription.

Subscribes an app installation instance (by registration_id, either FID or FCM Token) to a topicSubscription. Returns a TopicSubscription if it is created successfully. If the subscription already exists, returns error of ALREADY_EXISTS.

request - The metadata request object.

Request parameters:

parent - Required. The parent resource where this subscription will be created. Format: projects/{project}/registrations/{registration} The {registration} part can be an FID or an FCM Token. Value must have pattern ^projects/\[^/\]+/registrations/\[^/\]+$.

topicName - Required. The ID to use for the subscription, which is the topic name. This will become the last segment of the TopicSubscription's resource name. Topic names match the pattern of "[a-zA-Z0-9-_.~%]{1,900}".

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

Completes with a TopicSubscription.

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

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

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