Articles in this section

How to attach completed BoldSign documents to HubSpot records using workflow.

Published:

We can automatically download completed BoldSign documents, upload them to HubSpot Files, and attach them as notes to the associated HubSpot record using HubSpot workflows and custom code actions.

This is a standalone workflow for downloading completed documents sent from the BoldSign web application and attaching them to HubSpot. This workflow is not related to the BoldSign for HubSpot integration.

How It Works

Once the workflow is enabled:

  1. Send a document from BoldSign and include HubSpot Record Id and HubSpot Object Type in tags.
  2. When the document is completed in BoldSign.
  3. BoldSign sends a webhook event to HubSpot.
  4. HubSpot enrolls the associated record into the workflow.
  5. The custom code downloads the completed document.
  6. The file is uploaded to HubSpot Files.
  7. A note is created for the uploaded file.
  8. The note will be associated with the corresponding HubSpot record.

Send Document from BoldSign with Tags

  • When sending the document from BoldSign, need to include the HubSpot Record Id and HubSpot object type in tags.
    image.png

Create a Workflow in HubSpot

  • From your HubSpot account go to automations and select workflow.

  • Create new work flow from scratch

    image.png

  • Select Custom events & external events -> Receive a webhook from an external app.

    image.png

Setup Trigger

  • To setup the trigger, add a webhook.

    image.png

  • Add a webhook name (ex: BoldSign WebHook) and proceed to next. Now copy the generated webhook URL from HubSpot.

  • Before adding a webhook in BoldSign using URL, need to send simple payload to this endpoint to do the mapping for the workflow with HubSpot record.

    BoldSign webhook sends verification data for first time and later it will send complete payload, which is too heavy to do the mapping. So, we are using simple required details with payload to do the mapping.

  • Send a test HTTP POST request to the webhook URL using any API testing tool (for example, Postman) or any system capable of sending HTTP requests, with the sample payload below.

    {
     "event": {
       "id": "111111",
       "eventType": "Completed",
       "environment": "Live"
     },
     "document": {
       "documentId": "x-document-id",
       "status": "Completed",
       "labels": [
         "hubspot-record-id",
         "hubspot-object-type"
       ]
     }
    } 
    

    This is a simple test payload used to map properties and configure the workflow trigger.

  • Review and map the data type for the given payload, to match the properties in HubSpot. It is mandatory to explicitly change the type of labels[0] into number, since it have the HubSpot record id.

    image.png

  • Next, Match your enrollment property, select Associated object and record id label.

    image.png

  • Now successfully completed the webhook setup.

  • Now you should create the webhook in BoldSign using the same webhook URL. Please refer this link to create webhook in BoldSign. You should use the URL generated from HubSpot as webhook target URL in BoldSign.

    image.png

  • Select the webhook and add criteria as per your requirement.
    Example: If document status = Completed → Attach the Completed documents to HubSpot Records.

  • Next, add conditions for eligible records, and proceed to Save and Continue.

    image.png

  • Re-enrollment must be enabled.

    image.png

Without re-enrollment, the same HubSpot record can only execute the workflow once. Future document completion events will not trigger the workflow again.

Setup action

  1. Choose Data Ops and Select custom code.

    image.png

  2. Custom code is only available for node js and python.

    image.png

  3. Initially, you don’t have any secrets. Click Add Secret and add the BoldSign API key and HubSpot token.

    1. Open Secrets Section
      You need to configure secrets before connecting APIs.
    • Navigate to the Secrets section in your HubSpot workflow setup
    • Confirm that no secrets are currently configured
    1. Add a New Secret
      This allows you to securely store API keys and tokens.
      • Click Add Secret
      • Provide a descriptive name for each secret (e.g., BoldSign API Key, HubSpot Token)

    2. Generate BoldSign API Key. Please refer this link to create BoldSign API Key.

    3. Generate Hubspot Access Token. Please refer this link to create HubSpot Access token.

    4. After generating the BoldSign API key and HubSpot access token, add the tokens in Secrets.

      image.png

  4. After Adding secrets, choose the secrets.

    image.png

  5. Select the properties to include it in code from BoldSign Webhook trigger

    image.png

    image.png

