Business API
Generate PDF
Request and response reference for POST /api/v1/generate-pdf
Endpoint
POST https://sheetstolabels.com/api/v1/generate-pdf
Content-Type: application/json
Authorization: Bearer <api_key>Request body
{
"templateId": "custom-1234567890",
"variables": {
"code": "ag193",
"qrUrl": "https://example.com/ag193",
"name": "Test Ambassador"
}
}| Field | Required | Description |
|---|---|---|
templateId | Yes | A cloud-synced custom template owned by the API key account |
variables | No | String, number, or boolean values used by template fields and {{token}} expressions |
Successful response
HTTP/1.1 200 OK
Content-Type: application/pdf
Content-Disposition: attachment; filename="card-ag193.pdf"
X-Request-Id: 6d70...
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 99The response body is the PDF binary. Each generated PDF page consumes one credit.
JavaScript example
import { writeFile } from 'node:fs/promises';
const response = await fetch('https://sheetstolabels.com/api/v1/generate-pdf', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.SHEETS_TO_LABELS_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ templateId, variables }),
});
if (!response.ok) {
const problem = await response.json();
throw new Error(`${problem.code}: ${problem.detail}`);
}
const pdf = Buffer.from(await response.arrayBuffer());
await writeFile('card-ag193.pdf', pdf);