<@U04S8PLJWMT> how should i retrieve timestamp for...
# ask-ai
j
@kapa.ai how should i retrieve timestamp for last sync time in connector for custom builder connection?
k
To retrieve the timestamp for the last sync time in a connector built with the Airbyte Connector Builder, you should use the cursor field configured for incremental sync. During each sync, Airbyte tracks the value of this cursor (typically a timestamp like
updated_at
or
date_modification
) and stores it as the stream state. On subsequent syncs, Airbyte injects this value as the starting point for the next incremental sync, so only new or updated records are fetched. In the Connector Builder UI, you configure: - The cursor field (e.g.,
updated_at
) - The datetime format for the cursor - The start datetime (used for the first sync; subsequent syncs use the last saved cursor value) - How to inject the cursor value into the outgoing HTTP request (as a query parameter, header, or in the body) On each sync, Airbyte automatically updates the state with the latest cursor value from the records retrieved. You do not need to manually retrieve or manage the last sync timestamp; Airbyte handles this as part of its incremental sync logic. If you need to reference this value in custom parameter injection, you can use variables like
{{ stream_state.cursor_field }}
in your request configuration, depending on your API's requirements and the builder's available variables. For more details, see the official documentation on incremental sync configuration in the Connector Builder UI: - [Incremental sync (Airbyte Docs)](https://docs.airbyte.com/platform/connector-development/connector-builder-ui/incremental-sync) - [Custom parameter injection](https://docs.airbyte.com/platform/connector-development/connector-builder-ui/incremental-sync#custom-parameter-injection) If you are experiencing issues where the last sync timestamp is not being respected (e.g., the connector re-fetches all data), this may be a bug or limitation in the Connector Builder, as described in [this GitHub issue](https://github.com/airbytehq/airbyte/issues/61567). In such cases, review your configuration and consider reporting the issue if it persists.
j
@kapa.ai ok, i want to extrapole stream_state.cursor_field value to inject it into query parameters. can i do that?
k
A message from kapa.ai
Yes, you can inject the last sync timestamp (the value of the cursor field from the stream state) into query parameters using the Connector Builder's custom parameter injection feature. To do this, you should use the available variables in Jinja expressions within the generic parameter section of the stream configuration form. The documentation explains that you can reference variables such as
{{ stream_interval.start_time }}
and
{{ stream_interval.end_time }}
to represent the start and end times of the current sync interval. These are typically derived from the stream state and are what you want to inject as query parameters for incremental syncs. For example:
Copy code
yaml parameters:   - key: from-date     value: "{{ stream_interval.start_time }}"   - key: to-date     value: "{{ stream_interval.end_time }}"
This approach is recommended when you need more control than the standard injection options provide, such as when you need to format the parameter or combine multiple values. You can use these variables in query parameters, headers, body, or even the URL path as needed for your API. For more details, see the documentation on [custom parameter injection](https://docs.airbyte.com/platform/connector-development/connector-builder-ui/incremental-sync#custom-parameter-injection) and the use of [available variables](https://docs.airbyte.com/platform/connector-development/config-based/understanding-the-yaml-file/reference/#/variables) in the Connector Builder UI. Note: The variable
stream_interval.start_time
is the recommended way to access the last sync timestamp, rather than a generic
stream_state.cursor_field
variable, according to the official documentation. [Source: Custom parameter injection](https://docs.airbyte.com/platform/connector-development/connector-builder-ui/incremental-sync#custom-parameter-injection)
j
@kapa.ai i want to take last syncs end time instead of current sync start time, as there might be long interval between them. How can i retrieve this info?
k
A message from kapa.ai
Based on the available Airbyte documentation, the recommended way to reference the sync interval in the Connector Builder is by using the variables
{{ stream_interval.start_time }}
and
{{ stream_interval.end_time }}
. These variables represent the start and end times of the current sync interval, and are designed to be used for injecting time-based parameters into your API requests. However, the documentation does not explicitly mention a built-in variable for directly accessing the previous sync's end time (i.e., the end time from the last completed sync, before the current one starts). The standard approach is to use
{{ stream_interval.start_time }}
as the lower bound for the current sync, which is typically set to the last record's cursor value from the previous sync. The
{{ stream_interval.end_time }}
is set to the current upper bound (often "now") for the current sync. If you need to reference the previous sync's end time specifically (not the current sync's start time), the knowledge sources do not provide a direct method or variable for this. The available variables are focused on the current sync interval only. If your use case requires this level of control, you may need to implement custom logic outside of the standard Connector Builder UI, or consider a custom connector implementation. Summary: You can use
{{ stream_interval.start_time }}
and
{{ stream_interval.end_time }}
for the current sync interval, but there is no documented way to directly access the previous sync's end time in the Connector Builder UI according to the current documentation sourcesĀ [Custom parameter injection](https://docs.airbyte.com/platform/connector-development/connector-builder-ui/incremental-sync#custom-parameter-injection).
j
@kapa.ai so if i want to insert into query params starttime and endtime to query only data that was in between syncs, what parameters should i use?
k
A message from kapa.ai
To query only the data that was created or updated between syncs, you should inject the start time and end time of the current sync interval into your query parameters. In Airbyte's Connector Builder, you do this using the variables: -
{{ stream_interval.start_time }}
-
{{ stream_interval.end_time }}
These variables represent the lower and upper bounds of the current sync window. Typically,
start_time
is set to the last record's cursor value from the previous sync (i.e., the last sync's end time), and
end_time
is set to the current upper bound (often "now"). Example configuration for query parameters:
Copy code
yaml parameters:   - key: starttime     value: "{{ stream_interval.start_time }}"   - key: endtime     value: "{{ stream_interval.end_time }}"
This setup ensures that your API requests only fetch records where the timestamp is between the last sync's end and the current sync's end, covering the interval between syncs. For more details, see the documentation on [custom parameter injection](https://docs.airbyte.com/platform/connector-development/connector-builder-ui/incremental-sync#custom-parameter-injection). If your API uses different parameter names (e.g.,
from-date
,
to-date
), just substitute those names for
starttime
and
endtime
in the example above.