Docs/API/Connections API

Connection API Code Examples

Practical code examples for the DBConvert Streams Connection API. For the complete endpoint reference, see Connections API Workflows.

Prerequisites

  • A valid DBConvert Streams API key and Install ID
  • The API server running (default: http://127.0.0.1:8020/api/v1)
  • Language-specific dependencies:
    • Python: requests (pip install requests)
    • Node.js: axios (npm install axios)
    • PowerShell: Version 5.1 or later

Examples by technology

Select a tab to view the workflow in the client you use.

# Set credentials
export API_KEY="your_api_key_here"
export INSTALL_ID="your_install_id_here"
export API_URL="http://127.0.0.1:8020/api/v1"

# Load user configurations (required before other endpoints)
curl "$API_URL/user/configs" \
  -H "X-API-Key: $API_KEY" \
  -H "X-Install-ID: $INSTALL_ID"

# List all connections
curl "$API_URL/connections" \
  -H "X-API-Key: $API_KEY" \
  -H "X-Install-ID: $INSTALL_ID"

# Create a MySQL connection
curl -X POST "$API_URL/connections" \
  -H "X-API-Key: $API_KEY" \
  -H "X-Install-ID: $INSTALL_ID" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "mysql-source",
    "type": "mysql",
    "spec": {
      "database": {
        "host": "localhost",
        "port": 3306,
        "username": "root",
        "password": "your_password",
        "database": "source_db"
      }
    }
  }'

# Create a PostgreSQL connection
curl -X POST "$API_URL/connections" \
  -H "X-API-Key: $API_KEY" \
  -H "X-Install-ID: $INSTALL_ID" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "pg-target",
    "type": "postgresql",
    "spec": {
      "database": {
        "host": "localhost",
        "port": 5432,
        "username": "postgres",
        "password": "your_password",
        "database": "target_db"
      }
    }
  }'

# Test a saved connection
curl -X POST "$API_URL/connections/$CONN_ID/ping" \
  -H "X-API-Key: $API_KEY" \
  -H "X-Install-ID: $INSTALL_ID"

# List databases
curl "$API_URL/connections/$CONN_ID/databases" \
  -H "X-API-Key: $API_KEY" \
  -H "X-Install-ID: $INSTALL_ID"

# List tables in a database
curl "$API_URL/connections/$CONN_ID/databases/source_db/tables" \
  -H "X-API-Key: $API_KEY" \
  -H "X-Install-ID: $INSTALL_ID"

# Delete a connection (requires confirmation header)
curl -X DELETE "$API_URL/connections/$CONN_ID" \
  -H "X-API-Key: $API_KEY" \
  -H "X-Install-ID: $INSTALL_ID" \
  -H "X-Confirm-Delete: true"

Error handling

The API returns structured errors:

{
  "error": "Validation failed for field 'X-Confirm-Delete': Deletion requires X-Confirm-Delete: true header",
  "type": "validation",
  "code": "VALIDATION_FAILED",
  "details": {
    "field": "X-Confirm-Delete",
    "reason": "Deletion requires X-Confirm-Delete: true header"
  }
}

Common status codes:

CodeMeaning
400Invalid request data
401Invalid or missing API key
404Connection not found
503Database connection error