Retrieving payables is done asynchronously:

  • first, request a snapshot to be created - this will create a new data processing request and put it in a queue;
  • then, poll for the status of this request in intervals of at least 60 seconds - your request is ready when status is "COMPLETE";
  • the snapshot of payables will remain available in cache for several hours, it can be retrieved multiple times.

This asynchronous process is required because payables are data-rich objects that carry a lot of pre-accounting information: accounts, tax codes, line items and analytical fields.

Here is a simplified diagram of the flow:

In more details, these are the steps to follow:

  1. Request an extract ("snapshot") of expenses ("payables") according to your desired criteria by using the Create a snapshot of payables API. This API will respond immediately with an ID - "key" - which will be the reference for your request.

    //Request
    curl --request POST \
         --url https://public-api.spendesk.com/v1/snapshots/payables \
         --header 'accept: application/json' \
         --header 'content-type: application/json' \
         --header 'authorization: Bearer *****' \
         --data '
    {
      "sortBy": "payableDate",
      "sortOrder": "desc",
      "bookkeepingStatus": [
        "exported",
        "exportedManually"
      ],
      "exportedAfter": "2024-01-01T00:00:00Z"
    }
    '
    
    //Response 200
    {
      "query": {
        "bookkeepingStatus": [
          "exported",
          "exportedManually"
        ],
        "exportedAfter": "2024-01-01T00:00:00Z"
        "sortBy": "payableDate",
        "sortOrder": "desc",
      },
      "key": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
      "expireInSeconds": 43200,
      "remainingSeconds": 43200
    }
    
  2. Poll for the results every minute by using the Get a snapshot of payables API and "key" from the previous step.

    curl --request GET \
         --url https://public-api.spendesk.com/v1/snapshots/payables/3fa85f64-5717-4562-b3fc-2c963f66afa6 \
         --header 'accept: application/json' \
         --header 'authorization: Bearer *****'
    
  3. Once you receive a response with status "COMPLETE" in the previous step, your data will be under result.data element. You may need to fetch multiple pages of results (see result.meta) using the same API.

  4. In case you receive a response with status "ERROR" in step 2, stop polling and check your query.