Accessing the Cloudera Anywhere Cloud API

Review the methods that you can access the Cloudera Anywhere Cloud API based on your infrastructure setup.

Using the Anywhere Cloud Console

You can access the Cloudera Anywhere Cloud API using the Anywhere Cloud Console. After logging in to the Anywhere Cloud Console, you can select and click on the API Explorer. This will open the API documentation, where you can try out the different endpoints.

Using the REST API references

You can review the available API endpoints by opening the following REST API reference documentation for Cloudera Anywhere Cloud:
  • Anywhere Cloud Console REST API reference
  • Authentication REST API reference
  • Diagnostics REST API reference

Creating tokens for using the API

Create bearer tokens in exchange of your access keys required to use the Cloudera Anywhere Cloud API. The JWT tokens are obtained using the client_id and client_secret, which are bound to your identity.

Access keys let you create a reusable client_id and client_secret pair that are bound to your user identity. You exchange these credentials for short-lived JSON Web Tokens (JWT) bearer tokens. These tokens are used to authenticate Cloudera Anywhere Cloud API calls.

  • Ensure that you know the domain name of your Cloudera Anywhere Cloud cluster, for example, mycluster.example.com.
  • Ensure that you have valid user credentials. Before an external identity provider is configured, use the LDAP credentials that were set during Cloudera Anywhere Cloud installation. After a SAML identity provider is configured, the curl method is not available to retrieve the hadoop-jwt session cookie. Instead of curl, use the browser steps.
  • Ensure that you have installed curl.
  1. Obtain hadoop-jwt session cookie using one of the following methods:
    • Using your browser
        1. Open https://console.[***DOMAIN***]/ in your browser.
        2. Log in with your credentials.
        3. Open browser developer tools to access your cookies.
        4. Copy the value of the hadoop-jwt cookie.
    • Using curl
      DOMAIN="[***DOMAIN***]"
      USERNAME="[***LDAP CREDENTIAL CONFIGURED DURING INSTALLATION***]"
      PASSWORD="[***LDAP CREDENTIAL CONFIGURED DURING INSTALLATION***]"
      
      # Hit the console — it redirects to the SSO login page
      REDIRECT_URL=$(curl -sk "https://console.${DOMAIN}/" -o /dev/null -w '%{redirect_url}')
      
      # Authenticate at the SSO endpoint and save the cookie
      curl -sk -X POST -u "${USERNAME}:${PASSWORD}" -c cookies.txt "${REDIRECT_URL}" -o /dev/null
      
      # Extract the cookie value
      HADOOP_JWT=$(grep hadoop-jwt cookies.txt | awk '{print $NF}')
      echo "${HADOOP_JWT}"
  2. Create an access key by calling the credential provisioning endpoint with your session cookie.
    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 key"}'
    The access key is bound to your authenticated user identity. The secret is returned only once and is not stored server-side.
    1. Save the client_id and client_secret.
  3. Exchange the access key for a bearer token.
    curl -sk \
      -u "${CLIENT_ID}:${CLIENT_SECRET}" \
      -X POST "https://console.${DOMAIN}/api/v0/auth/access-keys/token" \
      -d "grant_type=client_credentials"
    1. Use the client_id and client_secret as the credential.
    2. Save the returned access_token.
  4. Include the bearer token in the Authorization header.
    curl -sk \
      -H "Authorization: Bearer ${ACCESS_TOKEN}" \
      "https://console.${DOMAIN}/api/v0/auth/sso-configurations"