Emails and attachments
Retrieve synced emails, send emails, create drafts, delete emails, and work with email attachments.
Use the Email API to retrieve synced emails, send new emails, and create drafts from connected mailboxes. Use the File API to upload attachments for sends and drafts, or to download attachments from synced emails.
Before you begin
Section titled “Before you begin”You will need:
- A valid API key
- The
emails:createscope to send emails or create drafts - The
emails:readscope to retrieve emails - The
files:createscope to upload attachments for sends or drafts - The
files:readscope to download synced email attachments - A user-backed API key, or a workspace key whose creator resolves to a user
- A connected Google or Microsoft mail account for the
fromaddress
Send and draft requests use these headers:
Authorization: Bearer $LIGHTFIELD_API_KEYLightfield-Version: 2026-03-01Content-Type: application/jsonRetrieve an email by ID
Section titled “Retrieve an email by ID”Use GET /v1/emails/{id} to fetch a synced email. The response includes the body when the caller has full access.
curl https://api.lightfield.app/v1/emails/$EMAIL_ID \ -H "Authorization: Bearer $LIGHTFIELD_API_KEY" \ -H "Lightfield-Version: 2026-03-01"This response excerpt shows an email visible to the caller:
{ "id": "eml_abc123", "objectType": "email", "createdAt": "2026-05-01T16:00:00.000Z", "updatedAt": "2026-05-01T16:10:00.000Z", "httpLink": null, "fields": { "$subject": { "valueType": "TEXT", "value": "Re: Renewal next steps" }, "$from": { "valueType": "EMAIL", "value": ["alex@customer.com"] }, "$to": { "valueType": "EMAIL", "value": ["sam@example.com"] }, "$cc": { "valueType": "EMAIL", "value": [] }, "$bcc": { "valueType": "EMAIL", "value": [] }, "$privacySetting": { "valueType": "TEXT", "value": null }, "$body": { "valueType": "HTML", "value": "<p>Thanks for the recap...</p>" } }, "relationships": { "$attachment": { "cardinality": "HAS_MANY", "objectType": "file", "values": ["fil_def456"] } }, "accessLevel": "FULL"}Email retrieval is privacy-filtered. With metadata-only access, sensitive fields such as $subject and $body are null, relationships.$attachment is omitted, and accessLevel is METADATA.
List emails
Section titled “List emails”Use GET /v1/emails to fetch a paginated list of emails. Results are privacy-filtered for the caller, and list rows omit fields.$body. Retrieve an email by ID for the body when your access permits it. See the list reference for the filtering and redaction rules.
See List methods for shared pagination and filtering parameters.
curl https://api.lightfield.app/v1/emails \ -H "Authorization: Bearer $LIGHTFIELD_API_KEY" \ -H "Lightfield-Version: 2026-03-01"Send an email directly
Section titled “Send an email directly”Use POST /v1/emails/send to send a new email from the connected mailbox for from.
curl https://api.lightfield.app/v1/emails/send \ -X POST \ -H "Authorization: Bearer $LIGHTFIELD_API_KEY" \ -H "Lightfield-Version: 2026-03-01" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: send-renewal-123" \ -d '{ "from": "sam@example.com", "to": ["alex@customer.com"], "subject": "Renewal next steps", "messageBody": { "contentType": "TEXT", "content": "Hi Alex, here are the next steps..." } }'A successful response returns when the provider accepts the send:
{ "sentAt": "2026-05-01T16:06:00.000Z"}Request fields
Section titled “Request fields”The example shows a plain-text send. Use the send reference for required fields, recipient limits, HTML bodies and the complete attachment schema. The draft reference lists which fields can be omitted for a draft.
Create a draft directly
Section titled “Create a draft directly”Use POST /v1/emails/draft to create a draft in the connected mailbox for from. Draft requests use the same shape as POST /v1/emails/send: from, to, cc, bcc, subject, messageBody, and attachments.
Include from and at least one populated recipient, subject, body or attachment field. A body containing only from returns 400. Use the draft reference for the complete field contract; recipient and attachment limits match sends.
curl https://api.lightfield.app/v1/emails/draft \ -X POST \ -H "Authorization: Bearer $LIGHTFIELD_API_KEY" \ -H "Lightfield-Version: 2026-03-01" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: draft-renewal-123" \ -d '{ "from": "sam@example.com", "to": ["alex@customer.com"], "subject": "Renewal next steps", "messageBody": { "contentType": "TEXT", "content": "Hi Alex, here are the next steps..." } }'A successful response returns when the provider creates the draft:
{ "draftedAt": "2026-05-01T16:06:00.000Z"}Upload attachments for sends and drafts
Section titled “Upload attachments for sends and drafts”Attachments are completed file IDs from the file upload lifecycle. For email attachments, use purpose: "email_attachment" when creating the upload session.
curl https://api.lightfield.app/v1/files \ -X POST \ -H "Authorization: Bearer $LIGHTFIELD_API_KEY" \ -H "Lightfield-Version: 2026-03-01" \ -H "Content-Type: application/json" \ -d '{ "purpose": "email_attachment", "filename": "renewal-summary.pdf", "mimeType": "application/pdf", "sizeBytes": 240000 }'After uploading and completing the file, pass the file ID in attachments on a send or draft request:
{ "from": "sam@example.com", "to": ["alex@customer.com"], "subject": "Renewal summary", "messageBody": { "content": "<p>Attached is the summary.</p>" }, "attachments": ["fil_abc123"]}Limits: maximum 5 attachments per send or draft. Gmail allows up to 20 MB combined raw attachment size; Outlook allows up to 3 MB per attachment. The email_attachment upload purpose accepts up to 20 MB per file, but sending or creating a draft applies the sender’s provider limits. A successful upload does not guarantee the file can be sent from every mailbox. These limits are decimal: 1 MB is 1,000,000 bytes. Attachment IDs must be completed File API uploads in the same workspace.
Download attachments from synced emails
Section titled “Download attachments from synced emails”Synced emails return attachment file IDs in relationships.$attachment on GET /v1/emails/{id}. Each value is a completed file ID (fil_...) pointing at a Document in the File API.
Read the attachment IDs from the email response, then request a temporary download URL for each file:
curl https://api.lightfield.app/v1/emails/$EMAIL_ID \ -H "Authorization: Bearer $LIGHTFIELD_API_KEY" \ -H "Lightfield-Version: 2026-03-01"Use Get a file download URL with one of the IDs from relationships.$attachment.values:
curl https://api.lightfield.app/v1/files/$FILE_ID/url \ -H "Authorization: Bearer $LIGHTFIELD_API_KEY" \ -H "Lightfield-Version: 2026-03-01"A successful response looks like:
{ "url": "https://...", "expiresAt": "2026-05-01T17:00:00.000Z"}Download the returned URL before expiresAt using the file download step. Request a new URL if it expires.
For synced email attachments, Lightfield fetches the bytes from the remote email provider on first download, caches them, and returns a signed URL. If the mailbox that synced the attachment is disconnected or needs reconnecting, the download returns 400 with code mail_attachment_mailbox_disconnected until the mailbox owner reconnects it in Lightfield.
If the request returns 502 with code mail_attachment_provider_unavailable, retry once at most, then skip the attachment and continue. To get the file now, open the original email in Gmail or Outlook.
After three HTTP 5xx responses from the provider for the same attachment without a successful fetch, Lightfield stops asking the provider for an hour. During that time, the request returns the same 502 immediately, and message says about how many minutes are left. If you see that message, skip the retry. Network failures, rate limits and permission errors don’t count toward the cutoff.
Idempotency
Section titled “Idempotency”POST /v1/emails/send and POST /v1/emails/draft support the Idempotency-Key header.
Use the same key when retrying the same send or draft creation after a timeout. Mail operations call a remote email provider, and those providers do not natively support Lightfield idempotency keys. Lightfield applies the key on a best-effort basis before and after the remote call.
See Idempotency for general retry behavior and conflict handling.
Common errors
Section titled “Common errors”These errors can come from email send/draft requests or attachment downloads through GET /v1/files/{id}/url. Attachment provider failures return 502 with a code; the other statuses use the operation’s standard error envelope.
| Status | Code | Meaning |
|---|---|---|
400 | mail_no_connected_account | from is not a connected mail account that can send or create drafts. |
400 | mail_reconnect_required | Connected account is missing required scopes. Reconnect it. |
400 | mail_send_failed | Mail provider rejected the send or draft creation. |
400 | mail_attachment_not_found | Attachment ID is missing, duplicated, or not an eligible upload. |
400 | mail_attachment_empty | Attachment file is 0 bytes. Re-upload via the Files API and verify the upload completed before attaching. |
400 | mail_attachment_mailbox_disconnected | Source mailbox is disconnected. Owner must reconnect. |
502 | mail_attachment_provider_unavailable | The provider could not fetch the attachment. See synced email attachments. |
400 | file_too_large | Attachment exceeds the upload cap or sender’s provider limit: Gmail allows 20 MB combined; Outlook allows 3 MB per attachment. |
400 | invalid_configuration | Attachment downloads unsupported for this workspace or provider. |
403 | n/a | User actor required, or provider denied attachment access. |
404 | n/a | Synced attachment not found or not accessible. |
429 | n/a | Provider rate-limited the request. Retry later. |
503 | n/a | Provider temporarily unavailable. |
See Errors for the standard error envelope.
End-to-end flow
Section titled “End-to-end flow”- If you need an attachment, upload and complete it with
purpose: "email_attachment". Check the selected mailbox’s provider limits before sending. - Choose send to deliver a new message, or draft to create editable work in the connected mailbox.
- Save a unique
Idempotency-Keyfor that intended operation. Reuse it when retrying the same request; see Idempotency. - Check the returned
sentAtordraftedAt. For a synced attachment download instead, follow Download attachments from synced emails.
Log a past email
Section titled “Log a past email”Use Log an email for history that a connected mailbox will not sync, such as an export from your previous CRM. Logging creates a CRM record; it does not send a message or cancel a sequence enrollment. It requires emails:create.
Choose an email sent in the past with at least one workspace member and one external participant. Replace sam@example.com below with a workspace member’s address and use the original message’s details. Exclude personal and non-sales mail before importing.
curl https://api.lightfield.app/v1/emails/log \ -H "Authorization: Bearer $LIGHTFIELD_API_KEY" \ -H "Lightfield-Version: 2026-03-01" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: import-renewal-email-001" \ -d '{ "fields": { "$sentAt": "2026-05-01T16:06:00.000Z", "$from": "sam@example.com", "$to": ["alex@customer.com"], "$subject": "Renewal next steps", "$body": { "text": "Hi Alex, the renewal review is on Tuesday." } }, "headers": { "Message-ID": "<renewal-001@example.com>" }, "autoCreateRecords": false }'The API returns the logged email. Save its id as EMAIL_ID, then retrieve it and check fields.$sentAt and the participant fields. Inspect accessLevel before expecting the subject or body. Privacy defaults to the most permissive setting among the participants’ connected accounts, or METADATA when none applies. Set $privacySetting only when you intend to override that policy.
Keep the source email’s Message-ID in headers. A duplicate ID returns 409 and writes nothing; check whether that email was already imported rather than generating another ID to bypass the conflict. Reuse the original idempotency key when retrying an uncertain request. To preserve threads, pass the original In-Reply-To and References headers, or use a stable $threadId grouping key. Setting $threadId overrides header-derived threading.
The example disables automatic record creation. Set autoCreateRecords: true only when you want the post-create sync to create accounts and contacts for unknown external participants. List results include emails linked to a non-trashed account, so a missing row in the email list does not by itself show that logging failed.
Delete and restore an email
Section titled “Delete and restore an email”Delete an email moves an email to the trash, whether it was synced from a connected mailbox or logged through the API. It requires emails:delete, and the caller must be a participant on the email or a workspace owner. A deleted synced email stays in the trash when its mailbox syncs again.
Use an email ID from retrieving or listing emails, or the ID returned by the logging request:
curl "https://api.lightfield.app/v1/emails/$EMAIL_ID" \ -X DELETE \ -H "Authorization: Bearer $LIGHTFIELD_API_KEY" \ -H "Lightfield-Version: 2026-03-01"A successful response returns the deleted email record. Check that its id matches the record you intended to trash. If the request is refused, check that the key has emails:delete and that the caller is a participant on the email or a workspace owner before retrying.
To recover that email, call Restore an email with emails:restore:
curl "https://api.lightfield.app/v1/emails/$EMAIL_ID/restore" \ -X POST \ -H "Authorization: Bearer $LIGHTFIELD_API_KEY" \ -H "Lightfield-Version: 2026-03-01"The response returns the restored record. Retrieve it by the same ID to verify it is readable again. Restoring an email that is already active returns the existing record unchanged. For a 403, check the key’s scope and caller access. For a 404, confirm the ID and workspace before retrying.
Next steps
Section titled “Next steps”- File uploads: upload files that can be used as email attachments.
- Scopes: learn which scopes to grant to your API key.
- API Reference: full endpoint reference for email and other resources.
Related documentation
Section titled “Related documentation”- In the app: connect a mailbox and write or reply to email. API send and draft calls create new messages; the app’s reply procedure is separate.
- Endpoint contracts: Email and File.