Object Record Documents
Manually generating documents from document templates for a given Object Record.
Object Record Documents API
POST /api/object-records/documents/
Starting the document generation process.
Permissions
Requires authentication
Request example
- Headers
Request Method: POST
Content-Type: application/json
Authorization: JWT access_tokenBody
| Key | Type | Required | Notes |
|---|---|---|---|
| object_record | int | True | |
| document_template | int | True | |
| object_record_field | int | False |
Validations
- object_record_id is an ID of Object Record
- object_record_field is slug name of Object Record field (ex. "field_slug_name")
- object_record_field is document type field
- object_record_field is defined in ObjectClass
- object_record_id and document_template_id have the same ObjectClass
- object_records.view permission to individual object_record
- object_records.edit permission if object_record_field is not null
- If the generation process for a given pair (object_record, document_template) is running (status processing), the next generation attempt is skipped
Sample request body
POST /api/object-records/documents/
{
"object_record": 1,
"document_template": 2,
"object_record_field": "field_abc"
}Response
| Key | Type | Notes |
|---|---|---|
| object_record | int | |
| document_template | int | |
| object_record_field | int | |
| _meta.labels | Object |
Response labels object
| Key | Type | Notes |
|---|---|---|
| object_record | str | |
| document_template | str |
- Successful status 201 Created
- Response body schema
{
"object_record": 1,
"document_template": 2,
"object_record_field": "field_abc",
"status": "processing",
"_meta": {
"labels": {
"object_record": "Record repr value",
"document_template": "Document Name"
}
}
}Errors
| Cause | Response code | Message |
|---|---|---|
| object_record is missing | 400 Bad Request | "object_record": ["This field is required."] |
| object_record is null | 400 Bad Request | "object_record": ["This field may not be null."] |
| object_record insufficient permissions | 400 Bad Request | "object_record": ["Invalid pk "value" - You do not have permission for this Record."] |
| object_record invalid ID | 400 Bad Request | "object_record": ["Invalid pk "value" - object does not exist."] |
| document_template is missing | 400 Bad Request | "document_template": ["This field is required."] |
| document_template is null | 400 Bad Request | "document_template": ["This field may not be null."] |
| document_template insufficient permissions | 400 Bad Request | "document_template": ["Invalid pk "value" - You do not have permission for this Document."] |
| document_template invalid ID | 400 Bad Request | "document_template": ["Invalid pk "value" - object does not exist."] |
| document_template, object_record do not have the same ObjectClass | 400 Bad Request | "non_field_errors": ["Record pk "value" cannot be used with Document pk "value"."] |
| object_record_field insufficient record.edit permissions | 400 Bad Request | "object_record_field": ["Invalid pk "value" - You do not have permission for this Record."] |
| object_record_field invalid SLUG | 400 Bad Request | "object_record_field": ["Invalid name "value" - field does not exist."] |
| object_record_field invalid type | 400 Bad Request | "object_record_field": ["Invalid type - field "value" is not Document type."] |
| Document for the given pair is already being processed | 400 Bad Request | "detail": ["Your request is already processing."] |
| insufficient permissions | 403 Forbidden | "detail": "You do not have permission to perform this action." |
GET /api/object-records/id/documents/
List Document Template based on query parameters and caller permissions.
The list is restricted only to those Document Templates for which the user has permission to view all classes used in the relational MF in given document. If the user does not have view permission for at least one Object Class used in the document, they will not be able to see that document.
Important
Access to endpoint require passing Object Class filter /api/object-records/<object_record_id>/documents/
Permissions
Requires authentication and object_records.list permission.
Request example
- Headers
Request Method: GET
Location: /api/object-records/1/documents/
Authorization: JWT access_tokenResponse
| Key | Type | Notes |
|---|---|---|
| limit | int | |
| offset | int | |
| total_count | int | Total number of items visible to the user (based on permissions). |
| filtered_count | int | Number of items visible to the user (based on permissions) with filters applied. |
| next | URL / null | Next page URL (null if there is no next page) |
| previous | URL / null | Previous page URL (null if there is no previous page) |
| results | Array | Described in the next table. |
Response results array
| Key | Type | Notes |
|---|---|---|
| id | int | |
| name | string | |
| allow_on_demand_generation | bool | |
| generated_document | Array |
Response generated_document array
| Key | Type | Notes |
|---|---|---|
| status | enum | processing, canceled, completed, field_updated, field_not_updated, failed |
| error_message | string | |
| document | int | |
| generated_at | datetime | |
| generated_by | user | |
| _meta.labels.document | Array |
Response _meta.labels.document array
| Key | Type | Notes |
|---|---|---|
| name | string | |
| url | string | |
| size | string | |
| type | string |
Response example
- Status
200 OK - Body
{
"limit": 100,
"offset": 0,
"filtered_count": 2,
"total_count": 2,
"next": null,
"previous": null,
"results": [
{
"id": 3,
"name": "Test docx",
"allow_on_demand_generation": true,
"generated_document": {
"id": 5,
"status": "completed",
"error_message": "",
"document": 90,
"generated_at": "2023-07-13T15:35:26.607101+02:00",
"generated_by": {
"id": 240,
"first_name": "Ryan",
"last_name": "Sample",
"username": "ryan.sample@example.test",
"company_name": "",
"is_deleted": false,
"account_type": "super_admin"
},
"_meta": {
"labels": {
"document": {
"name": "Test docx.docx",
"url": "",
"size": "4258",
"type": "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
}
}
}
}
},
{
"id": 4,
"name": "Test",
"generated_document": null
}
]
}Sorting
| Parameter | Example | Notes |
|---|---|---|
| id | {build}/api/object-records/1/documents/?ordering=id | Ascending |
| id | {build}/api/object-records/1/documents/?ordering=-id | Descending (-) |
| name | {build}/api/object-records/1/documents/?ordering=name | Ascending |
| name | {build}/api/object-records/1/documents/?ordering=-name | Descending (-) |
| allow_on_demand_generation | {build}/api/object-records/1/documents/?ordering=allow_on_demand_generation | Ascending |
| allow_on_demand_generation | {build}/api/object-records/1/documents/?ordering=-allow_on_demand_generation | Descending (-) |
Filtering
For the full description of standard predicates see ALX API standards - Developers guide.
| Parameter | Type | Example |
|---|---|---|
| id | int | {build}/api/object-records/1/documents/?id=1 |
| id | int | {build}/api/object-records/1/documents/?id__in=1,2 |
| name | string | {build}/api/object-records/1/documents/?name__iexact=template name |
| allow_on_demand_generation | bool | {build}/api/object-records/1/documents/?allow_on_demand_generation=True |
| Error | Response code | Message |
|---|---|---|
| Invalid object_record_id in URL | 404 Not Found | "detail": ["Not found."] |
| Insufficient permissions | 403 Forbidden | "detail": "You do not have permission to perform this action." |
OPTIONS /api/object-records/object_record_id/documents/
Permissions
Requires authentication and object_records.list permission.
Request example
- Headers
Request Method: OPTIONS
Location: /api/object-records/1/documents/Response example
- Status
200 OK - Body
{
"list": {
"columns": [
{
"alias": "id",
"type": "int",
"predicates": [
"exact",
"in"
],
"sort_ok": true
},
{
"alias": "name",
"type": "string",
"predicates": [],
"sort_ok": true
},
{
"alias": "allow_on_demand_generation",
"type": "bool",
"predicates": [
"exact"
],
"sort_ok": true
},
{
"alias": "generated_document",
"type": "json",
"predicates": [],
"sort_ok": false
}
]
}
}GET /api/object-records/object_record_id/documents/document_template_id/
Permissions
Requires authentication and Object Record view
Request example
- Headers
Request Method: GET
Authorization: JWT access_tokenResponse
| Key | Type | Notes |
|---|---|---|
| id | int | |
| name | string | |
| allow_on_demand_generation | bool | |
| generated_document | Object |
Response generated_document object
| Key | Type | Notes |
|---|---|---|
| status | enum | |
| error_message | string | |
| document | int | |
| generated_at | datetime | |
| generated_by | user | |
| _meta.labels.document | Object |
Response _meta.labels.document object
| Key | Type | Notes |
|---|---|---|
| name | string | |
| url | string | |
| size | int | |
| type | string |
Response example
- Status
200 OK - Body
{
"id": 2,
"name": "Template name",
"allow_on_demand_generation": true,
"generated_document": {
"status": "completed",
"error_message": "",
"document": 1,
"generated_at": "2023-07-12T12:17:58.737002+02:00",
"generated_by": {
"id": 240,
"first_name": "First Name",
"last_name": "Second",
"username": "mail@test.test",
"company_name": "",
"is_deleted": false,
"account_type": "super_admin"
},
"_meta": {
"labels": {
"document": {
"name": "TemplateName_2023-07-12.docx",
"url": "https://some.url",
"size": 4200,
"type": "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
}
}
}
}
}Errors
| Error | Response code | Message |
|---|---|---|
A non-existent record_id was given | 404 Not Found | "detail": "Not found." |
A non-existent document_template_id was given | 404 Not Found | "detail": "Not found." |
| Insufficient permissions | 403 Forbidden | "detail": "You do not have permission to perform this action." |
| Requesting user is not authenticated | 401 Unauthorized | "detail": "Authentication credentials were not provided." |
POST /api/object-records/object_record_id/documents/document_template_id/cancel/
Canceling the document generation process.
Permissions
Requires authentication, Object Record view and Object Class view to all Object Classes used in Template as merge fields.
Request example
- Headers
Request Method: POST
Content-Type: application/json
Authorization: JWT access_tokenValidations
- Document has already been processed
Sample request body
POST /api/object-records/object_record_id/documents/document_template_id/cancel/
{
}Response
| Key | Type | Notes |
|---|---|---|
| object_record | int | |
| document_template | int | |
| object_record_field | int | |
| _meta.labels | Object |
Response labels object
| Key | Type | Notes |
|---|---|---|
| object_record | str | |
| document_template | str |
- Successful status 201 Created
- Response body schema
{
"object_record": 1,
"document_template": 2,
"object_record_field": "field_abc",
"status": "cancelled",
"_meta": {
"labels": {
"object_record": "Record repr value",
"document_template": "Document Name"
}
}
}Errors
| Error | Response code | Message |
|---|---|---|
A non-existent record_id was given | 404 Not Found | "detail": "Not found." |
A non-existent document_template_id was given | 404 Not Found | "detail": "Not found." |
| Cancelling for statuses other than "processing" | 400 Bad Request | "detail": ["Document has already been processed."] |
| Insufficient permissions | 403 Forbidden | "detail": "You do not have permission to perform this action." |
GET /api/object-records/record_id/documents/template_id/download/uuid/
Download generated document.
Permissions
Requires authentication, Object Record view and Object Class view to all Object Classes used in Template as merge fields.
Request
- Headers
Content-Type: application/force-download- Schema
GET /api/object-records/2/documents/12/download/4fef1510-7b0b-46fd-84d4-7b933d3b6f72/GET /api/object-records/id/document-fields/
Document fields list for given Object Record.
Permissions
Requires authentication and object_records.view permission.
Request example
- Headers
Request Method: GET
Location: /api/object-records/1/document-fields/
Authorization: JWT access_tokenResponse
| Key | Type | Notes |
|---|---|---|
| limit | int | |
| offset | int | |
| total_count | int | Total number of items visible to the user (based on permissions). |
| filtered_count | int | Number of items visible to the user (based on permissions) with filters applied. |
| next | URL / null | Next page URL (null if there is no next page) |
| previous | URL / null | Previous page URL (null if there is no previous page) |
| results | Array | Described in the next table. |
Response results array
| Key | Type | Notes |
|---|---|---|
| alias | string | |
| label | string | |
| max_num_of_files | int | |
| is_available | bool |
Response example
- Status
200 OK - Body
{
"limit": 50,
"offset": 0,
"filtered_count": 1,
"total_count": 1,
"next": null,
"previous": null,
"results": [
{
"alias": "field_document",
"label": "Document",
"max_num_of_files": 3,
"is_available": true
}
]
}| Error | Response code | Message |
|---|---|---|
| Invalid object_record_id in URL | 404 Not Found | "detail": ["Not found."] |
| Insufficient permissions | 403 Forbidden | "detail": "You do not have permission to perform this action." |