For the complete documentation index, see llms.txt. This page is also available as Markdown.
Testing & Debugging
Testing your Sling API specifications is a crucial step before deploying them in production. This document covers tools and techniques to verify your specs work correctly, debug issues, and optimize performance.
The general workflow for developing and testing API specs is:
Creating a Connection with an API Spec
The first step is create and save your Spec YAML file somewhere accessible. This can be your local drive, or any other be any storage connection you have setup, such a S3/GCP bucket, or FTP/SFTP. Furthermore, sling supports reading API Specs from a HTTP URL (such as Github URLs).
Once you have an API Spec file to use, you can then create a connection in your env.yaml file, like this:
You can also use an environment variable (YAML or JSON format):
The connection should show up like the others:
Using the Test Command
Sling provides the conns test command to verify your API connection and test individual endpoints.
Testing the Connection
Testing Specific Endpoints
Discovering Available Endpoints
To see the available endpoints in your API spec:
This command is particularly useful for verifying that all your endpoints are correctly defined and visible to Sling.
Debugging Tools
Sling offers two levels of debug output to help diagnose issues with your API specs.
Debug Flag
The --debug flag provides basic information about request flows, pagination, and data processing:
Debug output includes:
API requests being made
Response status codes
Record counts
Pagination details
State variable changes
Trace Flag
For more detailed debugging, use the --trace flag:
The trace output includes everything from debug plus:
Full request headers and parameters
Response headers
JSON response bodies (truncated for large responses)
Detailed expression evaluation
Auth token refresh events
Queue operations
⚠️ Warning: The --trace flag may expose sensitive information in logs, such as authorization tokens. Use carefully and don't share unredacted logs.
Examining Request and Response Flow
With trace enabled, you can see the complete flow of HTTP requests and responses. This is invaluable for debugging pagination, authentication, or data extraction issues:
Common Issues
Authentication Problems
If you're getting 401 Unauthorized or 403 Forbidden responses:
Common fixes:
Verify the secrets such as API keys or tokens in your environment file
Check for correct authentication type (bearer, basic, oauth2)
Ensure required scopes are included for OAuth2
Pagination Issues
If your endpoint doesn't retrieve all expected data:
Look for:
stop_condition evaluation results
next_state changes between requests
Response headers for Link-based pagination
has_more flags in response bodies
JMESPath Extraction Problems
If your records aren't being properly extracted:
Look for:
Complete response JSON to verify the correct path
JMESPath extraction results
Record counts in your output
Testing Best Practices
1. Test Incrementally
When building complex API specs:
Start by testing basic authentication
Test a simple endpoint without pagination
Add and test pagination
Test one endpoint that uses iteration
Test queue-based workflows with multiple endpoints
Finally, test complex transformations and processors
2. Limit Data During Testing
Use these techniques to limit data volume during testing:
Set the environment variable SLING_TEST_ENDPOINT_LIMIT:
Or use date filtering if the API supports it:
3. Use Replication Files for Full Testing
Create a replication YAML file to test the flow from API to your database:
Run with:
4. Create Environment Variables for Testing
For testing different scenarios:
Real-World Examples
Testing Stripe Endpoints
This example tests the Stripe customer and balance transaction endpoints:
The corresponding replication file would look like:
💡 Tip: When developing a complex API spec, maintain a test script with your commonly used test commands for quick iteration.
connections:
stripe:
type: api
# fetch from github repo
spec: https://github.com/my-org/my-repo/blob/main/api/specs/stripe.yaml
secrets:
api_key: xxxxxxxxxxxxxxx
my_api:
type: api
spec: file:///path/to/my_api.yaml # read from local file
secrets:
account_id: xxxxxxxxxxx
token: xxxxxxxxxxxxxxx
my_other_api:
type: api
spec: aws_s3/path/to/my_other_api.yaml # fetches from your s3 connection
# Windows Powershell
$env:DBT_CLOUD_API='{ type: api, spec: https://github.com/slingdata-io/sling-cli/blob/main/api/specs/dbt_cloud.yaml, secrets: { account_id: xxxxx, api_token: xxxxxxx } }'
# Linux or Mac
export DBT_CLOUD_API='{ type: api, spec: https://github.com/slingdata-io/sling-cli/blob/main/api/specs/dbt_cloud.yaml, secrets: { account_id: xxxxx, api_token: xxxxxxx } }'
# List all your connections
$ sling conns list
+----------------+-----------------+----------------+
| CONN NAME | CONN TYPE | SOURCE |
+----------------+-----------------+----------------+
| POSTGRES | DB - PostgreSQL | sling env yaml |
| SNOWFLAKE | DB - Snowflake | sling env yaml |
| STRIPE | API - Spec | sling env yaml |
| MY_API | API - Spec | sling env yaml |
| MY_OTHER_API | API - Spec | sling env yaml |
| DBT_CLOUD_API | API - Spec | env variable |
+----------------+-----------------+----------------+
# Test that your connection is properly configured
sling conns test API_CONNECTION_NAME
# Example testing a Stripe connection
sling conns test STRIPE
# Test specific endpoints
sling conns test API_CONNECTION_NAME --endpoints endpoint1,endpoint2
# Example testing specific Stripe endpoints
sling conns test STRIPE --endpoints customer,charge
# List all endpoints in your API spec
sling conns discover API_CONNECTION_NAME
# Example for Shopify
sling conns discover STRIPE
# Basic debugging information
sling conns test STRIPE --endpoints customer --debug
# Detailed trace information
sling conns test STRIPE --endpoints customer --trace
# Trace with attention to record extraction
sling conns test API_NAME --endpoints ENDPOINT_NAME --trace
# Windows Powershell
$env:SLING_TEST_ENDPOINT_LIMIT='30'
# Linux or Mac
export SLING_TEST_ENDPOINT_LIMIT=30
# In your endpoint definition
response:
records:
# Limit total records processed during testing
limit: 10
# Example from Shopify endpoint
request:
parameters:
# Limit to recent data only
updated_at_min: '{date_format(date_add(now(), -2, "day"), "%Y-%m-%dT%H:%M:%S%z")}'
# Example stripe_test.yaml
source: stripe_sling
target: postgres
defaults:
mode: full-refresh # Use for testing instead of incremental
object: apis.stripe_test_{stream_name} # Use test schema
streams:
# Test specific streams
customer:
charge:
env:
SLING_LOADED_AT_COLUMN: timestamp
sling run -r stripe_test.yaml --debug
# Test with different time ranges
CREATED_GTE=1659312000 sling conns test STRIPE --endpoints charge --debug
# Test with specific user
GITHUB_USERNAME=test-user sling conns test GITHUB --endpoints repos --debug
# Test specific Stripe endpoints
sling conns test STRIPE --endpoints customer,customer_balance_transaction --debug
# r.61.stripe.yaml
source: stripe_sling
target: postgres
defaults:
mode: incremental
object: apis.{source_name}_{stream_name}
source_options:
flatten: 1 # flatten records 1 level only
streams:
'*':
env:
SLING_STATE: postgres/sling_state.stripe # one state table per replication
SLING_LOADED_AT_COLUMN: timestamp