IntegrationsSuccess Stories

Downloading Completed Documents from Circularo

Dev Talk

In our previous posts, we discussed securing your webhooks with HMAC and monitoring webhook callbacks with Ngrok.

Now, let’s put those webhooks to work! One of the most common integration requirements is to download a document once it has been fully signed and completed by all involved parties.

By combining Circularo’s real-time feedback via webhooks with our REST API, you can build a seamless “Signed and Archived” pipeline that moves completed documents directly into your local storage, document management system, or cloud drive.

Step 1: Setting up the webhook

To start, you need to tell Circularo to notify your server when a document’s workflow is finished. You can configure this in the Circularo Administration or via the API.

You need to define the following parameters 

  • URL: Your server endpoint (e.g., https://your-api.com/webhooks/circularo)
  • HMAC Secret (optional): (Highly Recommended) Use a secret to verify the request as discussed in our HMAC guide

You’ll want to listen for the documentCompleted events generated by the application. This event triggers only after all participants have signed and the document is finalized.

Note: Circularo will return all events triggered in the application to the defined webhook URL. You, as the integrator, need to implement the filtering logic to pick only the events matching the correct criteria. In this case, all events with “event”: “documentCompleted”

Step 2: Consuming the webhook

When a document is completed, Circularo sends a POST request to your URL. The payload contains the unique documentId. Your first task is to extract this ID:

{
  "documentId": "9ff53f87-e82b-472b-908e-ad1fd298ac58",
  "event": "documentCompleted",
  "actor": "system",
  "timestamp": "2024-06-01T13:10:10.500Z"
}

Step 3: Getting the file details

A “Document” in Circularo is a container that can hold multiple versions or files alongside additional information such as document metadata. To download the actual PDF, you first need to get the identifier for the file using the documentId you just received.

Call the Get Document endpoint: 

GET /api/v1/documents/{documentId}

Response

{
  "results": [
    {
      "documentId": "9ff53f87-e82b-472b-908e-ad1fd298ac58",
      "documentTitle": "My document",
      "documentType": "d_default",
      "_version": 2,
      "pdfFile": {
  "content": "wss3z9nSmSdh4FGTFS8wrUTGwfmtWYplGZ3JjVQKlwN9s2IBfJhhdTCbcbA2pMrv",
        ...
      },
      "workflow": {
        "workflowType": "wf_archive",
        ...
      },
      ...
    }
  ],
  ...
}

The response contains the following important properties:

  • fileHash – Located at results[0].pdfFile.content in the response.
    • The unique file hash (ID) that identifies the document’s content. This hash is used to download the document file
    • Example value: wss3z9nSmSdh4FGTFS8wrUTGwfmtWYplGZ3JjVQKlwN9s2IBfJhhdTCbcbA2pMrv

Step 4: Downloading the file

Once you have the file id, you can fetch the actual binary data that contains the PDF. Circularo provides a dedicated endpoint for file retrieval that supports efficient streaming.

Endpoint: GET /api/v1/files/loadFile/hash/{hash} 

Here is a conceptual flow of how your backend might handle this:

Conclusion

Automating the download process eliminates manual archival work and ensures that your records are always up to date. By listening for documentCompleted, you ensure that you only archive the final, legally binding version of the document, complete with all signatures.

For detailed API specifications and more examples, check out the Circularo Developers Guide.

In our next article, we will have a look at how to initialize Circularo workflow using the Circularo API call – how to add users, setup sequential or parallel flow, add permissions and reminders, and more.

01277