BigID API/API Tutorial

From BigID Developer Portal
< BigID API
Revision as of 16:12, 3 March 2022 by Bigid (talk | contribs)

In this article, you'll learn:

  • How to get a BigID token using a REST API call
  • Where to find the BigID API documentation
  • How to use a BigID token to receive data from BigID


scenarioAs part of your data governance tasks, you need to get a list of data sources so you can be sure that your external data catalog has the right information. You've thought about doing this through the user interface, but you expect that you'll review this list around every three months. With that in mind, the BigID API seems like the best option. Discover and test the API calls you'll need to perform this task.

The BigID API allows you to perform all the actions you're used to performing via the BigID user interface programmatically. This is perfect for scenarios like the one in this exercise where you need to perform the same operation on a scheduled basis. In order to communicate with BigID over its API, we first need to authenticate ourselves.

Authenticating with BigID

There are two ways to authenticate ourselves to BigID:

  • User Token - A user token (generated from Administration -> Access Management by a System Administrator) allows you to access BigID by exchanging a user token for a session token at the /refresh endpoint. This means you don't have to store your username and password within an application, but user tokens are only valid for a maximum of 999 days.
  • Username and Password - You provide a username and password to the /sessions endpoint and BigID will return a session token that is valid for any other API endpoints (given that user has permissions to access them) for 24 hours. This will only work for on-prem versions of BigID.

Select which version of BigID you're using to get the proper instructions:

I'm using BigID On Premise

In this tutorial, we're going to authenticate with BigID using Username/Password auth and retrieve a list of data sources.

Getting a session token

Below you'll see the POST request we'll use to authenticate. The body of the request contains our username and password and we're directing the request to the sessions endpoint in our BigID Sandbox system. Press Send to get a session token.

In the response, there's a bunch of information about the logged in user. For our purposes, we just care about line 4, the auth_token. This token is what we'll use the authenticate with the other BigID APIs. We've placed a sample below with the auth token highlighted. Copy the auth token from the request you placed above. We'll need it in just a second.

{
    "success": true,
    "message": "Enjoy your token!",
    "auth_token": "eyJhbGciOiJ<don't copy me! I'm just an example!>...",
    "username": "bigid",
    "firstName": "BigID Admin",
    "permissions": [
        "admin",
        "permission.tasks.edit",
        "permission.tasks.read_task_list",
    ...

Calling an API

Now that you have a session token we can directly call BigID APIs. Documentation for these APIs is available at https://www.docs.bigid.com/bigid/reference/api-getting-started . Since we're just trying to perform a simple task, we don't need the docs here, just to know that GET /ds-connections is the endpoint to retrieve a list of data source connections.

Add a new header named "Authorization" and paste the session token you got in the previous request to authenticate yourself.

In that API call, we can see a list of data sources and all the information for each data source.

{
    "status": "success",
    "statusCode": 200,
    "data": {
        "ds_connections": [
            "<data source info here>"
         ]
    }
}

We now know the API calls we need and can use our programming language of choice to prepare our report. Below are some samples.

import fetch from 'node-fetch';

let credentials = { username: "bigid", password: "learner" };
let env = "https://sandbox.mybigid.com/";

async function getDataSources(credentials, env) {
    // Request API Key using user/pass authentication
    const sessionRequest = fetch(env + 'api/v1/sessions', {
        method: 'POST',
        body: JSON.stringify(credentials),
        headers: { 'Content-Type': 'application/json' }
    });
    const sessionData = await request.json();

    const dsRequest = fetch(env + 'api/v1/ds-connections', {
        method: 'GET',
        headers: {
            'Content-Type': 'application/json',
            'Authorization': sessionData.auth_token
        }
    });
    return await dsRequest.json();
}
let credentials = { username: "bigid", password: "learner" };
let env = "https://sandbox.mybigid.com/";

async function getDataSources(credentials, env) {
    // Request API Key using user/pass authentication
    const sessionRequest = window.fetch(env + 'api/v1/sessions', {
        method: 'POST',
        body: JSON.stringify(credentials),
        headers: { 'Content-Type': 'application/json' }
    });
    const sessionData = await request.json();

    const dsRequest = window.fetch(env + 'api/v1/ds-connections', {
        method: 'GET',
        headers: {
            'Content-Type': 'application/json',
            'Authorization': sessionData.auth_token
        }
    });
    return await dsRequest.json();
}
import requests

credentials = {'username':'bigid', 'password':'learner'}
env = 'https://sandbox.mybigid.com/'

def getDataSources(credentials, env):
    sessionRequest = requests.post(env+'api/v1/sessions', data = credentials)
    sessionData = sessionRequest.json()
    dsRequest = requests.get(env+'api/v1/ds-connections', headers = {'Authorization':sessionData.get('auth_token')})
    return dsRequest.json()