You can list the subjects within a specific schema registry or context in your project.
This document shows you how to list subjects using the Google Cloud console or the Managed Kafka API.
Required roles and permissions
    
      To get the permissions that
      you need to list subjects,
    
      ask your administrator to grant you the
    
  
  
    
      Managed Kafka Schema Registry Viewer  (roles/managedkafka.schemaRegistryViewer)
     IAM role on your schema registry or context.
  
  
  
  
  For more information about granting roles, see Manage access to projects, folders, and organizations.
  
  
This predefined role contains the permissions required to list subjects. To see the exact permissions that are required, expand the Required permissions section:
Required permissions
The following permissions are required to list subjects:
- 
                Grant the following permission on the parent schema registry or context:
                  
managedkafka.googleapis.com/subjects.list 
You might also be able to get these permissions with custom roles or other predefined roles.
For more information about predefined roles, see the Managed Service for Apache Kafka predefined roles.
List the subjects in a schema registry
To list all subjects in a specific schema registry or context within your project, follow these steps.
Console
In the Google Cloud console, go to the Schema registries page.
Click the name of the schema registry whose details you want to view.
In the Schema registry details page, the subjects are listed under Subjects in this schema registry.
Optional: To filter which subjects are displayed, click Filter. You can filter by the following properties:
- Name
 - Context
 
REST
The request must be authenticated with an access token in the Authorization
header. To obtain an access token for the current Application Default
Credentials:
gcloud auth application-default print-access-token.
To list subjects directly under a schema registry, make a GET request to the
specific URI using the
projects.locations.schemaRegistries.schemas.subjects.list
method for the default context.
GET https://managedkafka.googleapis.com/v1main/projects/PROJECT_ID/locations/LOCATION/schemaRegistries/REGISTRY_ID/subjects
Authorization: Bearer $(gcloud auth application-default print-access-token)
To list subjects under a context within a schema registry, make a GET
request to the specific URI using the
projects.locations.schemaRegistries.contexts.schemas.subjects.list
method:
GET https://managedkafka.googleapis.com/v1main/projects/PROJECT_ID/locations/LOCATION/schemaRegistries/REGISTRY_ID/contexts/CONTEXT_ID/subjects?subjectPrefix=SUBJECT_PREFIX
Authorization: Bearer $(gcloud auth application-default print-access-token)
Replace the following:
PROJECT_ID (required): your Google Cloud project ID.
LOCATION (required): the Google Cloud region where the schema registry is located.
REGISTRY_ID (required): the ID of your schema registry.
CONTEXT_ID (optional): the ID of the context (if listing subjects within a context).
SUBJECT_PREFIX (optional): the context to filter the subjects by, in the format of
:.{context}:. If unset, all subjects in the registry are returned. If set to an empty string, lists subjects in the default context.
If the request is successful, the API returns a 200 OK status code. The
response body contains a JSON array of subject names.
The following is a sample successful response of subjects in a JSON array for the default context:
[
  "orders-topic-key",
  "orders-topic-value",
  "user-profile-event"
]
Subjects in non-default contexts are returned in the format
:.context:subject.
For more information, see the
projects.locations.schemaRegistries.contexts.schemas.subjects/list
method documentation.
What's next
- Learn more about schema registry
 - List subject versions
 - Register a new schema version
 - Delete a subject