List topics

This document describes how to list a Pub/Sub topic. To list atopic you can use the Google Cloud console, the gcloud CLI, the client library,or the Pub/Sub API.

Before you begin

Required roles and permissions

To get the permissions that you need to list topics and manage them, ask your administrator to grant you the Pub/Sub Editor(roles/pubsub.editor) IAM role on your topic or project. For more information about granting roles, seeManage access to projects, folders, and organizations.

This predefined role contains the permissions required to list topics and manage them. To see the exact permissions that are required, expand theRequired permissions section:

Required permissions

The following permissions are required to list topics and manage them:

  • Create a topic:pubsub.topics.create
  • Delete a topic:pubsub.topics.delete
  • Detach a subscription from a topic:pubsub.topics.detachSubscription
  • Get a topic:pubsub.topics.get
  • List a topic:pubsub.topics.list
  • Publish to a topic:pubsub.topics.publish
  • Update a topic:pubsub.topics.update
  • Get the IAM policy for a topic:pubsub.topics.getIamPolicy
  • Configure theIAM policy for a topic:pubsub.topics.setIamPolicy

You might also be able to get these permissions withcustom roles or otherpredefined roles.

You can configure access control at the project level and at the individualresource level. You can create a subscription in one project andattach it to a topic located in a different project.Ensure that you have the required permissions foreach project.

List a topic

Console

  • In the Google Cloud console, go to the Pub/SubTopics page.

  • Go to Topics

    TheTopics page lists all the available topics.

    By default, the console returns 50 topics. You can increase this value toreturn a maximum of 200 topics by using theRows per page drop down toggle.This toggle only appears in the console if you have more than 20 topics in a project.

gcloud

  1. In the Google Cloud console, activate Cloud Shell.

    Activate Cloud Shell

    At the bottom of the Google Cloud console, aCloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.

  2. To list topics, use thegcloud pubsub topics list command:

    gcloudpubsubtopicslist

By default, a maximum of 100 results are returned per query.You can specify an alternative value of up to 1,000 using the page size parameter.For example, using the Google Cloud CLI, specify--page-size=1000.

REST

To list topics, use theprojects.topics.listmethod:

Request:

The request must be authenticated with an access token in theAuthorization header. To obtain an access token for the current Application Default Credentials:gcloud auth application-default print-access-token.

GET https://pubsub.googleapis.com/v1/projects/PROJECT_ID/topicsAuthorization: BearerACCESS_TOKEN

