Pull Latest Records
The "pull latest records" strategy involves fetching records based on their creation, update, or deletion date.
Use this strategy when the external app does not support webhook events.
Configuration Example
# spec.yml
name: Collection Name
events:
created:
implementationType: pull-latest
methods:
pullLatestRecords:
implementationType: javascript
Functions
There is only one method: pullLatestRecords
.
Pull Latest Records
File: <event-type>-pull-latest-records.<ext>
, for example created-pull-latest-records.js
Arguments:
cursor
– string, cursor returned from the previous page of the results. If not provided, the first page is returned.parameters
– object, parameters (matchingparametersSchema
) of this particular data collection.
Result:
records
– list of objects representing records, ordered by creation date or date-time in descending order.cursor
– string (optional) providing information to retrieve the next chunk of records if pagination is allowed.
Example Implementation:
export default async function pullLatestRecords({
apiClient,
cursor,
parameters,
}) {
// Define the path based on your External App's API structure.
const path = `${parameters.path}?$orderby=createdDateTime desc`
// Make the API request to retrieve records.
const response = await apiClient.get(`${cursor ? cursor : path}`)
// Return the result with records and optional cursor for pagination.
return {
records: response.records,
cursor: response.nextPageLink,
}
}
Updated 2 days ago