Dynamic Endpoints ⚡

Examples of using dynamic endpoints to programmatically generate multiple endpoint configurations

Dynamic endpoints allow you to programmatically generate multiple endpoint configurations based on runtime data. This is powerful for APIs where the list of available endpoints or resources isn't known until you query the API itself, or when you need to create many similar endpoints without repeating configuration.

Learn more: Dynamic Endpoints " State Variables " Processors

How Dynamic Endpoints Work

Dynamic endpoints use the dynamic_endpoints key to generate multiple endpoint configurations:

  1. Setup Phase (optional): Execute API calls to fetch data needed for iteration

  2. Iteration Phase: Loop over a list (from setup or predefined)

  3. Generation Phase: Create one endpoint configuration per iteration item

  4. Execution Phase: Run the generated endpoints like normal static endpoints

The generated endpoints are combined with any static endpoints defined in the endpoints section.

Simple Iteration Over Static List

The simplest use case - iterate over a predefined list to create multiple similar endpoints.

Spec File (resources_api.yaml)

resources_api.yaml
name: "Resources API"

defaults:
  state:
    base_url: https://api.example.com/v1
  request:
    headers:
      Authorization: "Bearer {secrets.api_key}"

dynamic_endpoints:
  # Iterate over a static list of resource types
  - iterate: '["users", "orders", "products"]'
    into: "state.resource_type"

    endpoint:
      # Generate endpoint name from resource type
      name: "{state.resource_type}"
      description: "Fetch {state.resource_type} data"

      request:
        url: "{state.base_url}/{state.resource_type}"
        parameters:
          limit: 100
          offset: 0

      pagination:
        next_state:
          offset: "{state.offset + 100}"
        stop_condition: length(response.records) < 100

      response:
        records:
          jmespath: "data[]"
          primary_key: ["id"]

        processors:
          # Add resource type to each record for tracking
          - expression: "state.resource_type"
            output: "record._resource_type"

Using Replication

Running with Sling: sling run -r /path/to/replication.yaml

This creates three endpoints from a single configuration, avoiding repetition.


Using Python

Dynamic Discovery from API

Fetch the list of available resources from the API itself, then create endpoints dynamically.

Spec File (database_api.yaml)


Using Replication


Using Python

Multi-Organization Endpoints

Create separate endpoints for each organization the authenticated user has access to.

Spec File (multi_org_api.yaml)


Using Replication

Geographic Regions with Metadata

Create endpoints for predefined geographic regions with additional metadata.

Spec File (regional_api.yaml)


Using Replication

Combining Static and Dynamic Endpoints

Mix static endpoints (for unique resources) with dynamic endpoints (for similar resources).

Spec File (hybrid_api.yaml)


Using Replication

Filtering During Setup

Only generate endpoints for resources matching specific criteria.

Spec File (filtered_api.yaml)


Using Replication

Pattern Matching Dynamic Endpoints

Use wildcards to run multiple dynamic endpoints at once.

Using Replication with Wildcards


Using Python with Pattern Matching

Best Practices

1. Use Meaningful Endpoint Names

Generate descriptive names that clearly identify what each endpoint does:

2. Filter in Setup Phase

Only generate endpoints you'll actually use:

3. Add Context to Records

Use processors to tag records with metadata from the iteration:

4. Validate Iteration Data

Ensure the data you're iterating over is valid:

5. Use Static Endpoints for Unique Resources

Don't force everything into dynamic endpoints. Use static endpoints for one-off resources:

6. Consider Performance

Be mindful of how many endpoints you generate:

Combining Dynamic Endpoints with Other Features

With Incremental Sync

With Backfill

Last updated

Was this helpful?