> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getmembrane.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 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

```yaml theme={null}
# 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 (matching `parametersSchema`) 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:**

```javascript theme={null}
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,
  }
}
```
