Protokol DMS is a built-in integration for storing, managing, and converting
files in your Protokol project. It includes a template document engine, file
conversion utilities, and a full media library.
Overview
File storage — upload, download, and organize files in project libraries
Document templates — create, version, and render documents using Go text/template
PDF generation — convert HTML to PDF with template data, fill PDF forms
Data conversion — bidirectional conversion between JSON, CSV, and Excel
EXIF extraction — extract metadata from image files
Workflow events — react to file upload, download, and deletion events
import{DMS}from"@ptkl/sdk/beta"constdms=newDMS()// List filesconstfiles=awaitdms.list({path:"/invoices"})// Download a file (returns Blob)constcontent=awaitdms.download("invoices/2024/invoice-001.pdf")// Get file with encoding (e.g. "base64")constdata=awaitdms.getMedia("invoices/2024/invoice-001.pdf","base64")
# List filescurl-XPOSThttps://lemon.protokol.io/luma/integrations/v3/dms/media/list\-H"Authorization: Bearer $TOKEN"\-H"Content-Type: application/json"\-d'{ "path": "/invoices" }'# Download a filecurl-XPOSThttps://lemon.protokol.io/luma/integrations/v3/dms/media/download\-H"Authorization: Bearer $TOKEN"\-H"Content-Type: application/json"\-d'{ "key": "invoices/2024/invoice-001.pdf" }'\--outputinvoice.pdf
Directories
import{DMS}from"@ptkl/sdk/beta"constdms=newDMS()// List directoriesconstdirectories=awaitdms.dirs("/invoices")// Create a directoryawaitdms.createDir("/invoices/2024")// Delete a directoryawaitdms.deleteDir("/invoices/old")
Convert HTML to PDF using the Chrome rendering engine. Supports Go text/template
syntax in the HTML — pass a data map to inject values before conversion.
import{DMS}from"@ptkl/sdk/beta"constdms=newDMS()// Simple HTML to PDF (inline HTML)constpdf=awaitdms.html2pdf({input_html:"<h1>Invoice #123</h1><p>Total: $500</p>",output_pdf:true,})// HTML template with data injectionconstpdf2=awaitdms.html2pdf({input_html:"<h1>{{.Title}}</h1><p>Amount: {{.Amount}} RSD</p>",data:{Title:"Invoice #456",Amount:"15000"},output_type:"base64",})// From a file in the media library, save result backconstpdf3=awaitdms.html2pdf({input_path:"templates/invoice.html",data:{CustomerName:"Acme Corp",InvoiceNumber:"INV-001"},output_path:"generated/invoices",output_file_name:"INV-001",replace:true,})
HTML templates use Go text/template syntax, not Mustache.
Use {{.FieldName}} to inject values, {{range .Items}} for loops,
and {{if .Condition}} for conditionals. See
Go template documentation for full syntax.
import{DMS}from"@ptkl/sdk/beta"constdms=newDMS()constfilled=awaitdms.fillPdf({input_path:"templates/application-form.pdf",output_path:"generated/forms",output_file_name:"filled-form",form_data:{full_name:"John Doe",date:"2024-03-15",total:"1500.00",},})// Or with typed form structureconstfilled2=awaitdms.fillPdf({input_path:"templates/application-form.pdf",output_pdf:true,forms:[{textfield:[{name:"full_name",value:"John Doe"},{name:"address",value:"123 Main St"},],checkbox:[{name:"agree_terms",value:true},],datefield:[{name:"sign_date",value:"2024-03-15"},],}],})
Create, manage, and version structured documents. Document template content uses
Go text/template syntax for dynamic rendering.
Template Engine
Document templates use Go text/template, not Mustache or Handlebars.
Use {{.FieldName}} to reference data fields. Dot access, range loops,
conditionals, and pipes are all supported.
Render a stored document template with data. Fetches the template, applies
Go text/template rendering with the provided data map, and returns the
rendered content.
import{DMS}from"@ptkl/sdk/beta"constdms=newDMS()constresult=awaitdms.generateDocument({path:"templates/invoice",variant:"default",data:{CompanyName:"Acme Corp",Number:"INV-001",Items:[{Name:"Widget A",Qty:10,Price:"100.00"},{Name:"Widget B",Qty:5,Price:"200.00"},],Total:"2000.00",},})console.log(result.data.content)// rendered HTML string
The DMS publishes lifecycle events that can trigger workflows:
Event
When
integration.dms.file.uploaded
File uploaded to DMS
integration.dms.file.downloaded
File downloaded from DMS
integration.dms.file.removed
File deleted from DMS
integration.dms.dir.removed
Directory removed from DMS
Permissions
Permission
Description
use
Basic DMS access
read
Read and list files
library_edit
Manage library structure
delete
Delete files
upload
Upload files
create_document
Create template documents
delete_document
Delete template documents
read_documents
View template documents
edit_document
Edit template documents
utilities
Use conversion and extraction utilities
Using in Platform Functions
module.exports=asyncfunction({$sdk,$input,response}){const{DMS}=$sdk.version("0.10")constdms=newDMS()// Generate a document from template with dataconstrendered=awaitdms.generateDocument({path:"templates/invoice",data:{CompanyName:$input.body.company,Number:$input.body.invoice_number,Amount:$input.body.amount,},})// Convert to PDF and saveconstpdf=awaitdms.html2pdf({input_html:rendered.data.content,output_path:"generated/invoices",output_file_name:$input.body.invoice_number,replace:true,})response.json({success:true,pdf:pdf.data})}
SDK Reference
import{DMS}from"@ptkl/sdk/beta"// Or via the Integrations facadeimport{Integrations}from"@ptkl/sdk/beta"constintegrations=newIntegrations()constdms=integrations.getDMS()