What are API recipes?
The Lightdash API is intentionally modular: most endpoints return small, focused pieces of information. While this keeps the API flexible, some real-world tasks require calling multiple endpoints together or assembling responses in a certain order. For example, Lightdash doesn’t provide a single endpoint that returns “SQL for every chart,” but you can accomplish this by combining the chart-listing endpoint with the metric-query endpoint. Follow the recipes below. API recipes are short guides that show you how to do exactly that. Each recipe walks through:- What you’re trying to accomplish (e.g., fetch SQL for all charts in a project)
- Which endpoints to call and in what order
- Example requests in
curl - Optional scripts in JS/Python when useful
When should you use recipes?
Use a recipe when:- You want to automate a workflow that spans multiple endpoints
- You need to query Lightdash programmatically but aren’t sure which calls to chain
- You want real examples of authentication, pagination, or interpreting metric queries
- You’re building internal tooling or dashboards powered by the Lightdash API
Before you run any recipe
You will need:- Python 3.9+ installed
- A Personal Access Token (PAT)
- Your Lightdash instance URL
- The project UUID you want to modify
Extract SQL from a saved Lightdash chart using the API
This recipe shows how to fetch the underlying SQL for any saved chart. You can use this to debug queries, run them directly in your warehouse, or automate data pulls outside of Lightdash.Step 1: Fetch the saved chart
(You must first create a Personal Access Token (PAT))Step 2: Extract the metricQuery JSON
metricQuery.json.
Step 3: Compile the metricQuery into SQL
One-Step Solution
Dashboard cleanup & usage audit for a project
This Python script helps you clean up dashboards in a specific Lightdash project. It uses the v2 Content API and can export results to CSV, Excel, or JSON for deeper analysis. This script provides:- A complete list of all dashboards with metadata for that project
- View counts and first viewed dates
- Creation and last modification dates
- Dashboard organization by spaces
- Cleanup recommendations based on usage patterns (never viewed, low engagement, stale, no description, etc.)
Before you run this script
You will need:- A copy of find_dashboards.py
Step 1: Install dependencies
You can run this script with poetry or plain Python:requests and pandas.)
Step 2: Update script configuration
Open the script and update these fields:Step 3: Run the script
Using poetry:Export all users in your organization
This Python script fetches all users in your Lightdash organization using the/api/v1/org/users endpoint. This is useful for audits, access reviews, and governance. It returns:
- Full name
- Role
- Group membership
- Optional Excel or CSV export
Before you run this script
You will need:- A copy of get_all_organization_users.py
Step 1: Install dependencies
Step 2: Update script configuration
Open the script and replace:Step 3: Run the script
Assign or update project access for a list of users
This Python script assigns Lightdash project roles to a list of users from a CSV file, and upgrades roles when needed. This is useful for large-scale onboarding, role synchronization, or managing customer/partner access. This script handles:- Bulk granting of project access
- Automatic role upgrades (e.g., viewer → editor)
- Skipping users who already have equal or higher access
- Checking whether users exist in the organization
- Merging org users, project access, and your CSV into one unified dataset
Before you run this script
You will need:- A CSV file of users with desired roles
- A copy of assign_project_access_to_user_list.py