Invoice Attachments
Attach supporting documents to invoices for complete record keeping and audit trails
Invoice attachments enable you to store supporting files directly with your invoices—such as receipts, contracts, purchase orders, delivery confirmations, or detailed breakdowns. By attaching files to invoices, you maintain complete documentation, simplify audits and compliance, and provide customers with all relevant information in one place. Attachments are stored securely and can be accessed programmatically or shared via invoice payment links.
Common Use Cases
- Attach vendor receipts for expense reimbursement invoices
- Include signed contracts or service agreements with invoices
- Attach customer purchase order documents for reference
Invoice attachments are file objects linked to invoices via invoice_id. Each attachment
includes metadata like filename, file type, size, and a secure download URL. Attachments
support any file type and are automatically included when invoices are expanded.
Prerequisites
Before working with invoice attachments, ensure you have:
Create invoices
Invoices must exist before you can attach files to them.
Understand invoices
Learn about invoice creation and management before working with attachments.
Uploading Invoice Attachments
Create invoices with attachments using base64-encoded data URIs.
File encoding requirements:
- Files must be base64-encoded as data URIs
- Format:
data:{mime_type};base64,{base64_content} - Example:
data:application/pdf;base64,JVBERi0xLjQKJ... - Supported for all file types
What happens when creating invoices with attachments:
- Invoice is created with attached files
- File content is uploaded and stored securely
- Attachment metadata is created (filename, type, size)
- Attachments are available immediately via the invoice for presentment
Retrieving Invoice Attachments
Access attachments through the invoice object or query attachments directly.
Query attachments across invoices
Search for specific attachments across all invoices:
# Find all PDF receipts
receipts = pl.InvoiceAttachment.filter_by(
q='type == "application/pdf" && attrs[category] == "receipt"',
order_by="desc(created_at)"
).all()
print(f"Found {len(receipts)} PDF receipts")Download attachment files
Use the url field to download attachment content:
import os
import requests
attachment = pl.InvoiceAttachment.get("file_abc123")
print(f"Download file from: {attachment.url}")
response = requests.get(attachment.url, headers={
"Authorization": f"Bearer {os.environ.get('PAYLOAD_API_KEY')}"
})
with open(f"./{attachment.filename}", "wb") as f:
f.write(response.content)
print(f"File saved as {attachment.filename}")URL Authentication: Attachment download URLs require authentication using your API key in
the Authorization header. URLs are time-limited for security and expire after a period of
inactivity.
Managing Attachments
Remove or replace invoice attachments.
Delete attachments
Replace attachments
To replace a file, delete the old attachment and upload a new one:
import base64
def file_to_data_uri(file_path, mime_type):
with open(file_path, "rb") as f:
base64_file = base64.b64encode(f.read()).decode("utf-8")
return f"data:{mime_type};base64,{base64_file}"
attachment = pl.InvoiceAttachment.get("file_old123")
attachment.delete()
file_data_uri = file_to_data_uri("./receipt_v2.pdf", "application/pdf")
pl.InvoiceAttachment.create(
invoice_id="inv_abc123",
file={"data_uri": file_data_uri},
filename="receipt_v2.pdf",
description="Updated receipt - corrected amount",
type="pdf",
attrs={
"version": 2,
"replaces": "file_old123",
"reason": "Amount correction"
}
)
print("Attachment replaced")Schema Reference
Fields relevant to invoice attachments:
InvoiceAttachment Fields
id^file_[A-Za-z0-9]+$invoice_id ID of Invoice^None_[A-Za-z0-9]+$filenamedescriptiontypesizeurlattrsInvoice Attachment Reference
attachmentsInvoiceAttachmentNext Steps
Enhance your invoice management with additional features
Manage Invoice Workflow
Build detailed invoices with line items using Creating Invoices, track invoice lifecycle and status changes with Invoice Statuses, and automate recurring invoice generation with Billing Schedules.
Process Invoice Payments
Accept payments against invoices with Payment API, send payment links to customers with Payment Requests, and enable autopay for recurring billing with Automatic Payments.
Track and Report
Monitor attachment upload events with Webhook Events, generate comprehensive invoice reports with Reporting Overview, and analyze payment data with Transaction Reports.
Related articles
- Creating Invoices - Build professional invoices with line items
- Invoice Statuses - Understanding invoice lifecycle
- Payment API - Process invoice payments
- File Uploads - Working with file uploads in Payload
- Webhook Events - Monitor invoice and attachment events
- Invoice API Reference - Complete invoice API documentation