this workflow needs hubspot-object-type, document-id, hubspot-record-id and document status

  1. Add below Custom Code, Use the following Node.js script:
const axios = require('axios');
const FormData = require('form-data');
 
exports.main = async (event, callback) => {
  try {
    // INPUTS
    const documentId = event.inputFields.documentid;
    const recordId   = event.inputFields.hubspotrecordid;   
    const objectType = event.inputFields.hubspotobjecttype;
 
    // TOKEN
    const boldsignApiKey = process.env.BOLDSIGN_API_KEY;
    const hubspotToken = process.env.HUBSPOT_ACCESS_TOKEN;
 
    // Association mapping
    const associationMap = {
      contact: 202,
      company: 190,
      deal: 214
    };
 
    const associationTypeId = associationMap[objectType.toLowerCase()];
 
    if (!associationTypeId) {
      throw new Error(`Unsupported objectType: ${objectType}`);
    }
 
    // Step 1: Download PDF
    const boldsignResponse = await axios.get(
      "https://api.boldsign.com/v1/document/download",
      {
        params: { documentId },
        headers: {
          "X-API-KEY": boldsignApiKey
        },
        responseType: "arraybuffer"
      }
    );
 
    // Step 2: Upload to HubSpot Files
    const formData = new FormData();
    formData.append("file", boldsignResponse.data, {
      filename: `document-${documentId}.pdf`,
      contentType: "application/pdf"
    });
 
    formData.append("options", JSON.stringify({
      access: "PRIVATE"
    }));
 
    formData.append("folderPath", "/boldsign-documents");
 
    const uploadResponse = await axios.post(
      "https://api.hubapi.com/files/v3/files",
      formData,
      {
        headers: {
          Authorization: `Bearer ${hubspotToken}`,
          ...formData.getHeaders()
        }
      }
    );
 
    const fileId = uploadResponse.data.id;
    const fileUrl = uploadResponse.data.url;
 
    // Step 3: Create Note + Attach + Associate dynamically
    const noteResponse = await axios.post(
      "https://api.hubapi.com/crm/v3/objects/notes",
      {
        properties: {
             hs_timestamp: new Date().toISOString(),
          hs_note_body: `BoldSign document attached (${objectType})`,
          hs_attachment_ids: fileId
        },
        associations: [
          {
            to: { id: recordId },
            types: [
              {
                associationCategory: "HUBSPOT_DEFINED",
                associationTypeId: associationTypeId
              }
            ]
          }
        ]
      },
      {
        headers: {
          Authorization: `Bearer ${hubspotToken}`,
          "Content-Type": "application/json"
        }
      }
    );
 
    const noteId = noteResponse.data.id;
 
    // OUTPUT
    callback({
      outputFields: {
        fileUrl,
        fileId,
        noteId,
        objectType
      }
    });
 
  } catch (error) {
    console.error(error.response?.data || error.message);
 
    callback({
      outputFields: {
        error: error.message
      }
    });
  }
};
  1. Now Save the workflow and then review and turn on the workflow.

    image.png

  2. Test, review and turn on the workflow.

    image.png

Test the Workflow

  1. Review the workflow configuration.
  2. Now send a test document from BoldSign with HubSpot Record Id and Object type in tags.
  3. Sign and complete the test document to trigger the completion event.
  4. Verify that:
    • The document is downloaded from BoldSign.
    • The file is uploaded to HubSpot Files.
    • A note is created.
    • The document is attached to the note.
    • The note is associated with the correct HubSpot record.
  5. Turn on the workflow.

Example Flow

BoldSign Document Completed
            ↓
BoldSign Webhook Sent
            ↓
HubSpot Workflow Triggered
            ↓
Download Document
            ↓
Upload File to HubSpot
            ↓
Create Note
            ↓
Attach Document
            ↓
Associate with HubSpot Record

Result

The workflow setup is complete.

Whenever a BoldSign document reaches the configured status, the signed document is automatically uploaded to HubSpot, attached to a note, and associated with the corresponding HubSpot record.

Was this article useful?
Like
Dislike
Help us improve this page
Please provide feedback or comments
Access denied
Access denied