Hello, <@U04S8PLJWMT>, using Airbyte Custom builde...
# ask-ai
x
Hello, @kapa.ai, using Airbyte Custom builder in a POST endpoint with JSON Object Body I need to add a variable inside this body that would be the input user variables.
Copy code
{
  "data": {
    "type": "campaign-values-report",
    "attributes": {
      "timeframe": {
        "key": "last_12_months"
      },
      "statistics": [
        "recipients",
        "opens",
        "opens_unique",
        "clicks",
        "clicks_unique",
        "unsubscribes",
        "spam_complaints",
        "bounced",
        "bounced_or_failed",
        "failed",
        "message_segment_count_sum",
        "conversions",
        "conversion_value"
      ],
      "conversion_metric_id": "LSjDzb"
    }
  }
}
Here I want conversion_metric_id value to be a variable
k
To add a user input variable to your JSON request body in the Airbyte Connector Builder, you can use Jinja expressions to reference configuration variables. Here's how to do it: In your connector's configuration, you would first define a user input field (e.g.,
conversion_metric_id
). Then, in your JSON request body, you can reference this variable using Jinja templating syntax:
Copy code
json {   "data": {     "type": "campaign-values-report",     "attributes": {       "timeframe": {         "key": "last_12_months"       },       "statistics": [         "recipients",         "opens",         "opens_unique",         "clicks",         "clicks_unique",         "unsubscribes",         "spam_complaints",         "bounced",         "bounced_or_failed",         "failed",         "message_segment_count_sum",         "conversions",         "conversion_value"       ],       "conversion_metric_id": "{{ config['conversion_metric_id'] }}"     }   } }
According to the [Request Options documentation](https://docs.airbyte.com/platform/connector-development/config-based/understanding-the-yaml-file/request-options#request-options-provider), you can configure the
request_body_json
in your requester to include nested JSON objects with variable interpolation. The
config
variable allows you to access user-provided configuration values. The documentation also confirms that [nested fields are supported](https://github.com/airbytehq/airbyte/issues/18784) in
request_body_json
, so your nested structure will work correctly. You can use Jinja expressions at any depth within the JSON body to inject dynamic values from your connector's configuration.
x
@kapa.ai thanks, now I need to run this endpoint for different timeframe is it possible to let Airbyte run multiple values of timeframe like an iteration ?
k
A message from kapa.ai
Yes, you can configure Airbyte to iterate over multiple timeframe values using the Partitioning feature in the Connector Builder. This is exactly what partitioning is designed for - making multiple requests with different parameter values. For your use case, you'll want to use a List Partition Router. Here's how to set it up: ## Configuration Steps 1. Enable Partitioning in your stream configuration 2. Configure the List Partition Router with: - Partition Values: Set this to either a static list like
["last_7_days", "last_30_days", "last_12_months"]
or reference a user input using
{{ config['timeframes'] }}
- Current Partition Value Identifier: Choose a name like
timeframe_key
- Inject Partition Value Into Outgoing HTTP Request: Since you need it in the JSON body, you'll reference it in your request body 3. Update your JSON body to use the partition value:
Copy code
json {   "data": {     "type": "campaign-values-report",     "attributes": {       "timeframe": {         "key": "{{ stream_partition.timeframe_key }}"       },       "statistics": [         "recipients",         "opens",         "opens_unique",         "clicks",         "clicks_unique",         "unsubscribes",         "spam_complaints",         "bounced",         "bounced_or_failed",         "failed",         "message_segment_count_sum",         "conversions",         "conversion_value"       ],       "conversion_metric_id": "{{ config['conversion_metric_id'] }}"     }   } }
According to the [Partitioning documentation](https://docs.airbyte.com/platform/connector-development/connector-builder-ui/partitioning), the List Partition Router will iterate over each value in your list and make a separate request for each one. If you set the partition values to
["last_7_days", "last_30_days", "last_12_months"]
, Airbyte will make three separate requests, one for each timeframe value. You can also make this user-configurable by creating a user input of type array and referencing it as
{{ config['timeframes'] }}
in the Partition Values field, as explained in the [static partitioning examples](https://docs.airbyte.com/platform/connector-development/connector-builder-ui/partitioning#dynamic-and-static-partitioning).
x
@kapa.ai I have to parameters
start
and
end
where I want to be each calendar year from 2022
Copy code
{
  "data": {
    "type": "campaign-values-report",
    "attributes": {
      "timeframe": {
        "start": "{{ config['start_window'] }}",
        "end": "{{ config['end_window'] }}"
      },
      "statistics": [
        "recipients",
        "opens",
        "opens_unique",
        "clicks",
        "clicks_unique",
        "unsubscribes",
        "spam_complaints",
        "bounced",
        "bounced_or_failed",
        "failed",
        "message_segment_count_sum",
        "conversions",
        "conversion_value"
      ],
      "conversion_metric_id": "{{ config['conversion_metric_id'] }}"
    }
  }
}
k
A message from kapa.ai
To iterate over calendar years from 2022 onwards with start and end dates for each year, you can use the List Partition Router with partition values for each year, and then reference those values in your JSON body. ## Configuration Approach 1. Set up a List Partition Router with partition values representing each year: - Partition Values:
["2022", "2023", "2024"]
(or make it user-configurable) - Current Partition Value Identifier:
year
2. Update your JSON body to construct the start and end dates dynamically:
Copy code
json {   "data": {     "type": "campaign-values-report",     "attributes": {       "timeframe": {         "start": "{{ stream_partition.year }}-01-01",         "end": "{{ stream_partition.year }}-12-31"       },       "statistics": [         "recipients",         "opens",         "opens_unique",         "clicks",         "clicks_unique",         "unsubscribes",         "spam_complaints",         "bounced",         "bounced_or_failed",         "failed",         "message_segment_count_sum",         "conversions",         "conversion_value"       ],       "conversion_metric_id": "{{ config['conversion_metric_id'] }}"     }   } }
This will make separate requests for each year: - 2022:
start: "2022-01-01"
,
end: "2022-12-31"
- 2023:
start: "2023-01-01"
,
end: "2023-12-31"
- 2024:
start: "2024-01-01"
,
end: "2024-12-31"
According to the [Custom parameter injection documentation](https://docs.airbyte.com/platform/connector-development/connector-builder-ui/incremental-sync#custom-parameter-injection), you can use Jinja expressions to freely configure properties of the JSON body. The
stream_partition
variable allows you to reference the current partition value, as shown in the [Partitioning examples](https://docs.airbyte.com/platform/connector-development/connector-builder-ui/partitioning#partition-router-types). If you need more complex date formatting or want to make the year list dynamic, you could also create a user input of type array where users specify which years to sync, and reference it as
{{ config['years'] }}
in the Partition Values field.
x
ok but what if I want to sync only the latest parition with airbyte cloud @kapa.ai ?
k
A message from kapa.ai
Based on the knowledge sources provided, I don't have specific information about how to configure Airbyte Cloud to sync only the latest partition when using a List Partition Router. However, I can suggest a couple of approaches based on the partitioning concepts: ## Possible Approaches 1. Modify your partition values dynamically: Instead of listing multiple years, you could configure your partition values to only include the current year. For example, set your Partition Values to just
["2024"]
(or whatever the current year is). 2. Use a single static value: If you only want the latest year, you might not need partitioning at all. You could simply use Jinja expressions directly in your JSON body to calculate the current year:
Copy code
json {   "data": {     "type": "campaign-values-report",     "attributes": {       "timeframe": {         "start": "2024-01-01",         "end": "2024-12-31"       },       ...     }   } }
3. Consider incremental sync: If your goal is to only sync new data, you might want to explore [incremental sync](https://docs.airbyte.com/platform/connector-development/connector-builder-ui/incremental-sync) instead of partitioning, which is designed to pull only data that has changed since the previous sync. Unfortunately, the knowledge sources don't contain specific information about filtering or limiting partition execution to only the latest partition in Airbyte Cloud. You may need to consult Airbyte's support or community forums for more specific guidance on this use case.