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.

Content Overview

Testing Workflow

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:

  1. Start by testing basic authentication

  2. Test a simple endpoint without pagination

  3. Add and test pagination

  4. Test one endpoint that uses iteration

  5. Test queue-based workflows with multiple endpoints

  6. 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.

Last updated

Was this helpful?