Docs/API/Streams API

Stream API Code Examples

Practical code examples for the DBConvert Streams Stream API. For the complete endpoint reference, see Streams 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)
  • At least one configured source and target connection (see Connection API Examples)
  • 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"

# Create a stream configuration
config_result=$(curl -s -X POST "$API_URL/stream-configs" \
  -H "X-API-Key: $API_KEY" \
  -H "X-Install-ID: $INSTALL_ID" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "mysql_to_postgresql",
    "mode": "load",
    "source": {
      "connections": [
        {
          "connectionId": "conn_source_id",
          "database": "sakila",
          "tables": [
            {"name": "actor"},
            {"name": "film"}
          ]
        }
      ]
    },
    "target": {
      "id": "conn_target_id",
      "spec": {
        "db": {
          "database": "postgres",
          "writeMode": "truncate_and_load",
          "structureOptions": {
            "tables": true,
            "indexes": true,
            "foreignKeys": true
          }
        }
      }
    }
  }')

# Extract configuration ID
CONFIG_ID=$(echo $config_result | jq -r '.id')
echo "Config ID: $CONFIG_ID"  # config_...

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

# Start a stream from the configuration
stream_result=$(curl -s -X POST "$API_URL/stream-configs/$CONFIG_ID/start" \
  -H "X-API-Key: $API_KEY" \
  -H "X-Install-ID: $INSTALL_ID")

# Extract stream execution ID
STREAM_ID=$(echo $stream_result | jq -r '.id')
echo "Stream ID: $STREAM_ID"  # stream_...

# Get stream statistics
curl "$API_URL/streams/$STREAM_ID/stats" \
  -H "X-API-Key: $API_KEY" \
  -H "X-Install-ID: $INSTALL_ID"

# Pause a running stream (returns 204 No Content)
curl -X POST "$API_URL/streams/$STREAM_ID/pause" \
  -H "X-API-Key: $API_KEY" \
  -H "X-Install-ID: $INSTALL_ID"

# Resume a paused stream (returns 204 No Content)
curl -X POST "$API_URL/streams/$STREAM_ID/resume" \
  -H "X-API-Key: $API_KEY" \
  -H "X-Install-ID: $INSTALL_ID"

# Stop a stream (returns 204 No Content)
curl -X POST "$API_URL/streams/$STREAM_ID/stop" \
  -H "X-API-Key: $API_KEY" \
  -H "X-Install-ID: $INSTALL_ID"

# Get run history for a configuration
curl "$API_URL/stream-configs/$CONFIG_ID/history" \
  -H "X-API-Key: $API_KEY" \
  -H "X-Install-ID: $INSTALL_ID"

# Get persisted logs for a completed stream
curl "$API_URL/streams/$STREAM_ID/logs" \
  -H "X-API-Key: $API_KEY" \
  -H "X-Install-ID: $INSTALL_ID"

# Delete a configuration (requires confirmation header)
curl -X DELETE "$API_URL/stream-configs/$CONFIG_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": "Cannot start new stream: found active streams that need attention",
  "type": "validation",
  "code": "VALIDATION_FAILED",
  "details": {
    "field": "stream_state",
    "reason": "Cannot start new stream: found active streams that need attention"
  }
}

Common status codes:

CodeMeaning
400Validation error (missing fields, invalid config)
401Invalid or missing API key
404Configuration or stream not found
503Service error