Skip to content

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_token

Body

KeyTypeRequiredNotes
object_recordintTrue
document_templateintTrue
object_record_fieldintFalse

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/

json

{
    "object_record": 1,
    "document_template": 2,
    "object_record_field": "field_abc"
}

Response

KeyTypeNotes
object_recordint
document_templateint
object_record_fieldint
_meta.labelsObject

Response labels object

KeyTypeNotes
object_recordstr
document_templatestr
  • Successful status 201 Created
  • Response body schema
json

{
    "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

CauseResponse codeMessage
object_record is missing400 Bad Request"object_record": ["This field is required."]
object_record is null400 Bad Request"object_record": ["This field may not be null."]
object_record insufficient permissions400 Bad Request"object_record": ["Invalid pk "value" - You do not have permission for this Record."]
object_record invalid ID400 Bad Request"object_record": ["Invalid pk "value" - object does not exist."]
document_template is missing400 Bad Request"document_template": ["This field is required."]
document_template is null400 Bad Request"document_template": ["This field may not be null."]
document_template insufficient permissions400 Bad Request"document_template": ["Invalid pk "value" - You do not have permission for this Document."]
document_template invalid ID400 Bad Request"document_template": ["Invalid pk "value" - object does not exist."]
document_template, object_record do not have the same ObjectClass400 Bad Request"non_field_errors": ["Record pk "value" cannot be used with Document pk "value"."]
object_record_field insufficient record.edit permissions400 Bad Request"object_record_field": ["Invalid pk "value" - You do not have permission for this Record."]
object_record_field invalid SLUG400 Bad Request"object_record_field": ["Invalid name "value" - field does not exist."]
object_record_field invalid type400 Bad Request"object_record_field": ["Invalid type - field "value" is not Document type."]
Document for the given pair is already being processed400 Bad Request"detail": ["Your request is already processing."]
insufficient permissions403 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_token

Response

KeyTypeNotes
limitint
offsetint
total_countintTotal number of items visible to the user (based on permissions).
filtered_countintNumber of items visible to the user (based on permissions) with filters applied.
nextURL / nullNext page URL (null if there is no next page)
previousURL / nullPrevious page URL (null if there is no previous page)
resultsArrayDescribed in the next table.

Response results array

KeyTypeNotes
idint
namestring
allow_on_demand_generationbool
generated_documentArray

Response generated_document array

KeyTypeNotes
statusenumprocessing, canceled, completed, field_updated, field_not_updated, failed
error_messagestring
documentint
generated_atdatetime
generated_byuser
_meta.labels.documentArray

Response _meta.labels.document array

KeyTypeNotes
namestring
urlstring
sizestring
typestring

Response example

  • Status 200 OK
  • Body
json
{
    "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

ParameterExampleNotes
id{build}/api/object-records/1/documents/?ordering=idAscending
id{build}/api/object-records/1/documents/?ordering=-idDescending (-)
name{build}/api/object-records/1/documents/?ordering=nameAscending
name{build}/api/object-records/1/documents/?ordering=-nameDescending (-)
allow_on_demand_generation{build}/api/object-records/1/documents/?ordering=allow_on_demand_generationAscending
allow_on_demand_generation{build}/api/object-records/1/documents/?ordering=-allow_on_demand_generationDescending (-)

Filtering

For the full description of standard predicates see ALX API standards - Developers guide.

ParameterTypeExample
idint{build}/api/object-records/1/documents/?id=1
idint{build}/api/object-records/1/documents/?id__in=1,2
namestring{build}/api/object-records/1/documents/?name__iexact=template name
allow_on_demand_generationbool{build}/api/object-records/1/documents/?allow_on_demand_generation=True
ErrorResponse codeMessage
Invalid object_record_id in URL404 Not Found"detail": ["Not found."]
Insufficient permissions403 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
json
{
    "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_token

Response

KeyTypeNotes
idint
namestring
allow_on_demand_generationbool
generated_documentObject

Response generated_document object

KeyTypeNotes
statusenum
error_messagestring
documentint
generated_atdatetime
generated_byuser
_meta.labels.documentObject

Response _meta.labels.document object

KeyTypeNotes
namestring
urlstring
sizeint
typestring

Response example

  • Status 200 OK
  • Body
json
{
    "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

ErrorResponse codeMessage
A non-existent record_id was given404 Not Found"detail": "Not found."
A non-existent document_template_id was given404 Not Found"detail": "Not found."
Insufficient permissions403 Forbidden"detail": "You do not have permission to perform this action."
Requesting user is not authenticated401 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_token

Validations

  • Document has already been processed

Sample request body

POST /api/object-records/object_record_id/documents/document_template_id/cancel/

json

{
}

Response

KeyTypeNotes
object_recordint
document_templateint
object_record_fieldint
_meta.labelsObject

Response labels object

KeyTypeNotes
object_recordstr
document_templatestr
  • Successful status 201 Created
  • Response body schema
json

{
    "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

ErrorResponse codeMessage
A non-existent record_id was given404 Not Found"detail": "Not found."
A non-existent document_template_id was given404 Not Found"detail": "Not found."
Cancelling for statuses other than "processing"400 Bad Request"detail": ["Document has already been processed."]
Insufficient permissions403 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
json
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_token

Response

KeyTypeNotes
limitint
offsetint
total_countintTotal number of items visible to the user (based on permissions).
filtered_countintNumber of items visible to the user (based on permissions) with filters applied.
nextURL / nullNext page URL (null if there is no next page)
previousURL / nullPrevious page URL (null if there is no previous page)
resultsArrayDescribed in the next table.

Response results array

KeyTypeNotes
aliasstring
labelstring
max_num_of_filesint
is_availablebool

Response example

  • Status 200 OK
  • Body
json
{
    "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
        }
    ]
}
ErrorResponse codeMessage
Invalid object_record_id in URL404 Not Found"detail": ["Not found."]
Insufficient permissions403 Forbidden"detail": "You do not have permission to perform this action."