Incremental
Examples of incrementally loading data from APIs to databases using sync state
How API Incremental Sync Works
Timestamp-Based Incremental Sync
name: "Orders API"
defaults:
state:
base_url: https://api.shop.com/v1
request:
headers:
Authorization: "Bearer {secrets.api_key}"
endpoints:
orders:
description: "Get orders updated since last sync"
# Persist last_updated_at for next run
sync: [last_updated_at]
state:
# Use last sync time if available, otherwise default to 30 days ago
updated_at_min: >
{coalesce(
sync.last_updated_at,
date_format(date_add(now(), -30, "day"), "%Y-%m-%dT%H:%M:%S%z")
)}
limit: 100
offset: 0
request:
url: "{state.base_url}/orders"
parameters:
# Filter API to only return records updated after this timestamp
updated_at_min: "{state.updated_at_min}"
limit: "{state.limit}"
offset: "{state.offset}"
pagination:
next_state:
offset: "{state.offset + state.limit}"
stop_condition: length(response.records) < state.limit
response:
records:
jmespath: "orders[]"
primary_key: ["order_id"]
processors:
# Track the maximum updated_at timestamp across all records
- expression: "record.updated_at"
output: "state.last_updated_at"
aggregation: "maximum" # Save highest timestamp for next sync
overrides:
mode: incremental # Upsert based on primary_keyID-Based Incremental Sync
Date-Based Incremental with Iteration
Multiple Sync Variables
Using SLING_STATE
Incremental with Full Refresh Fallback
Best Practices
1. Always Provide Sensible Defaults
2. Use Appropriate Aggregation
3. Include Primary Keys
4. Handle Edge Cases
5. Use Incremental Mode Override
Combining Incremental with Backfill
Last updated
Was this helpful?