Introduction

Metabase is a popular open-source business intelligence and data visualization platform that connects to multiple databases and allows users to create dashboards and reports. As a Metabase administrator, you may need to view all configured database connections for auditing, troubleshooting, or migration purposes.

This article explains how to list all databases configured in Metabase using the API from the command line.

Prerequisites

Before proceeding, ensure you have:

  • Access to the Metabase server.
  • Metabase administrator credentials.
  • curl installed on the server.
  • jq installed (optional, for formatted output).
  • Network access to the Metabase application URL.

Verify that Metabase is accessible:

$ curl -I http://localhost:3000

Expected output:

HTTP/1.1 200 OK

Implementation

Step 1: Generate a Metabase Session Token

Authenticate with Metabase and obtain a session token.

$ curl -X POST http://localhost:3000/api/session \
-H “Content-Type: application/json” \
-d ‘{
“username”:”admin@example.com”,
“password”:”your_password”
}’

Example output:

{
“id”:”SESSION_TOKEN”
}

Copy the session token value.

Step 2: List All Configured Database

Run the following command:

curl -X GET http://localhost:3000/api/database \
-H “X-Metabase-Session: SESSION_TOKEN”

Example output:

{
“data”:[
{
“id”:1,
“name”:”Production MySQL”,
“engine”:”mysql”
},
{
“id”:2,
“name”:”Analytics PostgreSQL”,
“engine”:”postgres”
}
]
}

Step 3: Display Only Database Names

For a cleaner output, use:

$ curl -s http://localhost:3000/api/database \
-H “X-Metabase-Session: SESSION_TOKEN” | jq -r ‘.data[].name’

Example output:

Production MySQL
Analytics PostgreSQL
Reporting Database

Step 4: Display Database Names and Types

curl -s http://localhost:3000/api/database \
-H “X-Metabase-Session: SESSION_TOKEN” | jq -r ‘.data[] | “(.name) – (.engine)”‘

Example output:

Production MySQL – mysql
Analytics PostgreSQL – postgres
Reporting Database – sqlserver

Verification

Confirm that:

  • The API request returns a list of configured databases.
  • Database names are displayed correctly.
  • Database engines (MySQL, PostgreSQL, SQL Server, etc.) are shown as expected.

If the API returns an authentication error, generate a new session token and try again.

Conclusion

Using the Metabase API, administrators can quickly list all configured database connections from the command line. This method is useful for auditing, migration planning, troubleshooting, and validating database connectivity without logging in to the Metabase web interface. Regularly reviewing configured databases helps maintain an organized and secure Metabase environment.

Leave a Reply