Basic Auth

A guide on how to use Basic Auth for authenticating our REST API.

Overview

Basic Auth is supported in most request libraries and is often as simple as adding a username- and password parameter. To get you up and running quickly, we present a few language-specific methods by fetching a list of projects available from the REST API using a Service Account for access control.

Prerequisites

  • Service Account Credentials A Service Account must be created with a membership in the target project. Any role will suffice.

Code Sample

Add the following environment variables as they will be used to authenticate the API. Replace the values of the form <VARIABLE> with your own details.

export DT_SERVICE_ACCOUNT_KEY_ID=<YOUR_SERVICE_ACCOUNT_KEY_ID>
export DT_SERVICE_ACCOUNT_SECRET=<YOUR_SERVICE_ACCOUNT_SECRET>

Create and enter a new directory that will contain the example project.

Install the necessary dependencies.

requests==2.31.0

Create a file main.py with the following content.

import os
import requests

if __name__ == '__main__':
    projects = requests.get(
        url='https://api.d21s.com/v2/projects',
        auth=(
            os.environ.get('DT_SERVICE_ACCOUNT_KEY_ID'),
            os.environ.get('DT_SERVICE_ACCOUNT_SECRET'),
        )
    )

    print(projects.json())

Running the file should list all projects available to the Service Account.

While this example sends a GET request to the API that lists all available projects, the request URL can be replaced with any call in our REST API Reference.

Last updated