Automate Attaching Signed Documents from Docupilot to Airtable Records

If you are generating documents from Airtable and sending them for eSignature using Docupilot, you can automatically save the completed signed documents back to the matching Airtable records as attachments.

This guide explains how to set this up using Airtable Automations, Docupilot eSignature webhooks, and Airtable scripts.

Overview of the Workflow

The workflow will run as follows:

  1. A document is generated from Airtable using Docupilot.
  2. The document is sent for eSignature.
  3. Docupilot sends status updates to Airtable.
  4. Once the envelope is completed, Airtable downloads the signed document.
  5. The Signed document is attached to the matching Airtable record.

What You’ll Need

Before you begin, make sure you have:

Step 1: Create the Required Fields in Airtable

  • In your Airtable table, create the following fields:
Field Name Field Type Purpose
Record Id Formula Stores the Airtable record ID
Signed Document Attachment Stores the completed signed document
Docupilot EnvelopeId Single line text Stores the Docupilot envelope ID

Step 2: Create an Airtable Automation for eSignature Updates

Step 3: Store the Envelope ID in Airtable

  • In the same Airtable Automation, add a Run Script action.
  • Click on Edit code, clear the content and Paste the below Script
let inputConfig = input.config();

let envelope_pk = inputConfig.docupilot_envelope_id;
let airtable_record_id = inputConfig.airtable_record_id;

let table = base.getTable("REPLACE ME"); /* Provide your base table name in the quotes */

await table.updateRecordAsync(
    airtable_record_id,
    {
        "Docupilot EnvelopeId": envelope_pk
    }
);

Important Note

In the above script, provide your base table name for the table name in the quotes.

  • Once the script is added, create and map the following input variables from the left side tab,
Variable Name Value
docupilot_envelope_id body -> envelope_pk
airtable_record_id body -> recordid
  • This script will capture the envelope ID from Docupilot and save it in the Docupilot EnvelopeId field of the related Airtable record. This envelope ID is required later to download the completed signed document.

Step 4: Create a Webhook for Completed Envelopes

Now, create a new Airtable Automation to listen specifically for completed envelope events.

Step 5: Download the Completed Document and Attach It to Airtable

  • In the automation created in Step 4, add a Run Script action and Paste the below script
let inputConfig = input.config();

let headers = {
    "X-Workspace": "REPLACE ME", /* Provide your Docupilot Workspace ID in the quotes */
    "Authorization": `Basic ${input.secret("docupilot_api_key")}`
};

// Get envelope details
let detailsResponse = await fetch(
    `https://api-us1.docupilot.app/dashboard/esign/envelopes/${inputConfig.envelope_id}/details/`,
    { headers }
);

if (!detailsResponse.ok) {
    throw new Error(`Details failed: ${detailsResponse.status}`);
}

let envelope = await detailsResponse.json();

let table = base.getTable("REPLACE ME"); /* Provide your base table name in the quotes */

let query = await table.selectRecordsAsync({
    fields: ["Docupilot EnvelopeId", "Signed Document"]
});

let record = query.records.find(
    r => r.getCellValue("Docupilot EnvelopeId") == inputConfig.envelope_id
);

if (!record) {
    throw new Error(`No record found for ${inputConfig.envelope_id}`);
}

let existingAttachments =
    record.getCellValue("Signed Document") || [];

// Fetch signed download URLs for all documents
let newAttachments = [];



for (let doc of envelope.documents) {

    console.log(inputConfig.envelope_id);
    console.log(doc.id);

    let downloadResponse = await fetch(
        `https://api-us1.docupilot.app/dashboard/esign/envelopes/${inputConfig.envelope_id}/documents/${doc.id}/download/?response_type=url`,
        { headers }
    );

    console.log(downloadResponse);

    if (!downloadResponse.ok) {
        throw new Error(
            `Download URL failed for document ${doc.id}: ${downloadResponse.status}`
        );
    }

    let downloadData = await downloadResponse.json();

    console.log(`Fetched signed URL for ${doc.document_name}`);

    newAttachments.push({
        url: downloadData.file_url,
        filename: doc.document_name
    });
}

console.log("New attachments:");
console.log(newAttachments);

await table.updateRecordAsync(record.id, {
    "Signed Document": [
        ...existingAttachments,
        ...newAttachments
    ]
});

console.log(`Added ${newAttachments.length} attachments`);

Important Note

In the above, script please provide your Docupilot Workspace ID for X-Workspace and Airtable base table name for table name.

  • Once the script is added, create and map the following input variable and Secret from the left side tab
Type Name Value
Input Variable envelope_id body -> content -> envelope_pk
Secret docupilot_api_key Paste the Generated API Key from Docupilot

This script will:

  • Download the completed signed document from Docupilot
  • Find the matching Airtable record
  • Attach the signed document to the Signed Document field

Step 6: Activate the Automations in Airtable

  • After configuring the workflow, switch both Airtable automations to Active.

This setup helps you manage the document signing process from Airtable and keeps completed signed copies stored against the relevant records.


If you’re stuck or need help with the setup, drop your questions here — happy to assist!