<@U04S8PLJWMT> I’m using a synthetic cursor field ...
# ask-ai
m
@kapa.ai I’m using a synthetic cursor field stream_interval.start_time, how to ensure the url is already requested a truncated to nearest hour start time and date?
k
To ensure that the URL is requested with a start time and date truncated to the nearest hour using the synthetic cursor field
stream_interval.start_time
, you can use Jinja templating to format or truncate the value before injecting it into the URL. Airbyte allows you to use Jinja expressions and available variables (like
stream_interval.start_time
) in the URL path, query parameters, or request body. However, the knowledge sources do not provide a built-in function or direct example for truncating
stream_interval.start_time
to the nearest hour. They do show that you can use Jinja templating for custom parameter injection, such as:
Copy code
jinja /exchangerates_data/{{ stream_interval.start_time }}
or
Copy code
json {   "query": "last_event_time BETWEEN TIMESTAMP \"{{ stream_interval.start_time }}\" AND TIMESTAMP \"{{ stream_interval.end_time }}\"" }
You can use Jinja filters to manipulate the string if your datetime format is consistent. For example, if your datetime is in ISO format (
YYYY-MM-DDTHH:MM:SSZ
), you could truncate the string to the hour by slicing:
Copy code
jinja {{ stream_interval.start_time[:13] }}:00:00Z
You would use this in your URL or parameter configuration, for example:
Copy code
jinja /search?from-date={{ stream_interval.start_time[:13] }}:00:00Z
This approach assumes your datetime string is always in the same format and you only need the hour precision. If you need more advanced datetime manipulation, you may need to preprocess the value before it reaches Airbyte, as the built-in templating is limited to basic string operations. For more on using variables and Jinja in Airbyte, see the [custom parameter injection documentation](https://docs.airbyte.com/platform/connector-development/connector-builder-ui/incremental-sync#custom-parameter-injection) and [YAML reference for variables](https://docs.airbyte.com/platform/connector-development/config-based/understanding-the-yaml-file/reference#variables). Summary: - Use Jinja templating to slice or format
stream_interval.start_time
as needed. - Example for truncating to the hour:
{{ stream_interval.start_time[:13] }}:00:00Z
- Insert this expression where you configure the URL or query parameter in the connector builder UI. If you need more advanced datetime logic, the knowledge sources do not provide a built-in solution, and you may need to handle it outside of Airbyte or with custom code. [Custom parameter injection](https://docs.airbyte.com/platform/connector-development/connector-builder-ui/incremental-sync#custom-parameter-injection)
m
@kapa.ai for the synthetic cursor field, should you use start_time or end_time, or does it matter?
k
A message from kapa.ai
For synthetic cursor fields in Airbyte, such as when using
stream_interval.start_time
or
stream_interval.end_time
, the choice depends on your use case and how you want to partition or track your data. The knowledge sources explain that the synthetic cursor field is typically used to represent the boundaries of the current sync interval. You can reference either
stream_interval.start_time
or
stream_interval.end_time
in your configuration, and both are available as variables for use in request parameters or URLs. The documentation provides examples of using both, depending on whether you want to reference the start or end of the current interval for your API requests or state tracking. For example, if you want to fetch records starting from the beginning of the interval, you would use
stream_interval.start_time
. If you want to fetch up to the end of the interval, you would use
stream_interval.end_time
. The choice does matter based on your API's requirements and how you want to define the window of data being synced. > In some cases, it's helpful to reference the start and end date of the interval that's currently synced, for example if it needs to be injected into the URL path of the current stream. In these cases it can be referenced using the
{{ stream_interval.start_time }}
and
{{ stream_interval.end_time }}
placeholders [Incremental sync example](https://docs.airbyte.com/platform/connector-development/connector-builder-ui/incremental-sync#example). Summary: - Use
stream_interval.start_time
to reference the beginning of the sync window. - Use
stream_interval.end_time
to reference the end of the sync window. - Choose based on your API's requirements and the logic of your incremental sync. Both are valid; it depends on your specific use case and how your source API expects the time window to be defined.