Quick Start

Prerequisites

To use the API, your organization should already have a Density account set up. You need an Owner Role to access Density API. Contact support@density.io to request a Density Owner role to get an API token.

Create an API Token

Short-lived token

Short-lived tokens are recommended for machine-to-machine API interactions. You must create a credential which consists of a client ID and client secret, which you send to an authorization endpoint to receive a short-lived token for use in other API calls. Credentials can be created in Atlas Developer Settings as follows:

  1. In Atlas , click the top right menu with your organization's name. A pop-down menu with the item "Your Account" appears.
  2. In the pop-down menu, click Your Account . The Settings page appears.
  3. At the bottom of the left hand sidebar, click Developer . Developer Settings appears. Note: only 'Owner' Density accounts are able to see developer tools. See Prerequisites , above.
  4. Click the Create Credentials button. This shows a dialog box.
  5. In the dialog box, give the Credential a name and click Save. A new Credential appears in the list below the Create Credential Button.
  6. Use the Client Id and Client Secret values in an auth request . The short lived access_token is returned as a property in the JSON response.

Make a Call to the API

All API endpoints are authenticated using your API token, obtained through the steps above. Tokens are strings which typically begin with the letters "eyJ"

Your token must be included in the Authorization HTTP header, prefixed by the string literal "Bearer" with a single space separating the two strings. Any API call made without the proper Authorization header will return a 403 error.

Example

The following example uses Bash and curl:

Copy
Copied
    CLIENT_ID=__obtain_from_atlas__
    CLIENT_SECRET=__obtain_from_atlas__
    ACCESS_TOKEN=$(curl -s -X POST https://api.density.io/v3/oauth/token \
      -H 'Content-Type: application/json' \
        -d @<(cat <<EOF
    {
        "client_id": "$CLIENT_ID",
        "client_secret": "$CLIENT_SECRET",
        "grant_type": "client_credentials"
      }
    EOF
    ) | grep -o '"access_token":"[^"]*"' | cut -d':' -f2 | tr -d '"')

    curl -s -X GET \
      https://api.density.io/v3/hello-world \
      -H 'Content-Type: application/json' \
      -H "Authorization: Bearer $ACCESS_TOKEN"