API & Webhook Integration

Generate Documents using Webhooks & APIs

Docupilot allows you to simplify your document generation process by integrating with other systems through Unauthenticated API endpoints which can also be configured as Webhooks in other applications.

Creating an API Endpoint

To create an API Endpoint, follow these steps:

  • Click on the Create tab to access the Create Document view and select API Integrations from the left sidebar.

Create an API Endpoint
  • Click on Create API Endpoint button to create the Url for document generation.

API Integration

When data is sent to the API Endpoint, it generates a Document and sends it to configured delivery locations. If no deliveries are configured, then it will return a secure file URL to download the generated document. This secure URL is valid for 24 hours by default which can be customized under Data Retention Preferences.

If you want to download the generated document along with triggering deliveries you need to append download=true query parameter in the URL.

If you want to receive the generated document as a file in response, append download=file query parameter in the URL. This will include the secure file URL in the Content-Location response header. If you do not prefer the secure file URL to be created, send an additional query parameter includeUrl=false. This will not return the Content-Location header in the response.

Using the API Endpoint

The API Endpoint can be configured in various locations – Ex: Configure it as a Webhook in your CRM, or configure it as a Webhook in your the Forms/Survey software you use, or configure this URL inside your custom built application, and send data to it.

For example, if this is your template:

Sample Template
Hello {{name}},

{{email}}
{{address}} {{state}} {{country}}

You should send a POST request to the API Endpoint, with Content-Type as application/json and body with JSON payload structured like in the example below:

Sample Request
Method: POST
URL: https://api.docupilot.app/documents/create/{org_unique}/{template_unique}/

Headers:
Content-Type: application/json

Body:
{
    "name":"John",
    "email":"[email protected]",
    "address":"XYZ Street",
    "state":"CA",
    "country":"USA"
}

Please note that the tokens (merge fields) defined in the template should match the keys in the webhook data.

Sample response when at-least 1 delivery configured:

{
    "status": "success",
    "data": null
}

Sample response with no deliveries configured -or- with download=true query parameter

{
    "status": "success",
    "data": {
        "file_url": "https://docupilot-documents.s3.amazonaws.com/temp/1a2cadd4-33f7-4f0c-9d9a-3e87803d3e7b/contract.pdf?AWSAccessKeyId=AKIAJTKZBQI56EOPGLFQ&Signature=BHG3mejXO3f1ymBcZVjMB04Sr6U%3D&Expires=1530277229",
        "file_name": "contract.pdf"
    }
}

Sample response when download=file query parameter is appended

Returns the File in Body
Response includes Content-Location in Header

To avoid creating the Secure file URL, add the includeUrl=false parameter to the API Endpoint, which will remove the Content-Location from the API response header.

Quickstart with a CURL Script

The API Integration tab shows an example CURL request for the respective template.

Sample CURL Script

Python

import requests

# update your API Endpoint URL here
api_endpoint = "https://api.docupilot.app/documents/create/46ac75c3/5e7d03ec"

payload = {
  "customer_name":"John",
  "customer_email":"[email protected]",
  "line_items":[
    {
      "description":"Design",
      "quantity":1,
      "price":"230"
    },
    {
      "description":"Development",
      "quantity":4,
      "price":"130"
    }
  ]
}
headers = {
  'Content-Type': "application/json"
}

response = requests.post(api_endpoint, data=payload, headers=headers)

print(response.text)

Deleting the API Endpoint

To delete the API Endpoint, click the Delete button available on the right side of the API Integrations section.

Deleting API Endpoint

To create or delete these links, users must have Manage or Write permissions on the templates. Please note that deleting the API Endpoint link will also remove the link created for Data Capture Form.

Last updated

Was this helpful?