Technical¶
Supported file types¶
File types with merge code support:
docx, xlsm, xlsx
File types without merge code support:
pdf
Components in the package¶
Document Templates uses the following components in Lime CRM:
- Web components
- Web client commands
- Custom endpoints
- Lime Admin config
- Admin CLI
Command-bus integration¶
Document Templates listens to two web client commands. This is useful to know when building a custom create-document flow, because dispatching either of these commands triggers the package's default behavior unless you intercept first.
CreateLimeobjectDialogCommand— dispatched when someone starts the workflow to create a new limeobject. Document Templates uses this to determine whether the template picker dialog should be shown before the create-document dialog.SaveLimeObjectCommand— dispatched when someone tries to save a new lime object after entering all the info. Document Templates uses this to route the save through the custom endpoint so that the document file is generated during lime-object creation.
Internal endpoints¶
List templates¶
GET /template/
Returns all templates that can be used.
Payload:
{
"limetype": null,
"extension": "docx"
}
limetype can be any limetype. When the value is set (not null), this limetype is used to filter for all templates
where this limetype is listed in the Restrict to lime types list in the template configuration in Lime Admin.
extension can only be set to docx.
Response:
Note: The first item in the list is a web client template while the second is a desktop template,
the desktop template would NOT be returned if Use Desktop Templates is unchecked in Lime Admin.
[
{
"extension": "docx",
"id": 59903701,
"last_modified": "2021-05-03T09:37:25.897000",
"mimetype": "application/octet-stream",
"filename": "template example.docx",
"size": 14026,
"storage_type": "sql",
"filetype": 115,
"metadata": {
"tags": [],
"limetypes": [
"project"
],
"locale": "en_US",
"locale_display_name": "English (United States)",
"active": true,
"template_id": "project-example"
}
},
{
"extension": "docx",
"id": 30190701,
"last_modified": "2014-04-28T11:46:18.263000",
"mimetype": "application/octet-stream",
"filename": "desktop template example.docx",
"size": 1725661,
"storage_type": "sql",
"filetype": 113,
"metadata": {
"category": "Sälj",
"name": "desktop template example"
}
}
]
Save template¶
POST /template/
Saves a template.
Payload (Form Data):
options is stringified JSON that, if present, should only contain the key migrate. If migrate is true, the file will be migrated from a desktop to web client template before it is saved.
{
<filename>: <File>
"options": "{migrate:false}"
}
Response:
{ "fileId": 1 }
Delete unused templates¶
DELETE /template/
Deletes all unused document templates. Does not delete desktop templates.
Response:
"x template(s) successfully deleted"
Create document¶
POST /document/<template_id>/
Creates a document from a template.
Payload:
An object containing the values of the create document form. The below example will be different for different CRM systems.
The property configured in Lime Admin as the Document Property should be populated with null since that property will
be populated with the new file generated from the template.
Template merge codes are populated from this data and the relations set on this object (i.e. coworker.email would return the email property of
the coworker with id 19601).
{
"coworker": 19601,
"document": null,
"date": "2021-05-03T07:50:55.098Z",
"person": null,
"description": "test",
"company": null,
"project": null,
"projectactivity": null,
"signing": null
}
Response:
{
"_id": 325001
}
Get template¶
GET /template/<template_id>/
Returns a template.
Response:
A file streamed as application/octet-stream.
Delete template¶
DELETE /template/<template_id>/
Deletes a template.
Note! This deletes the actual template file, not the configuration entry in Lime Admin. This action is non-recoverable!
Response:
No response, returns a HTTP status code 204 on success.
Validate template¶
POST /template/validate/
Validates a template.
Payload (Form Data):
{
<filename>: <File>
}
Response:
If valid:
[]
If invalid:
[
{
"code": <ErrorCode>,
"message": <ErrorMessage>
}
]
ErrorCode can be one of "UnsupportedExtension", "Unparsable" or "LegacyTemplate".
Zombie files¶
Template files are not deleted when a configuration entry is deleted in Lime Admin. This allows for the potential recovery of important documents.