Skip to main content
Automatically generate or fetch a PDF and attach it to a record in Twenty. This is commonly used to create quotes, invoices, or reports that are linked to Companies, Opportunities, or other objects.

Overview

This workflow uses a Manual Trigger so users can generate a PDF on demand for any selected record. A Logic Function handles:
  1. Downloading the PDF from a URL (from a PDF generation service)
  2. Uploading the file to Twenty
  3. Creating an Attachment linked to the record

Prerequisites

Before setting up the workflow:
  1. Create an API Key: Go to Settings → APIs and create a new API key. You’ll need this token for the logic function.
  2. Set up a PDF generation service (optional): If you want to dynamically generate PDFs (e.g., quotes), use a service like Carbone, PDFMonkey, or DocuSeal to create the PDF and get a download URL.

Step-by-Step Setup

Step 1: Configure the Trigger

  1. Go to Workflows and create a new workflow
  2. Select Manual Trigger
  3. Choose the object you want to attach PDFs to (e.g., Company or Opportunity)
With a Manual Trigger, users can run this workflow using a button that appears on the top right once a record is selected, to generate and attach a PDF.

Step 2: Add a Logic Function

  1. Add a Code action (logic function)
  2. Create a new function with the code below
  3. Configure the input parameters

Input Parameters

ParameterValue
companyId{{trigger.object.id}}
If attaching to a different object (Person, Opportunity, etc.), rename the parameter accordingly (e.g., personId, opportunityId) and update the logic function.

Logic Function Code

Step 3: Customize for Your Use Case

To attach to a different object

Replace targetCompanyId with the appropriate field:
ObjectField Name
CompanytargetCompanyId
PersontargetPersonId
OpportunitytargetOpportunityId
Custom ObjecttargetYourCustomObjectId
Update both the function parameter and the variables.data object in the attachment mutation.

To use a dynamic PDF URL

If using a PDF generation service, you can:
  1. First make an HTTP Request action to generate the PDF
  2. Pass the returned PDF URL to the logic function as a parameter

Step 4: Test and Activate

  1. Save the workflow
  2. Navigate to a Company record
  3. Click the menu and select your workflow
  4. Check the Attachments section on the record to verify the PDF was attached
  5. Activate the workflow

Combining with PDF Generation Services

For creating dynamic quotes or invoices:

Example: Generate Quote → Attach PDF

StepActionPurpose
1Manual Trigger (Company)User initiates on a record
2Search RecordGet Opportunity or line item details
3HTTP RequestCall PDF generation API with record data
4Serverless FunctionDownload and attach the generated PDF
  • Carbone - Template-based document generation
  • PDFMonkey - Dynamic PDF creation from templates
  • DocuSeal - Document automation platform
  • Documint - API-first document generation
Each service provides an API that returns a PDF URL, which you can then pass to the logic function.

Troubleshooting

IssueSolution
”Failed to download PDF”Check the PDF URL is accessible and returns a valid PDF
”Upload failed”Verify your API key is valid and has write permissions
”Attachment creation failed”Ensure the object ID field name matches your target object