HomeGuidesRecipesAPI ReferencePython SDK
Alation Help Center
API Reference

Queriers APIs

Data Source Object Queriers (Find "Top DB Accounts" of a Schema, Table, or Column)

Description

This API allows admin users to get a list of database accounts that have queried a subject.

Note:

  1. To enable this API, set the flag alation.feature_flags.enable_querying_db_accounts_api to True.
  2. This API is available in version 4.17 and later.

URL

GET /integration/v1/**<otype>**/**<id>**/db_account/?**<params>**

Replace <otype> with any one of the following:

schema

table

attribute

Replace <id> with the unique identifier of a subject inside Alation catalog.

Replace <params> with your list of parameters. Multiple parameters can be combined as PARAM1&PARAM2

URL Parameters

NameRequiredDescription
limitNoLimit the number of database accounts returned.
Example: /integration/v1/table/1/db_account/?limit=10
Note: The default value for this parameter is 25.
skipNoSkip a number of records and return the rest. limit and skip are used for pagination of the results.
Example: /integration/v1/table/1/db_account/?skip=10

Headers

HTTP HeaderValue
TOKEN<your_token>

Replace <your_token> with API Token which can be obtained from getToken API call (Get API Token).

Success Response

Content-Type: application/json

Status: 200 OK

Body

[
    {
        "db_account": "user_alation_dba",
        "num_executions": 40,
        "ts_last_query": "2017-12-08T16:45:38Z"
    },
    {
        "db_account": "user_alation_dba2",
        "num_executions": 100,
        "ts_last_query": "2017-12-09T13:45:38Z"
    }
]
NameDescription
db_accountName of the database account.
num_executionsNumber of times queries have been executed on the subject by the database account.
NOTE: This value depends on QLI and might not always represent the correct number of executions.
ts_last_queryTimestamp of the latest query executed by the database account.
NOTE: The value for this parameter has the timezone offset included.

Note: Upon querying the objects through Alation's Compose query tool, the Query Log Ingestion (QLI) job needs to be run for the database accounts to appear in the API response.

Error Response

Invalid Token

Status: 403 FORBIDDEN

Body

{
   "detail": "Authentication failed"
}

Missing Token Header

Status: 403 FORBIDDEN

Body

{
    "detail": "Authentication credentials were not provided."
}

Non-admin user access

Status: 403 FORBIDDEN

Body

{
    "detail": "Permission denied"
}

Code Samples

cURL

#!/bin/bash
# This is an example token. Please replace this with your token.
API_TOKEN="2abcd-4c04-4c21-8692-eda27a877f90"

BASE_URL="https://alation.yourcompany.com/integration/v1"
OTYPE="schema"
ID=1

# Get all database accounts that have queried a schema with unique identifier as 1
curl -H "TOKEN: ${API_TOKEN}" "${BASE_URL}/${OTYPE}/${ID}/db_account/"

Python

import requests
import json

# This is an example token. Please replace this with your token.
headers = {'Token': '2abcd-4c04-4c21-8692-eda27a877f90'}
otype = 'table'
id = 1

# Get all database accounts that have queried a table with unique identifier as 1
response = requests.get('https://alation.yourcompany.com/integration/v1/%s/%s/db_account/' % (otype, str(id)), headers=headers)
users = json.loads(response.text)
for user in users:
    print "DB Account: %s, ts_last_query: %s" % (user['db_account'], user['ts_last_query'])