Skip to content

Legal Rail

Legal document management, templates, and contract documentation.

The Legal Rail provides endpoints for managing legal documents, contract templates, version control, and document signing workflows.

/api/v1/legal
POST /api/v1/legal/templates

Create a legal document template.

Request Body:

{
"name": "Murabaha Financing Agreement",
"type": "CONTRACT",
"category": "FINANCING",
"jurisdiction": "SAU_SAMA",
"language": "ar",
"content": "{{template_content}}",
"variables": [
{ "name": "customerName", "type": "string", "required": true },
{ "name": "financingAmount", "type": "currency", "required": true },
{ "name": "profitRate", "type": "percentage", "required": true }
],
"shariahApproved": true,
"fatwaReference": "fatwa_123"
}

Response:

{
"data": {
"templateId": "tpl_abc123",
"version": "1.0.0",
"status": "DRAFT",
"createdAt": "2025-01-15T10:00:00Z"
}
}
POST /api/v1/legal/documents/generate

Generate a document from template.

Request Body:

{
"templateId": "tpl_abc123",
"variables": {
"customerName": "Ahmad Abdullah",
"financingAmount": "500000.00",
"financingCurrency": "SAR",
"profitRate": "5.5",
"tenor": 60
},
"outputFormat": "PDF"
}

Response:

{
"data": {
"documentId": "doc_xyz789",
"templateId": "tpl_abc123",
"status": "GENERATED",
"downloadUrl": "https://...",
"expiresAt": "2025-01-16T10:00:00Z"
}
}
GET /api/v1/legal/documents/:documentId

Retrieve document details.

GET /api/v1/legal/documents

Query Parameters:

ParameterTypeDescription
typestringDocument type
statusstringDocument status
contractIdstringRelated contract
POST /api/v1/legal/documents/:documentId/signatures

Request document signature.

Request Body:

{
"signers": [
{
"name": "Ahmad Abdullah",
"email": "ahmad@example.com",
"role": "CUSTOMER",
"order": 1
},
{
"name": "Bank Representative",
"email": "legal@bank.com",
"role": "INSTITUTION",
"order": 2
}
],
"expiresAt": "2025-02-01",
"reminderDays": [3, 7]
}
POST /api/v1/legal/documents/upload

Upload an external document.

Request Body (multipart/form-data):

file: document.pdf
type: SUPPORTING
category: KYC
description: Customer ID document
POST /api/v1/legal/templates/:templateId/versions

Create a new template version.

Request Body:

{
"content": "{{updated_template_content}}",
"changeNotes": "Updated profit calculation clause",
"requiresApproval": true
}
GET /api/v1/legal/templates/:templateId/compare

Compare two template versions.

Query Parameters:

ParameterTypeDescription
version1stringFirst version
version2stringSecond version
TypeDescription
CONTRACTLegal contract
AGREEMENTAgreement/MOU
DISCLOSUREDisclosure document
SCHEDULEContract schedule
AMENDMENTContract amendment
SUPPORTINGSupporting document
StatusDescription
DRAFTIn draft
GENERATEDGenerated from template
PENDING_SIGNATUREAwaiting signatures
PARTIALLY_SIGNEDSome signatures collected
FULLY_SIGNEDAll signatures collected
EXECUTEDLegally executed
ARCHIVEDArchived
EventDescription
legal.document.generatedDocument generated
legal.document.signedDocument signed
legal.document.executedDocument executed
legal.template.approvedTemplate approved