const doc = await client.documents.create({
title: 'API Architecture Diagram',
product: 'lucidchart',
});
console.log(`Document: ${doc.documentId}`);
console.log(`Edit URL: ${doc.editUrl}`);
const importData = {
pages: [{
id: 'page1',
title: 'Main',
shapes: [
{ id: 's1', type: 'rectangle', boundingBox: { x: 100, y: 100, w: 200, h: 80 },
text: 'API Gateway', style: { fill: '#4A90D9' } },
{ id: 's2', type: 'rectangle', boundingBox: { x: 100, y: 300, w: 200, h: 80 },
text: 'Database', style: { fill: '#7B68EE' } },
{ id: 's3', type: 'rectangle', boundingBox: { x: 400, y: 200, w: 200, h: 80 },
text: 'Auth Service', style: { fill: '#50C878' } },
],
lines: [
{ id: 'l1', endpoint1: { shapeId: 's1' }, endpoint2: { shapeId: 's2' },
stroke: { color: '#333', width: 2 } },
{ id: 'l2', endpoint1: { shapeId: 's1' }, endpoint2: { shapeId: 's3' },
stroke: { color: '#333', width: 2, pattern: 'dashed' } },
],
}],
};
await client.documents.import(doc.documentId, importData);
const pages = await client.documents.getPages(doc.documentId);
const pageId = pages[0].id;
await client.pages.updateShape(doc.documentId, pageId, 's1', {
text: 'API Gateway v2',
style: { fill: '#2E86C1', fontSize: 14 },
});
const png = await client.documents.export(doc.documentId, {
format: 'png',
pageIndex: 0,
scale: 2,
crop: true,
});
fs.writeFileSync('diagram.png', png);
console.log('Exported diagram.png');
A successful run produces a Lucidchart document with shapes, connectors, and styling,
then exports a high-resolution PNG. Console output shows the document ID and edit URL.