Your API key can be found and copied in the bottom left user menu:

To query SQL databases or Cube integrations you will also need your integration id. Your integration_id can be found on your integration’s page URL:

Query Database Integrations With SQL

You can query your databases with SQL through the API.

Python

import requests

API_KEY = "YOUR_API_KEY"
db_integration_id = "YOUR_DB_INTEGRATION_ID"
query = "SELECT * FROM TABLE LIMIT 10"

def run_query(sql: str, integration_id: str):
    json={
        "sql": sql,
    }
    if integration_id:
            json['integration_id'] = integration_id
    res = requests.post(
        url="https://api.definite.app/v1/query",
        json=json,
        headers={
            "Authorization": f"Bearer {API_KEY}",
            },
    )
    return res.json()
query_result = run_cube_query(query, db_integration_id)

cURL

curl -X POST "https://api.definite.app/v1/query" \
     -H "Authorization: Bearer YOUR_API_KEY" \
     -H "Content-Type: application/json" \
     -d '{"sql": "YOUR_SQL_QUERY", "integration_id": "YOUR_INTEGRATION_ID"}'

Query Cube Integrations

You can also query Cube through the API by passing in a Cube query in JSON format.

Python

import requests

API_KEY = 'YOUR_API_KEY'
cube_integration_id = 'YOUR_CUBE_INTEGRATION_ID'

query = {
  "dimensions": [],
  "filters": [],
  "measures": [
    "hubspot_deals.win_rate"
  ],
  "timeDimensions": [
    {
      "dimension": "hubspot_deals.close_date",
      "granularity": "month"
    }
  ],
  "order": [],
  "limit": 2000
}


def run_cube_query(query: dict, integration_id: str):
    json={
        "cube_query": query,
    }
    if integration_id:
            json['integration_id'] = integration_id
    res = requests.post(
        url="https://api.definite.app/v1/query",
        json=json,
        headers={
            "Authorization": f"Bearer {API_KEY}",
            },
    )
    return res.json()

res = run_cube_query(query, cube_integration_id)

cURL

curl -X POST https://api.definite.app/v1/query \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "cube_query": {
      "dimensions": [],
      "filters": [],
      "measures": [
        "hubspot_deals.win_rate"
      ],
      "timeDimensions": [
        {
          "dimension": "hubspot_deals.close_date",
          "granularity": "month"
        }
      ],
      "order": [],
      "limit": 2000
    },
    "integration_id": "YOUR_CUBE_INTEGRATION_ID"
  }'