Queues
Queues enable sophisticated multi-step data extraction workflows where one endpoint collects data (such as records or identifiers )that is used by subsequent endpoints. This is essential for APIs that require separate calls to fetch related data.
Queue Architecture
Queue Declaration and Usage
1. Queue Declaration
Queues must be declared at the top level of your API spec:
# Declare queues for passing data between endpoints
queues:
- customer_ids
- invoice_ids
- order_items2. Sending Data to Queues
Use processors to send data from one endpoint to a queue:
endpoints:
list_customers:
description: "Get list of customers"
request:
url: "customers"
response:
records:
jmespath: "data[]"
primary_key: ["id"]
processors:
# Send customer IDs to queue for detailed processing
- expression: "record.id"
output: "queue.customer_ids"3. Consuming Data from Queues
Use the iterate section to process each item from a queue:
Queue Functions
Queues can be used with built-in functions for advanced processing:
Chunking Queue Data
Process queue items in batches for more efficient API calls:
Real-World Example: Stripe API
This example from the Stripe API demonstrates a complete queue-based workflow:
Queue Properties and Behavior
Queue Characteristics
Temporary Storage
Queues are backed by temporary files
Automatically cleaned up after run
FIFO Order
Items are processed in first-in, first-out order
IDs processed in the order they were added
JSON Encoding
All data is JSON-encoded for safe storage
Handles strings, numbers, objects, arrays
Single Run Scope
Queues exist only within a single Sling execution
Cannot persist between separate runs
Queue Lifecycle
Direct Queue-to-Records Pattern
You can pipe queue data directly to records without making HTTP requests using the special syntax iterate.into: "response.records".
Basic Syntax
When to Use
Deduplicate queue items before further processing
Enrich queue data with state variables
Transform queue structure
Export queue contents as a separate dataset
Example: Deduplication Workflow
Data Type Handling
Scalar values (strings/numbers) are wrapped: "user123" → {"value": "user123"}
Object values are used as-is: {"id": 1, "name": "Alice"} → same structure
Limitations
No HTTP response data (
response.status,response.headersunavailable)Cannot use pagination or response rules
Don't define a
requestblock (it will be ignored)
💡 Tip: This pattern is much faster than unnecessary HTTP requests for queue transformation steps.
Advanced Queue Patterns
Pattern 1: Multi-Level Hierarchies
Process nested data structures with multiple queue levels:
Pattern 2: Conditional Queue Population
Only queue certain items based on conditions:
Pattern 3: Queue Transformation
Transform data before queuing:
Queue Best Practices
Performance Optimization
Error Handling with Queues
💡 Tip: Use descriptive queue names that clearly indicate their purpose (e.g.,
customer_ids,pending_order_ids,failed_payment_ids).
⚠️ Warning: Queues consume disk space proportional to the number of items. For very large datasets (millions of items), monitor available disk space.
📝 Note: Queue items are automatically JSON-encoded, so complex objects, arrays, and special characters are handled safely.
Last updated
Was this helpful?