Using the Schema Registry REST API

Manage schemas directly through the Schema Registry REST API to list schemas, register schema versions, check compatibility, and perform other schema operations.

The Schema Registry REST API gives you direct access to the schemas stored in Schema Registry. Use the REST API when you need to run schema operations from scripts or custom tooling, or when you need to inspect or manage schemas without access to the UI.

To access the API and manage schemas, you get the Schema Registry URL and client credentials from Anywhere Cloud Console and exchange the credentials for a bearer token using the OAuth token endpoint. You obtain the CA certificates from the Kafka client configuration bundle that Cloudera Surveyor provides on the Client Configurations tab.

  • You deployed and have access to an instance of Cloudera Streams Messaging, if not see Deploying Cloudera Streams Messaging.

  • You have configured Apache Ranger policies for Schema Registry. See Configuring Ranger authorization for policy setup details.

  • Perform the credential provisioning steps in this task while logged in to Anywhere Cloud Console as a user who has the Ranger policies required for the API calls you want to perform. The credentials you create inherit that user's access.

    This task walks you through some basic schema management operations with example API calls. If you are unsure which Schema Registry Ranger policies you need, log in as a user who is added to a policy that grants full access to Schema Registry.

  • You must have access to a Bash-compatible shell environment with curl and jq.

  1. Get the Schema Registry URL from Anywhere Cloud Console.
    1. In Anywhere Cloud Console, go to Admin Center > Apps > Deployed Engines.
    2. Find and click the entry for your Schema Registry instance.
    3. In the Endpoints table, get the URL from the landingPage row.

      You can copy the URL with the option. The URL includes the /api/v1 suffix.

    4. Assign the URL you copied to an environment variable.
      export SR_URL=https://schema-registry.my-csm.my-awc.cloudera.com/api/v1
  2. Gather the values required for credential provisioning.
    1. Log in to Anywhere Cloud Console.
    2. Look up and record your domain from your Anywhere Cloud Console console URL.
      Your domain is the portion of the URL that comes after console.. For example, if your console URL is https://console.my-awc.cloudera.com, your domain is my-awc.cloudera.com.
    3. Obtain and record the hadoop-jwt session cookie from your browser's developer tools.

      To do this, open browser developer tools and navigate to the Cookies section. Find the hadoop-jwt cookie and record its value.

      To open browser developer tools:

      • Chrome: Press F12 and go to Application > Cookies.
      • Firefox: Press F12 and go to Storage > Cookies.
      • Safari: Press Cmd+Option+I and go to Storage > Cookies.
    4. Open your local terminal and set your domain and hadoop-jwt session cookie as environment variables.

      The following command prompts you to enter each value. The cookie value is not displayed as you type.

      printf "Domain: " && read -r DOMAIN; \
        printf "Hadoop JWT cookie: " && read -rs HADOOP_JWT && echo; \
        export DOMAIN HADOOP_JWT
  3. Obtain client credentials.

    Client credentials are used by applications to authenticate directly with the OAuth server. You can request client credentials through a provisioning endpoint using your session cookie.

    1. Call the credential provisioning endpoint and save the response to a file.
      curl -sk \
        -H "Cookie: hadoop-jwt=${HADOOP_JWT}" \
        -H "Content-Type: application/json" \
        -X POST "https://console.${DOMAIN}/api/v1/auth/access-keys/credentials" \
        -d '{"description": "my automation keys"}' > credentials.json
    2. Record the client_id and client_secret values from credentials.json.

      You need these values in a later step. The response in credentials.json resembles the following example:

      {
        "client_id": "123e4567-e89b-12d3-a456-426614174000",
        "client_secret": "dGhpcy1pcy1hLXNhbXBsZS1zZWNyZXQtZm9yLWRvY3M=",
        "principal": "admin",
        "issued_at": "2026-04-13T22:24:40.330429188Z"
      }

      The client_id and client_secret fields are your client credentials. The principal field is the user principal those credentials are bound to. It matches the user you were logged in as in Anywhere Cloud Console when you obtained the hadoop-jwt session cookie used to call the provisioning endpoint. When your client connects, Apache Ranger authorizes it as this principal. The example shows admin; in your environment, the value is your Anywhere Cloud Console login username. The issued_at field is informational only.

    3. Optional: Save the client credentials from credentials.json to a password manager or another secure location for future use.
      Client credentials are long-lived and can be reused for other clients or programmatic API calls.
  4. Access Cloudera Surveyor.
    1. In Anywhere Cloud Console, go to Streams Messaging
    2. Find and click the entry for your Cloudera Surveyor instance.
  5. Download the client configuration bundle from Cloudera Surveyor.
    1. In Cloudera Surveyor, go to Clusters and select your Kafka cluster.
    2. Go to the Client Configurations tab.
    3. Click Download All.
    4. Extract the archive to a working directory and keep all files in the same directory.
      Some paths in the configuration files are relative, so all files must remain in the same directory.
  6. Exchange your client credentials for a bearer token.
    1. Set your client credentials as environment variables.

      Use the client_id and client_secret values that you recorded from credentials.json. The following command prompts you to enter each value. The client secret is not displayed as you type.

      printf "Client ID: " && read -r CLIENT_ID; \
        printf "Client secret: " && read -rs CLIENT_SECRET && echo; \
        export CLIENT_ID CLIENT_SECRET
    2. Request a bearer token from the OAuth token endpoint and store it in an environment variable.

      Run the following command from the directory where you extracted the client configuration bundle. The command stores the token in the ACCESS_TOKEN variable and does not print it.

      ACCESS_TOKEN=$(curl -sS \
        -u "${CLIENT_ID}:${CLIENT_SECRET}" \
        -X POST "https://console.${DOMAIN}/api/v1/auth/access-keys/token" \
        -d "grant_type=client_credentials" \
        --cacert ca-bundle.crt | jq -r '.access_token')
  7. Perform basic schema management operations with the Schema Registry REST API.

    With SR_URL, ACCESS_TOKEN, and ca-bundle.crt from earlier steps, complete the following substeps in order. They cover common schema management operations. You will create and evolve an example schema named my-schema.

    1. List existing schemas.
      curl -sS -X GET "${SR_URL}/schemaregistry/schemas" \
        -H "Authorization: Bearer ${ACCESS_TOKEN}" \
        --cacert ca-bundle.crt | jq

      The response is a JSON object with an entities array that lists the schemas you are authorized to view. On a fresh registry, the response is {"entities":[]}.

    2. Create the schema entity for my-schema.
      curl -sS -X POST "${SR_URL}/schemaregistry/schemas" \
        -H "Content-Type: application/json" \
        -H "Authorization: Bearer ${ACCESS_TOKEN}" \
        --cacert ca-bundle.crt \
        -d '{"name":"my-schema","type":"avro","schemaGroup":"kafka","compatibility":"BACKWARD","evolve":true,"description":"Example schema"}'

      The response is a numeric schema ID. This step creates schema metadata only. No Avro text is stored yet.

    3. Register the first Avro schema version for my-schema.
      curl -sS -X POST "${SR_URL}/schemaregistry/schemas/my-schema/versions" \
        -H "Content-Type: application/json" \
        -H "Authorization: Bearer ${ACCESS_TOKEN}" \
        --cacert ca-bundle.crt \
        -d '{"schemaText":"{\"type\":\"record\",\"name\":\"MyRecord\",\"fields\":[{\"name\":\"id\",\"type\":\"int\"}]}","description":"Version 1"}'

      The response is version number 1.

    4. List schemas to confirm my-schema was created.
      curl -sS -X GET "${SR_URL}/schemaregistry/schemas" \
        -H "Authorization: Bearer ${ACCESS_TOKEN}" \
        --cacert ca-bundle.crt | jq

      The entities array now contains an entry with "name":"my-schema".

    5. Get the registered version 1 schema.
      curl -sS -X GET "${SR_URL}/schemaregistry/schemas/my-schema/versions/1" \
        -H "Authorization: Bearer ${ACCESS_TOKEN}" \
        --cacert ca-bundle.crt | jq

      The response is a JSON object with schemaText and "version":1.

    6. Check whether an evolved schema is compatible before registering it.
      curl -sS -X POST "${SR_URL}/schemaregistry/schemas/my-schema/compatibility" \
        -H "Content-Type: application/json" \
        -H "Authorization: Bearer ${ACCESS_TOKEN}" \
        --cacert ca-bundle.crt \
        -d '{"type":"record","name":"MyRecord","fields":[{"name":"id","type":"int"},{"name":"label","type":["null","string"],"default":null}]}' | jq

      With BACKWARD compatibility, adding an optional field returns {"compatible":true,...}.

    7. Register the backward-compatible version 2 for my-schema.
      curl -sS -X POST "${SR_URL}/schemaregistry/schemas/my-schema/versions" \
        -H "Content-Type: application/json" \
        -H "Authorization: Bearer ${ACCESS_TOKEN}" \
        --cacert ca-bundle.crt \
        -d '{"schemaText":"{\"type\":\"record\",\"name\":\"MyRecord\",\"fields\":[{\"name\":\"id\",\"type\":\"int\"},{\"name\":\"label\",\"type\":[\"null\",\"string\"],\"default\":null}]}","description":"Version 2"}'

      The response is version number 2.

    8. Get the latest registered version of my-schema.
      curl -sS -X GET "${SR_URL}/schemaregistry/schemas/my-schema/versions/latest" \
        -H "Authorization: Bearer ${ACCESS_TOKEN}" \
        --cacert ca-bundle.crt | jq

      The response shows "version":2 and the evolved schema text.

You accessed Schema Registry through its REST API and performed common schema management operations: you created a schema entity, registered schema versions, checked compatibility before evolving the schema, and retrieved versions. You can now use the same authentication flow and CA certificates to run any Schema Registry REST API operation.

  • For the full endpoint catalog, see the Schema Registry REST API reference.

  • If your bearer token expires, obtain a new one by doing Step 6.b.