how to use the output from a stream as input to an...
# replication-ask-ai
m
how to use the output from a stream as input to another? I want to use the list of countries returned in one endpoint as request parameter into another stream.
k
Great use case! In Airbyte, the standard way to use the output of one stream as input to another is through partitioning, specifically using the Substream Partition Router (available in the Connector Builder / low-code CDK). Using the Substream Partition Router (Connector Builder) This approach lets you use each record from a "parent" stream (your countries endpoint) as a partition for a "child" stream. Here's how to configure it: 1. Parent Stream: Select the stream that returns your list of countries. 2. Parent Key: Set this to the field on the country record you want to pass (e.g.,
country_code
or
id
). 3. Partition Field: Choose an identifier, e.g.,
country
— this lets you reference the value as
{{ stream_partition.country }}
in the child stream. 4. URL Path / Request Option: Use the partition value in your child stream's path or as a request parameter, e.g.: ◦ As a path:
/data/{{ stream_partition.country }}/details
◦ As a query parameter: inject
country
as a request parameter [Substream Partition Router] Example For WooCommerce order notes (analogous to your use case): • Parent Stream:
orders
• Parent Key:
id
• Partition Field:
order_id
• URL Path:
/orders/{{ stream_partition.order_id }}/notes
This causes the connector to first fetch all records from the parent stream, extract the
id
field from each, and then make one request per value to the child stream. [Partitioning docs] Using the Python CDK (Custom Connectors) If you're building a custom Python connector, you can implement this in the child stream's
stream_slices
method by reading records from the parent stream and yielding slices:
Copy code
def read_slices_from_records(self, stream_class, slice_field):
    stream = stream_class(authenticator=self.authenticator)
    stream_slices = stream.stream_slices(sync_mode=SyncMode.full_refresh)
    for stream_slice in stream_slices:
        for record in stream.read_records(sync_mode=SyncMode.full_refresh, stream_slice=stream_slice):
            yield {slice_field: record["country_code"]}
Then in your
path()
method, use
stream_slice["country_code"]
to build the URL or pass it as a parameter. [Forum: Passing stream results] In summary: For the Connector Builder, use the Substream Partition Router — it's the recommended and most straightforward approach for your use case. 👍 0 button 👎 0 button ℹ️ Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.