Where:

  • PROJECT_ID is your project ID.
  • Response:

    {"topics": [  {    "name": "projects/PROJECT_ID/topics/mytopic1",    ...  },  {    "name": "projects/PROJECT_ID/topics/mytopic2",    ...  }]}

    C++

    Before trying this sample, follow the C++ setup instructions inQuickstart: Using Client Libraries. For more information, see thePub/Sub C++ API reference documentation.

    namespacepubsub_admin=::google::cloud::pubsub_admin;[](pubsub_admin::TopicAdminClientclient,std::stringconst&project_id){intcount=0;for(auto&topic:client.ListTopics("projects/"+project_id)){if(!topic)throwstd::move(topic).status();std::cout <<"Topic Name: " <<topic->name() <<"\n";++count;}if(count==0){std::cout <<"No topics found in project " <<project_id <<"\n";}}

    C#

    Before trying this sample, follow the C# setup instructions inQuickstart: Using Client Libraries. For more information, see thePub/Sub C# API reference documentation.

    usingGoogle.Api.Gax.ResourceNames;usingGoogle.Cloud.PubSub.V1;usingSystem.Collections.Generic;publicclassListProjectTopicsSample{publicIEnumerable<Topic>ListProjectTopics(stringprojectId){PublisherServiceApiClientpublisher=PublisherServiceApiClient.Create();ProjectNameprojectName=ProjectName.FromProject(projectId);IEnumerable<Topic>topics=publisher.ListTopics(projectName);returntopics;}}

    Go

    The following sample uses the major version of the Go Pub/Sub client library (v2). If you are still using the v1 library, seethe migration guide to v2.To see a list of v1 code samples, seethe deprecated code samples.

    Before trying this sample, follow the Go setup instructions inQuickstart: Using Client Libraries.For more information, see thePub/Sub Go API reference documentation.

    import("context""fmt""io""cloud.google.com/go/pubsub/v2""cloud.google.com/go/pubsub/v2/apiv1/pubsubpb""google.golang.org/api/iterator")funclistTopics(wio.Writer,projectIDstring)error{// projectID := "my-project-id"ctx:=context.Background()client,err:=pubsub.NewClient(ctx,projectID)iferr!=nil{returnfmt.Errorf("pubsub.NewClient: %w",err)}deferclient.Close()req:=&pubsubpb.ListTopicsRequest{Project:fmt.Sprintf("projects/%s",projectID),}it:=client.TopicAdminClient.ListTopics(ctx,req)for{topic,err:=it.Next()iferr==iterator.Done{break}iferr!=nil{returnfmt.Errorf("error listing topics: %w",err)}fmt.Fprintf(w,"got topic: %s\n",topic)}returnnil}

    Java

    Before trying this sample, follow the Java setup instructions inQuickstart: Using Client Libraries. For more information, see thePub/Sub Java API reference documentation.

    importcom.google.cloud.pubsub.v1.TopicAdminClient;importcom.google.pubsub.v1.ProjectName;importcom.google.pubsub.v1.Topic;importjava.io.IOException;publicclassListTopicsExample{publicstaticvoidmain(String...args)throwsException{// TODO(developer): Replace these variables before running the sample.StringprojectId="your-project-id";listTopicsExample(projectId);}publicstaticvoidlistTopicsExample(StringprojectId)throwsIOException{try(TopicAdminClienttopicAdminClient=TopicAdminClient.create()){ProjectNameprojectName=ProjectName.of(projectId);for(Topictopic:topicAdminClient.listTopics(projectName).iterateAll()){System.out.println(topic.getName());}System.out.println("Listed all topics.");}}}

    Node.js

    Before trying this sample, follow the Node.js setup instructions inQuickstart: Using Client Libraries. For more information, see thePub/Sub Node.js API reference documentation.

    //ImportstheGoogleCloudclientlibraryconst{PubSub}=require('@google-cloud/pubsub');//Createsaclient;cachethisforfurtheruseconstpubSubClient=newPubSub();asyncfunctionlistAllTopics(){//Listsalltopicsinthecurrentprojectconst[topics]=awaitpubSubClient.getTopics();console.log('Topics:');topics.forEach(topic=>console.log(topic.name));}

    Node.ts

    Before trying this sample, follow the Node.js setup instructions inQuickstart: Using Client Libraries. For more information, see thePub/Sub Node.js API reference documentation.

    //ImportstheGoogleCloudclientlibraryimport{PubSub,Topic}from'@google-cloud/pubsub';//Createsaclient;cachethisforfurtheruseconstpubSubClient=newPubSub();asyncfunctionlistAllTopics(){//Listsalltopicsinthecurrentprojectconst[topics]=awaitpubSubClient.getTopics();console.log('Topics:');topics.forEach((topic:Topic)=>console.log(topic.name));}

    PHP

    Before trying this sample, follow the PHP setup instructions inQuickstart: Using Client Libraries. For more information, see thePub/Sub PHP API reference documentation.

    use Google\Cloud\PubSub\PubSubClient;/** * Lists all Pub/Sub topics. * * @param string $projectId  The Google project ID. */function list_topics($projectId){    $pubsub = new PubSubClient([        'projectId' => $projectId,    ]);    foreach ($pubsub->topics() as $topic) {        printf('Topic: %s' . PHP_EOL, $topic->name());    }}

    Python

    Before trying this sample, follow the Python setup instructions inQuickstart: Using Client Libraries. For more information, see thePub/Sub Python API reference documentation.

    fromgoogle.cloudimportpubsub_v1# TODO(developer)# project_id = "your-project-id"publisher=pubsub_v1.PublisherClient()project_path=f"projects/{project_id}"fortopicinpublisher.list_topics(request={"project":project_path}):print(topic)

    Ruby

    The following sample uses Ruby Pub/Sub client library v3. If you are still using the v2 library, see the migration guide to v3.To see a list of Ruby v2 code samples, seethe deprecated code samples.

    Before trying this sample, follow the Ruby setup instructions inQuickstart: Using Client Libraries.For more information, see thePub/Sub Ruby API reference documentation.

    pubsub=Google::Cloud::PubSub.newtopic_admin=pubsub.topic_admintopics=topic_admin.list_topicsproject:pubsub.project_pathputs"Topics in project:"topics.eachdo|topic|putstopic.nameend

    What's next

    Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

    Last updated 2026-02-19 UTC.