Stay organized with collections
Save and categorize content based on your preferences.
Creates a subscription to a given topic. See the resource name rules. If the
subscription already exists, returns ALREADY_EXISTS. If the
corresponding topic doesn't exist, returns NOT_FOUND. If the name is
not provided in the request, the server will assign a random name for
this subscription on the same project as the topic, conforming to the
resource name format. The
generated name is populated in the returned Subscription object. Note
that for REST API requests, you must specify a name in the request.
Arguments
Parameters
name
string
Required. The name of the subscription. It must have the format "projects/{project}/subscriptions/{subscription}". {subscription} must start with a letter, and contain only letters ([A-Za-z]), numbers ([0-9]), dashes (-), underscores (_), periods (.), tildes (~), plus (+) or percent signs (%). It must be between 3 and 255 characters in length, and it must not start with "goog".
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Method: googleapis.pubsub.v1.projects.subscriptions.create\n\nCreates a subscription to a given topic. See the [resource name rules](https://cloud.google.com/pubsub/docs/admin#resource_names). If the\nsubscription already exists, returns `ALREADY_EXISTS`. If the\ncorresponding topic doesn't exist, returns `NOT_FOUND`. If the name is\nnot provided in the request, the server will assign a random name for\nthis subscription on the same project as the topic, conforming to the\n[resource name format](https://cloud.google.com/pubsub/docs/admin#resource_names). The\ngenerated name is populated in the returned Subscription object. Note\nthat for REST API requests, you must specify a name in the request.\n\nArguments\n---------\n\nRaised exceptions\n-----------------\n\nResponse\n--------\n\nIf successful, the response contains an instance of [`Subscription`](/workflows/docs/reference/googleapis/pubsub/v1/Overview#Subscription).\n\nSubworkflow snippet\n-------------------\n\nSome fields might be optional or required.\nTo identify required fields, refer to the [API documentation](https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/create). \n\n### YAML\n\n```yaml\n- create:\n call: googleapis.pubsub.v1.projects.subscriptions.create\n args:\n name: ...\n body:\n ackDeadlineSeconds: ...\n deadLetterPolicy:\n deadLetterTopic: ...\n maxDeliveryAttempts: ...\n detached: ...\n enableMessageOrdering: ...\n expirationPolicy:\n ttl: ...\n filter: ...\n labels: ...\n messageRetentionDuration: ...\n name: ...\n pushConfig:\n attributes: ...\n oidcToken:\n audience: ...\n serviceAccountEmail: ...\n pushEndpoint: ...\n retainAckedMessages: ...\n retryPolicy:\n maximumBackoff: ...\n minimumBackoff: ...\n topic: ...\n result: createResult\n```\n\n### JSON\n\n```json\n[\n {\n \"create\": {\n \"call\": \"googleapis.pubsub.v1.projects.subscriptions.create\",\n \"args\": {\n \"name\": \"...\",\n \"body\": {\n \"ackDeadlineSeconds\": \"...\",\n \"deadLetterPolicy\": {\n \"deadLetterTopic\": \"...\",\n \"maxDeliveryAttempts\": \"...\"\n },\n \"detached\": \"...\",\n \"enableMessageOrdering\": \"...\",\n \"expirationPolicy\": {\n \"ttl\": \"...\"\n },\n \"filter\": \"...\",\n \"labels\": \"...\",\n \"messageRetentionDuration\": \"...\",\n \"name\": \"...\",\n \"pushConfig\": {\n \"attributes\": \"...\",\n \"oidcToken\": {\n \"audience\": \"...\",\n \"serviceAccountEmail\": \"...\"\n },\n \"pushEndpoint\": \"...\"\n },\n \"retainAckedMessages\": \"...\",\n \"retryPolicy\": {\n \"maximumBackoff\": \"...\",\n \"minimumBackoff\": \"...\"\n },\n \"topic\": \"...\"\n }\n },\n \"result\": \"createResult\"\n }\n }\n]\n```"]]