List subjects

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.

The Managed Kafka Schema Registry Viewer (roles/managedkafka.schemaRegistryViewer) role contains the necessary permission to list subjects within a schema registry or context. Higher-level roles like Managed Kafka Schema Registry Editor (roles/managedkafka.schemaRegistryEditor) and Managed Kafka Schema Registry Admin (roles/managedkafka.schemaRegistryAdmin) also include this permission.

For more information about predefined roles, see the Managed Service for Apache Kafka predefined roles.

List your subjects

To list all subjects in a specific schema registry or context within your project, follow these steps.

Console

  1. In the Google Cloud console, go to the Schema registries page.

    Go to schema registry

    A list of schema registries in your project is displayed.

  2. Click the name of the schema registry whose details you want to view.

    The Schema registry details page opens. The information displayed on this page is explained in the Schema registry page details section.

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/v1/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/v1/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.

Apache Kafka® is a registered trademark of The Apache Software Foundation or its affiliates in the United States and/or other countries.