# Incremental Sync

It is important to adopt an efficient strategy for downloading Peppol documents from My Azur API. In this chapter, we will see how to maintain a client-side timestamp of the last sync performed and how to request from My Azur API the list of documents following that timestamp.

We start by requesting the list of all received documents (First sync, no previous requests).

```powershell
curl --location 'https://api-sandbox.myazur.app/folders/<folder_id>/documents?incoming=true&status_changed_after=2022-09-23T15%3A26%3A27.193661' \
--header 'Authorization: Bearer <Firebase Token>
```

<figure><img src="/files/0Al5R8zRzqL7mpOOZsrf" alt=""><figcaption><p>Get the full list of received documents</p></figcaption></figure>

We'll get the list of documents in JSON format as following:

<pre class="language-json"><code class="lang-json">{
    <a data-footnote-ref href="#user-content-fn-1">"created_at": "2024-01-09T15:56:58.059944"</a>,
    "objects": [
        {
            "created_at": "2023-10-04T21:56:19.931579",
            "created_by": "abc123-def456-ghi789-jkl012",
            "folder_id": 5,
            "id": 6,
            "incoming": true,
            "response_status_id": 1,
            "status_id": 1,
            "updated_at": "2023-10-04T21:56:19.931579",
            "updated_by": "abc123-def456-ghi789-jkl012"
        },
        {
            "created_at": "2023-10-19T12:38:23.314652",
            "created_by": "abc123-def456-ghi789-jkl012",
            "folder_id": 5,
            "id": 11,
            "incoming": true,
            "response_status_id": 1,
            "status_id": 1,
            "updated_at": "2023-10-19T12:38:23.314652",
            "updated_by": "abc123-def456-ghi789-jkl012"
        },
        ....
        ....
    ]
}
</code></pre>

We get a list of objects and the created\_at timestamp. We should save this timestamp as last synced at timestamp. To request the new received documents we'll send the saved timestamp as query arg in the next request as following:

```powershell
curl --location 'https://api-sandbox.myazur.app/folders/<folder_id>/documents?incoming=true&status_changed_after=2024-01-09T15%3A56%3A58.059944'
--header 'Authorization: Bearer <Firebase Token>
```

<figure><img src="/files/brQ2pLPGIPVCoVtySY3v" alt=""><figcaption><p>Fetch only the new Peppol Documents (Incremental Sync)</p></figcaption></figure>

The same strategy can be used to fetch the list of sent documents that changed their statuses. Initially when you submit a document it gets a status\_id = 1 (Submitted). You are supposed to periodically check for status change by sending the request illustrated above with the query arg incoming = false. You'll get all the documents that you previously sent that changed status.

[^1]: Use the created\_at timestamp as last\_sync


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developer.myazur.app/peppol/incremental-sync.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
