Retrieve the PostgreSQL database connection details for your organization. This provides direct access to your organization’s Neon database instance.
Response
Database project name (typically org_[organization_id])
Database connection detailsShow Connection URI Object
Complete PostgreSQL connection string with credentialsFormat: postgresql://[user]:[password]@[host]/[database]?[params]
Example Request
curl -X GET -H "x-api-key: YOUR_API_KEY" \
https://api.xpander.ai/v1/misc/db
Example Response
{
"id": "still-meadow-47437464",
"name": "org_91fbe9bc-35b3-41e8-b59d-922fb5a0f031",
"organization_id": "91fbe9bc-35b3-41e8-b59d-922fb5a0f031",
"connection_uri": {
"uri": "postgresql://user:password@ep-proud-credit-af01jccy.c-2.us-west-2.aws.neon.tech/xpander?channel_binding=require&sslmode=require"
}
}
Usage Examples
Python (psycopg2)
import psycopg2
import requests
# Get connection string
response = requests.get(
"https://api.xpander.ai/v1/misc/db",
headers={"x-api-key": "YOUR_API_KEY"}
)
connection_uri = response.json()["connection_uri"]["uri"]
# Connect to database
conn = psycopg2.connect(connection_uri)
cursor = conn.cursor()
# Query data
cursor.execute("SELECT * FROM tasks LIMIT 10")
results = cursor.fetchall()
Node.js (pg)
const fetch = require('node-fetch');
const { Client } = require('pg');
// Get connection string
const response = await fetch('https://api.xpander.ai/v1/misc/db', {
headers: { 'x-api-key': 'YOUR_API_KEY' }
});
const { connection_uri } = await response.json();
// Connect to database
const client = new Client({
connectionString: connection_uri.uri
});
await client.connect();
// Query data
const result = await client.query('SELECT * FROM tasks LIMIT 10');
console.log(result.rows);
CLI (psql)
# Get connection string
CONNECTION_URI=$(curl -H "x-api-key: YOUR_API_KEY" \
https://api.xpander.ai/v1/misc/db | jq -r '.connection_uri.uri')
# Connect with psql
psql "$CONNECTION_URI"
Database Schema
Your organization database contains tables for:
- agents - Agent configurations and metadata
- tasks - Task execution records
- knowledge_bases - Knowledge base metadata
- documents - Document records and processing status
- users - User information and permissions
- And more…
Security Notes
- The connection string includes credentials - keep it secure
- Use environment variables to store the connection string
- Never commit connection strings to version control
- The database is read-write - be careful with modifications
- SSL is required for all connections
Use Cases
- Custom analytics - Query task and agent data directly
- Data export - Extract data for external analysis
- Integration - Connect BI tools like Tableau, Metabase, etc.
- Backup - Create custom backup solutions
- Advanced queries - Perform complex SQL queries not available via API
Notes
- This is a Neon PostgreSQL serverless database
- Connection pooling is handled automatically
- Database is located in AWS us-west-2 region
- SSL mode is required for security
See Also
- [List Tasks](/API reference/v1/tasks/list-tasks) - Query tasks via REST API
- [List Agents](/API reference/v1/agents/list-agents) - Query agents via REST API
- Neon Documentation - Learn more about Neon PostgreSQL