Files
Endpoints for managing template files including template source files, assets (CSS, JS, images), and data files.
GET /api/templates/{id}/files
Get all files associated with a template.
Authentication: Required (session)
Pre-blocks: template.lookup(params.id)
Response:
{
"_links": {
"self": { "href": "/api/templates/{id}/files" }
},
"_embedded": {
"inf:template-file": [
{
"id": "file-123",
"filename": "report.html",
"role": "TEMPLATE",
"contentType": "text/html",
"size": 2048,
"templateId": "abc123",
"embedded": true,
"createdAt": "2024-01-15T10:30:00Z",
"_links": {
"self": { "href": "/api/templates/abc123/files/file-123" },
"inf:file-contents": { "href": "/api/templates/abc123/files/file-123/contents" }
}
},
{
"id": "file-456",
"filename": "styles.css",
"role": "ASSET",
"contentType": "text/css",
"size": 512,
"templateId": "abc123",
"embedded": true
}
]
},
"start": 0,
"count": 2,
"total": 2
}
POST /api/templates/{id}/files
Create a new file for the template.
Authentication: Required (session)
Pre-blocks: template.lookup(params.id), permission.template.write(pre.template)
Request Body:
| Field | Type | Required | Description |
|---|---|---|---|
filename | string | Yes | Filename with extension |
contentType | string | No | MIME type |
role | string | Yes | File role: TEMPLATE, ASSET, DATA |
Example Request:
{
"filename": "logo.png",
"contentType": "image/png",
"role": "ASSET"
}
Response:
Returns the created file object with 201 Created status and Location header.
POST /api/templates/{id}/files/_upload
Upload a file to the template with multipart form data.
Authentication: Required (session)
Pre-blocks: template.lookup(params.id), permission.template.write(pre.template)
Request:
Multipart form data with file upload.
Response:
Returns the created file object with 201 Created status.
GET /api/templates/{id}/files/{file}
Get metadata for a specific template file.
Authentication: Required (session)
Pre-blocks: template.lookup(params.id)
Response:
{
"id": "file-123",
"filename": "report.html",
"role": "TEMPLATE",
"contentType": "text/html",
"size": 2048,
"templateId": "abc123",
"embedded": true,
"createdAt": "2024-01-15T10:30:00Z",
"_links": {
"self": { "href": "/api/templates/abc123/files/file-123" },
"inf:file-contents": { "href": "/api/templates/abc123/files/file-123/contents" }
}
}
PUT /api/templates/{id}/files/{file}
Update file metadata (note: files with role TEMPLATE cannot be renamed).
Authentication: Required (session)
Pre-blocks: template.lookup(params.id), permission.template.write(pre.template)
Request Body:
| Field | Type | Description |
|---|---|---|
filename | string | New filename (not allowed for TEMPLATE role files) |
contentType | string | MIME type |
Response:
Returns the updated file object.
DELETE /api/templates/{id}/files/{file}
Delete a file from the template.
Authentication: Required (session)
Pre-blocks: template.lookup(params.id), permission.template.edit(pre.template)
Response:
Returns 204 No Content on successful deletion.
GET /api/templates/{id}/files/{file}/contents
Get the contents of a template file.
Authentication: Required (session)
Pre-blocks: template.lookup(params.id)
Response:
Returns the file contents with appropriate Content-Type header.
PUT /api/templates/{id}/files/{file}/contents
Update the contents of a template file.
Authentication: Required (session)
Pre-blocks: template.lookup(params.id), permission.template.write(pre.template)
Request Body:
Raw file contents (text or binary depending on content type).
Response:
Returns success confirmation after updating file contents.
GET /api/templates/{id}/template-file
Get the primary template file metadata.
Authentication: Required (session)
Pre-blocks: template.lookup(params.id)
Response:
Returns the file object designated as the primary template file.
PUT /api/templates/{id}/template-file
Set which file should be the primary template file.
Authentication: Required (session)
Pre-blocks: template.lookup(params.id), permission.template.write(pre.template)
Request Body:
| Field | Type | Description |
|---|---|---|
templateFileId | string | File ID to set as primary template |
Response:
Returns the updated template object with new templateFileId.