Object Classes Document Template
This technical design describes implementation and API for Object Classes Document Template.
POST /api/object-classes/object_class_id/document-templates/
Creates document template.
Permissions
Requires authentication and object_classes.edit permission.
Request
- URL parameters
| Key | Type | Notes |
|---|---|---|
| object_class_id | pk |
- Body parameters
| Key | Type | Notes |
|---|---|---|
| name | string | |
| description | string | |
| template_file | string | File token |
| allow_on_demand_generation | bool |
- Headers
Content-Type: application/json
Authorization: JWT access_token- Schema
POST /api/object-classes/1/document-templates/
{
"name": "Test Document Template",
"description": "",
"template_file": "9d1b16dc-db37-4631-8469-804c7d4048b2",
"allow_on_demand_generation": true
}Validations
- name
- is string
- is required
- unique (case insensitive) for the given Object Class
- max length is 100
- must be trimmed of white spaces
- description
- is string
- is optional
- max length is 500
- template_file
- is a file type (accepts uploaded file token, see doc)
- is required
- only " .docx " files allowed
- only 1 file is allowed
- validate Jinja template syntax
- validate merge tags:
- related classes
- allow_on_demand_generation
- is bool
Restrictions
- Up to 1000 Document Templates per Object Class can be added, limit is configurable per build.
Response
| Key | Type | Notes |
|---|---|---|
| id | pk | Automatically generated by the backend. |
| name | string | Name of the document template |
| description | string | Description of the document template |
| template_file | integer | Id of the template file |
| allow_on_demand_generation | bool | |
| created_at | datetime | |
| warning | string | |
| created_by | user | |
| modified_at | datetime | |
| modified_by | user | |
| _meta.labels.files | Object | Object containing template files details |
Response _meta.labels.files object
| Key | Type | Notes |
|---|---|---|
| name | string | Template file name with extension |
| url | string | Template file download URL |
| size | string | Template file size in bytes |
| type | string | Template file extension |
- Successful status
201 Created - Response body:
{
"id": 1,
"name": "Test Document Template",
"description": "",
"template_file": 27,
"allow_on_demand_generation" : true,
"warning" : "",
"created_at": "2022-10-13T10:22:33.344172+02:00",
"created_by": {
"id": 2,
"first_name": "John",
"last_name": "Kovalsky",
"username": "john.kovalsky@autologyx.com",
"company_name": "",
"is_deleted": false,
"account_type": "full"
},
"modified_at": "2022-10-13T10:22:33.344193+02:00",
"modified_by": {
"id": 2,
"first_name": "John",
"last_name": "Kovalsky",
"username": "john.kovalsky@autologyx.com",
"company_name": "",
"is_deleted": false,
"account_type": "full"
},
"_meta": {
"labels": {
"files": {
"27": {
"name": "test.docx",
"url": "http://client.testserve/api/object-classes/1/document-templates/1/download/",
"size": "8085",
"type": "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
}
}
}
}
}Errors
| Cause | Response status code | Response message |
|---|---|---|
| Invalid object_class_id in URL | 403 Forbidden | "detail": "You do not have permission to perform this action." |
| name missing | 400 Bad Request | "name": ["This field is required."] |
| name is empty | 400 Bad Request | "name": [ "This field may not be blank." ] |
| name is null | 400 Bad Request | "name": [ "This field may not be null." ] |
| name not unique | 400 Bad Request | "name": ["This field must be unique."] |
| name too long | 400 Bad Request | "name": ["Ensure this field has no more than 100 characters."] |
| description too long | 400 Bad Request | "description": ["Ensure this field has no more than 500 characters."] |
| template_file missing | 400 Bad Request | "template_file": ["This field is required."] |
| template_file is null | 400 Bad Request | "template_file": [ "This field may not be null." ] |
| template_file not docx | 400 Bad Request | "template_file": ["Invalid file type."] |
| allow_on_demand_generation invalid value | 400 Bad Request | "allow_on_demand_generation": ["Must be a valid boolean."] |
| Exceeded max number of templates | 400 Bad Request | "detail": "Limit of 1000 Document Templates has been exceeded.", "error_code": "ERR_LIMIT_EXCEEDED" |
| Document can't be parsed | 400 Bad Request | "error": ["Error while parsing document. Please check the syntax."] |
| Class not related | 400 Bad Request | "error": ["Merge field { name } refers to a Class ID={id} which is not related with Class ID={id}."] |
| Insufficient permissions | 403 Forbidden | "detail": "You do not have permission to perform this action." |
GET /api/object-classes/object_class_id/document-templates/
Returns list of document templates.
Permissions
Requires authentication and object_classes.edit permission.
Request
- Headers
Content-Type: application/json
Authorization: JWT access_token- Schema
GET /api/object-classes/`object_class_id`/document-templates/Response
| Key | Type | Notes |
|---|---|---|
| limit | int | |
| offset | int | |
| total_count | int | Total number of results visible to the user (based on permissions). |
| filtered_count | int | Number of results visible to the user (based on permissions) with filters applied. |
| next | url | Next page URL (null if there is no next page) |
| previous | url | Previous page URL (null if there is no previous page) |
| results | Array | List of results. Described in the next table. |
Response results array
| Key | Type | Notes |
|---|---|---|
| id | pk | Automatically generated by the backend. |
| name | string | Name of the document template |
| description | string | Description of the document template |
| template_file | integer | Id of the template file |
| template_file_name | string | Name of the template file without extension |
| allow_on_demand_generation | bool | |
| warning | string | |
| created_at | datetime | |
| created_by | user | |
| modified_at | datetime | |
| modified_by | user | |
| _meta.labels.files | Object | Object containing template files details |
- Successful status
200 OK - Response body schema
{
"limit": 100,
"offset": 0,
"filtered_count": 1,
"total_count": 1,
"next": null,
"previous": null,
"results": [
{
"id": 3,
"name": "Document Templates Test",
"description": "",
"template_file": 29,
"template_file_name": "test",
"allow_on_demand_generation": true,
"warning": "",
"created_at": "2022-10-17T11:29:01.694549+02:00",
"created_by": {
"id": 2,
"first_name": "John",
"last_name": "Kovalsky",
"username": "john.kovalsky@autologyx.com",
"company_name": "",
"is_deleted": false,
"account_type": "full"
},
"modified_at": "2022-10-17T11:29:01.694569+02:00",
"modified_by": {
"id": 2,
"first_name": "John",
"last_name": "Kovalsky",
"username": "john.kovalsky@autologyx.com",
"company_name": "",
"is_deleted": false,
"account_type": "full"
},
"_meta": {
"labels": {
"files": {
"29": {
"name": "test.docx",
"url": "/api/object-classes/1/document-templates/3/download/",
"size": "152199",
"type": "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
}
}
}
}
}
]
}Sorting
| Parameter | Example | Notes |
|---|---|---|
| id | {build}/api/object-classes/id/document-templates/?ordering=id | Ascending |
| id | {build}/api/object-classes/id/document-templates/?ordering=-id | Descending (-) |
| name | {build}/api/object-classes/id/document-templates/?ordering=name | Ascending |
| name | {build}/api/object-classes/id/document-templates/?ordering=-name | Descending (-) |
| allow_on_demand_generation | {build}/api/object-classes/id/document-templates/?ordering=allow_on_demand_generation | Ascending |
| allow_on_demand_generation | {build}/api/object-classes/id/document-templates/?ordering=-allow_on_demand_generation | Descending (-) |
| created_at | {build}/api/object-classes/id/document-templates/?ordering=created_at | Ascending |
| created_at | {build}/api/object-classes/id/document-templates/?ordering=-created_at | Descending (-) |
| modified_at | {build}/api/object-classes/id/document-templates/?ordering=modified_at | Ascending |
| modified_at | {build}/api/object-classes/id/document-templates/?ordering=-modified_at | Descending (-) |
Filtering
Please check ALX API standards for predicates available per type.
| Parameter | Type |
|---|---|
| uuid | uuid |
| name | string |
| template_file_name | string |
| allow_on_demand_generation | bool |
| warning | string |
| created_at | datetime |
| created_by | user |
| modified_at | datetime |
| modified_by | user |
Errors
| Error | Response code | Message |
|---|---|---|
| Wrong ordering value | 400 Bad Request | "ordering": ["Select a valid choice. {value} is not one of the available choices."] |
GET /api/object-classes/object_class_id/document-templates/document_template_id/
Permissions
Requires authentication and document-templates.edit permission.
Request
- URL parameters
| Key | Type | Notes |
|---|---|---|
| object_class_id | id | |
| document_template_id | id |
- Headers
Content-Type: application/json
Authorization: JWT access_token- Schema
GET /api/object-classes/`task_group_templates_id`/document-templates/`document_template_id`Response
| Key | Type | Notes |
|---|---|---|
| id | pk | Automatically generated by the backend. |
| name | string | Name of the document template |
| description | string | Description of the document template |
| template_file | integer | Id of the template file |
| allow_on_demand_generation | bool | Id of the template file |
| warning | string | Id of the template file |
| created_at | datetime | |
| created_by | user | |
| modified_at | datetime | |
| modified_by | user | |
| _meta.labels.files | Object | Object containing template files details |
Response example
- Status
200 OK - Body
{
"id": 1,
"name": "Test Document Template",
"description": "",
"template_file": 1,
"allow_on_demand_generation" : true,
"warning" : "",
"created_at": "2022-10-13T10:22:33.344172+02:00",
"created_by": {
"id": 2,
"first_name": "John",
"last_name": "Kovalsky",
"username": "john.kovalsky@autologyx.com",
"company_name": "",
"is_deleted": false,
"account_type": "full"
},
"modified_at": "2022-10-13T10:22:33.344193+02:00",
"modified_by": {
"id": 2,
"first_name": "John",
"last_name": "Kovalsky",
"username": "john.kovalsky@autologyx.com",
"company_name": "",
"is_deleted": false,
"account_type": "full"
},
"_meta": {
"labels": {
"files": {
"27": {
"name": "test.docx",
"url": "http://client.testserve/api/object-classes/1/document-templates/1/download/",
"size": "8085",
"type": "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
}
}
}
}
}Sorting
Not supported
Filtering
Not supported
Errors
| Error | Response code | Message |
|---|---|---|
A non-existent document_template_id was given | 404 Not Found | "detail": "Not found." |
A non-existent object_class_id was given | 404 Not Found | "detail": "Not found." |
| Insufficient permissions | 403 Forbidden | "detail": "You do not have permission to perform this action." |
PATCH /api/object-classes/object_class_id/document-templates/document_template_id/
Updates single document template.
Permissions
Requires authentication and object_classes.edit permission.
Request
- URL parameters
| Key | Type | Notes |
|---|---|---|
| object_class_id | pk | |
| document_template_id | pk | |
| allow_on_demand_generation | bool |
- Body parameters
| Key | Type | Notes |
|---|---|---|
| name | string | |
| description | string | |
| template_file | string | File token |
- Headers
Content-Type: application/json
Authorization: JWT access_token- Schema
PATCH /api/object-classes/1/document-templates/1/
{
"name": "Test Document Template",
"description": "",
"template_file": "9d1b16dc-db37-4631-8469-804c7d4048b2",
"allow_on_demand_generation" : true
}Response
| Key | Type | Notes |
|---|---|---|
| id | pk | Automatically generated by the backend. |
| name | string | Name of the document template |
| description | string | Description of the document template |
| template_file | integer | Id of the template file |
| allow_on_demand_generation | bool | |
| warning | string | |
| created_at | datetime | |
| created_by | user | |
| modified_at | datetime | |
| modified_by | user | |
| _meta.labels.files | Object | Object containing template files details |
- Successful status
200 OK - Response body schema:
{
"id": 1,
"name": "Test Document Template",
"description": "",
"template_file": 27,
"allow_on_demand_generation" : true,
"warning" : "",
"created_at": "2022-10-13T10:22:33.344172+02:00",
"created_by": {
"id": 2,
"first_name": "John",
"last_name": "Kovalsky",
"username": "john.kovalsky@autologyx.com",
"company_name": "",
"is_deleted": false,
"account_type": "full"
},
"modified_at": "2022-10-13T10:22:33.344193+02:00",
"modified_by": {
"id": 2,
"first_name": "John",
"last_name": "Kovalsky",
"username": "john.kovalsky@autologyx.com",
"company_name": "",
"is_deleted": false,
"account_type": "full"
},
"_meta": {
"labels": {
"files": {
"27": {
"name": "test.docx",
"url": "http://client.testserve/api/object-classes/1/document-templates/1/download/",
"size": "8085",
"type": "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
}
}
}
}
}Errors
| Cause | Response status code | Response message |
|---|---|---|
| Invalid object_class_id in URL | 403 Forbidden | "detail": "You do not have permission to perform this action." |
| Invalid id in URL | 404 Not Found | "detail": ["Not found."] |
| name missing | 400 Bad Request | "name": ["This field is required."] |
| name is empty | 400 Bad Request | "name": [ "This field may not be blank." ] |
| name is null | 400 Bad Request | "name": [ "This field may not be null." ] |
| name not unique | 400 Bad Request | "name": ["This field must be unique."] |
| name to long | 400 Bad Request | "name": ["Ensure this field has no more than 100 characters."] |
| description to long | 400 Bad Request | "description": ["Ensure this field has no more than 500 characters."] |
| template_file missing | 400 Bad Request | "template_file": ["This field is required."] |
| template_file is null | 400 Bad Request | "template_file": [ "This field may not be null." ] |
| template_file not docx | 400 Bad Request | "template_file": ["Invalid file type."] |
| allow_on_demand_generation invalid value | 400 Bad Request | "allow_on_demand_generation": ["Must be a valid boolean."] |
| Exceeded max number of templates | 400 Bad Request | "detail": "Limit of 1000 Document Templates has been exceeded.", "error_code": "ERR_LIMIT_EXCEEDED" |
| Document can't be parsed | 400 Bad Request | "error": ["Error while parsing document. Please check the syntax."] |
| Class not related | 400 Bad Request | "error": ["Merge field { name } refers to a Class ID={id} which is not related with Class ID={id}."] |
| Insufficient permissions | 403 Forbidden | "detail": "You do not have permission to perform this action." |
DELETE /api/object-classes/object_class_id/document-templates/document_template_id/
Deletes single document template.
Important
During deletion, the use of Document Template in Sequences is checking.
Permissions
Requires authentication and object_classes.edit permission.
Request
- URL parameters
| Key | Type | Notes |
|---|---|---|
| object_class_id | pk | |
| document_template_id | pk |
- Headers
Content-Type: application/json
Authorization: JWT access_token- Schema
DELETE /api/object-classes/1/document-templates/1/Response
- Successful status
204 No Content
Errors
| Error | Response code | Message |
|---|---|---|
object_class_id is invalid | 404 Bad Request | "detail": "Not found." |
document_template_id is invalid | 404 Bad Request | "detail": "Not found." |
| Unauthorized API call | 403 Bad Request | "detail": "You do not have permission to perform this action." |
Document Template is in use | 400 Bad Request | "detail": "Document Template is in use by Sequences." |
GET /api/object-classes/object_class_id/document-templates/document_template_id/usage/
Permissions
Requires authentication and object_classes.view permission.
Request
- URL parameters
| Key | Type | Notes |
|---|---|---|
| object_class_id | pk | |
| document_template_id | pk |
- Headers
Content-Type: application/json
Authorization: JWT access_tokenResponse
| Key | Type | Notes |
|---|---|---|
| num_of_sequences | int | |
| sequences | Array |
Response sequences array
| Key | Type | Notes |
|---|---|---|
| id | int | Sequence id |
| name | string | Name of sequence |
Response
- Successful status
200 OK - Response body:
{
"num_of_sequences": 1,
"sequences": [
{
"id": 1,
"name": "Sample sequence"
}
]
}Errors
| Error | Response code | Message |
|---|---|---|
object_class_id is invalid | 404 Bad Request | 'detail': "Not found." |
document_template_id is invalid | 404 Bad Request | 'detail': "Not found." |
| Unauthorized API call | 403 Bad Request | 'detail': "You do not have permission to perform this action." |
OPTIONS /api/object-classes/object_class_id/document-templates/
Permissions
Requires authentication and object_classes.edit permission.
Request
- Headers
Content-Type: application/json
Authorization: JWT access_token- Schema
OPTIONS /api/object-classes/1/document-templates/Response
- Successful status
200 OK - Response body:
{
"list": {
"columns": [
{
"alias": "id",
"type": "int",
"predicates": [
"exact",
"gt",
"gte",
"lt",
"lte",
"range"
],
"sort_ok": true
},
{
"alias": "name",
"type": "string",
"predicates": [
"exact",
"iexact",
"contains",
"icontains",
"startswith",
"istartswith",
"endswith",
"iendswith"
],
"sort_ok": true
},
{
"alias": "description",
"type": "string",
"predicates": [],
"sort_ok": false
},
{
"alias": "template_file_name",
"type": "string",
"predicates": [
"exact",
"iexact",
"contains",
"icontains",
"startswith",
"istartswith",
"endswith",
"iendswith"
],
"sort_ok": false
},
{
"alias": "allow_on_demand_generation",
"type": "bool",
"predicates": [
"exact"
],
"sort_ok": true
},
{
"alias": "created_at",
"type": "datetime",
"predicates": [
"exact",
"gt",
"gte",
"lt",
"lte",
"range"
],
"sort_ok": true
},
{
"alias": "created_by",
"type": "user",
"predicates": [
"exact",
"in"
],
"sort_ok": false,
"autocomplete": "/api/users/autocomplete/?text__icontains="
},
{
"alias": "modified_at",
"type": "datetime",
"predicates": [
"exact",
"gt",
"gte",
"lt",
"lte",
"range"
],
"sort_ok": true
},
{
"alias": "modified_by",
"type": "user",
"predicates": [
"exact",
"in"
],
"sort_ok": false,
"autocomplete": "/api/users/autocomplete/?text__icontains="
}
]
},
"details": {
"schema": [
{
"alias": "name",
"type": "string",
"required": true,
"validators": [
{
"type": "min_length",
"length": 1
},
{
"type": "max_length",
"length": 100
}
]
},
{
"alias": "description",
"type": "string",
"required": false,
"validators": [
{
"type": "max_length",
"length": 500
}
]
},
{
"alias": "template_file",
"type": "file",
"required": true,
"validators": [
{
"type": "allowed_extensions",
"extensions": [
"docx"
]
},
{
"type": "max_size",
"size": 1
}
]
}
]
},
"restrictions": {
"limit_items_in_object_class": 1000
}
}POST /api/object-classes/object_class_id/document-templates/verify/
Creates document template.
Permissions
Requires authentication and object_classes.edit permission.
Request
- URL parameters
| Key | Type | Notes |
|---|---|---|
| object_class_id | pk |
- Body parameters
| Key | Type | Notes |
|---|---|---|
| template_file | string | Temporary File token or ID of Object Class Document File |
- Headers
Content-Type: application/json
Authorization: JWT access_token- Schema
POST /api/object-classes/1/document-templates/verify/
{
"template_file": "9d1b16dc-db37-4631-8469-804c7d4048b2"
}Validations
- template_file
- is required
- is Temporary file token or Object Class Document File ID
- validate Jinja template syntax
- validate merge tags:
- related classes
- class fields
Response
For valid template
- Successful status
204 No Content
For invalid template
| Key | Type | Notes |
|---|---|---|
| error | Array[string] | List of found issues. |
For invalid class fields
| Key | Type | Notes |
|---|---|---|
| warning | Array[string] | List of found issues. |
Responses
| Cause | Response status code | Response message |
|---|---|---|
| Document can't be parsed | 200 OK | "error": ["Error while parsing document. Please check the syntax."] |
| Class not related | 200 OK | "error": ["Merge field { name } refers to a Class ID={id} which is not related with Class ID={id}."] |
| Class field not valid | 200 OK | "warning": ["Merge field { record.field_unknown } refers to a Field field_unknown which is not available in Class ID={id}."] |
- Successful status
200 OK - Response body:
{
"error": ["Merge field record refers to a Class ID=999 which is not related with Class ID=1."]
}Errors
| Cause | Response status code | Response message |
|---|---|---|
| Invalid object_class_id in URL | 403 Forbidden | "detail": "You do not have permission to perform this action." |
| Wrong file ID of object class document template or not related file to passed object class | 400 Bad Request | "template_file": ["Invalid file_id {file_id}."] |
| Wrong file token | 400 Bad Request | "template_file": ["Invalid token {token}."] |
| Insufficient permissions | 403 Forbidden | "detail": "You do not have permission to perform this action." |
GET /api/object-classes/object_class_id/document-templates/document_template_id/download/
Download a given document template.
Permissions
Requires authentication and object_classes.view permission for object class related to a given file.
Request
- URL parameters
| Key | Type | Notes |
|---|---|---|
| object_class_id | pk | |
| document_template_id | pk |
- Headers
Content-Type: <MIME type>
Content-Disposition: <disposition>; filename="<filename>"
Content-Length: <file size in bytes>
Authorization: JWT access_tokenResponse
- Successful status
200 OK - Response body:
The body will be the raw contents of the file.
Errors
| Error | Response code | Message |
|---|---|---|
object_class_id is invalid | 404 Bad Request | 'detail': "Not found." |
document_template_id is invalid | 404 Bad Request | 'detail': "Not found." |
| Unauthorized API call | 403 Bad Request | 'detail': "You do not have permission to perform this action." |