· 11 min read
Automate PDF Archive and Email of Reports via API
End-to-end workflow: raw data → PDF → cloud folder → email attachment, with REST only (generate-document, folders, send-document).
In enterprise applications and SaaS platforms, generating a PDF document is only the first piece of the puzzle. Once the report, invoice, or delivery note is ready, a chain of mandatory actions kicks in: the file must be saved securely in an organized folder structure, made available for future download, and often sent immediately by email to the customer or the administrative department.
Implementing this entire workflow from scratch means writing code to:
- Interface with graphic libraries for PDF rendering.
- Configure and manage storage (local or AWS S3 bucket) including permissions and paths.
- Configure SMTP servers, manage send queues, and ensure emails with heavy attachments do not end up in spam.
In this guide we will show how to automate report archiving and email delivery via API: reduce the entire process to a sequence of REST Web API calls — generation, organized archiving, and delivery — without local storage or dedicated SMTP on your business application.
Flow architecture: generate → archive → send
Instead of overloading your software backend with separate threads for files and SMTP, the modern microservices approach uses specialized API endpoints that work in sequence.
The three key steps:
-
generate-document: takes application data as JSON, injects it into the pre-configured graphic template, and produces the PDF. -
folders: organizes the file in a logical tree on the portal (e.g. Customer reports / July 2026). You passfolderIdto generate-document. -
send-document: takes the newly createddocumentIdand sends the email with attachment (SMTP on the API key or platform default).
Practical guide: implementing the workflow in Node.js
Let’s see how to translate this automation into code. Goal: generate a monthly activity report, archive it in the customer’s folder, and email it to them. Documentation: Web API.
const axios = require('axios');
const API_BASE = 'https://backend.quartzapi.com/index.php?r=api';
const API_KEY = 'TUO_API_KEY_SEGRETA';
const headers = {
Authorization: `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
};
async function eseguiAutomazioneReport() {
try {
// PHASE 0 (optional): create the period folder
const folderRes = await axios.post(
`${API_BASE}/v1-folders/create`,
{ name: 'Clienti — Luglio 2026' },
{ headers }
);
const folderId = folderRes.data.folderId;
// PHASE 1: PDF generation + archive in the folder
console.log('1. Generating the PDF...');
const genResponse = await axios.post(
`${API_BASE}/v1-jobs/generate-document`,
{
templateCode: 'REPORT_ATTIVITA',
folderId,
externalId: 'RPT-TECH-2026-07',
outputFormat: 'pdf',
data: {
cliente: 'Tech Solutions S.r.l.',
mese: 'Luglio 2026',
ore_totali: 45,
dettaglio_attivita: [
{
data: '05/07/2026',
descrizione: 'Refactoring database e indici SQL',
ore: 5
},
{
data: '12/07/2026',
descrizione: 'Sviluppo nuove API di integrazione',
ore: 40
}
]
}
},
{ headers }
);
const documentId = genResponse.data.result.documentId;
const downloadUrl = genResponse.data.result.downloadUrl;
console.log(`→ PDF archived. documentId: ${documentId}`);
console.log(`→ Download: ${downloadUrl}`);
// PHASE 2: send email with attachment
console.log('2. Sending the PDF by email...');
await axios.post(
`${API_BASE}/v1-jobs/send-document`,
{
documentId,
to: ['amministrazione@clientetech.it'],
subject: 'Report Attività Mensile - Luglio 2026',
body:
'Gentile cliente, in allegato trova il report delle attività di Luglio 2026.'
},
{ headers }
);
console.log('→ Email sent successfully!');
} catch (error) {
console.error(
'Workflow error:',
error.response ? error.response.data : error.message
);
}
}
eseguiAutomazioneReport();
Equivalent cURL (generate + send)
# 1) Create folder (save folderId from the response)
curl -X POST "https://backend.quartzapi.com/index.php?r=api/v1-folders/create" \
-H "Authorization: Bearer TUO_API_KEY_SEGRETA" \
-H "Content-Type: application/json" \
-d '{"name":"Clienti — Luglio 2026"}'
# 2) Generate and archive
curl -X POST "https://backend.quartzapi.com/index.php?r=api/v1-jobs/generate-document" \
-H "Authorization: Bearer TUO_API_KEY_SEGRETA" \
-H "Content-Type: application/json" \
-d '{"templateCode":"REPORT_ATTIVITA","folderId":"fld_...","data":{...}}'
# 3) Send email
curl -X POST "https://backend.quartzapi.com/index.php?r=api/v1-jobs/send-document" \
-H "Authorization: Bearer TUO_API_KEY_SEGRETA" \
-H "Content-Type: application/json" \
-d '{"documentId":"doc_...","to":["amministrazione@clientetech.it"],"subject":"Report Luglio 2026"}'
Why eliminate local storage and dedicated SMTP servers?
Moving this process to a specialized API infrastructure gives software houses three immediate benefits:
-
Zero disk space issues (decoupled storage): PDFs do not live on your
application server. No full disks or ad-hoc backups: they stay in the cloud, downloadable with
GET api/v1-documents/download&uid={documentId}. -
Email deliverability: configuring SMTP with SPF, DKIM, and DMARC is complex.
With
send-documentyou use the platform SMTP or the one configured on the API key (portal → Email/SMTP), without a custom mailer in the business app. -
Full traceability: with a unique
documentIdyou can retrieve the file, resend it, or download it without reprocessing the source data.
Conclusions
Automating document processes should not mean heavy code and complex infrastructure. Isolating business logic and leaving graphic formatting, storage, and email routing to the APIs makes SaaS applications leaner, faster, and easier to scale — ideal if you are looking for how to generate and send reports via API or save PDFs in a cloud folder.
Want to automate your application’s reports? QuartzAPI is built to make life easier for software houses. With the public beta you configure templates and cloud folders and test the full generate-and-send flow via API with no upfront costs.
Ready-to-use snippets
v1-folders/create·v1-folders/index(alsotree=1)v1-jobs/generate-documentwithfolderIdv1-jobs/send-document·v1-documents/download- Reference: Web API documentation