create method
- CreateSubscriptionPayload request,
- String parent, {
- String? subscriptionId,
- String? $fields,
Creates a subscription for a specific user to a specific subscriber.
This method requires the subscriber to have a SubscriptionCreatePolicy
set to MANUAL for the given data types.
request - The metadata request object.
Request parameters:
parent - Required. The parent subscriber. Format:
projects/{project}/subscribers/{subscriber} The {subscriber} ID is
user-settable (4-36 characters, matching
/[a-z]([a-z0-9-]{2,34}[a-z0-9])/) if provided during creation, or
system-generated otherwise.
Value must have pattern ^projects/\[^/\]+/subscribers/\[^/\]+$.
subscriptionId - Optional. The {subscription_id} is user-settable (4-36
chars, matching /[a-z]([a-z0-9-]{2,34}[a-z0-9])/) or
system-generated otherwise. If provided, the ID must be unique within the
parent subscriber.
$fields - Selector specifying which fields to include in a partial
response.
Completes with a Subscription.
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<Subscription> create(
CreateSubscriptionPayload request,
core.String parent, {
core.String? subscriptionId,
core.String? $fields,
}) async {
final body_ = convert.json.encode(request);
final queryParams_ = <core.String, core.List<core.String>>{
'subscriptionId': ?subscriptionId == null ? null : [subscriptionId],
'fields': ?$fields == null ? null : [$fields],
};
final url_ = 'v4/' + core.Uri.encodeFull('$parent') + '/subscriptions';
final response_ = await _requester.request(
url_,
'POST',
body: body_,
queryParams: queryParams_,
);
return Subscription.fromJson(
response_ as core.Map<core.String, core.dynamic>,
);
}