Document Generation (OPG) - Integration API¶
The OPG integration API allows PDF documents to be generated. Clients can interact directly with this API for bulk document generation.
Authentication¶
The client authenticates using a bearer token for requests other than PDF document generation.
This token must be sent in the Authorization header of each HTTP request. For example:
POST https://opg.obmessage.ai/api/v1/templates/
Authorization: Bearer {{JWT_TOKEN}}
Create template¶
HTTP request to create a template¶
POST https://opg.obmessage.ai/api/v1/templates/
X-Api-Key: {{API_KEY}}
Content-Type: application/json
{
"name": "string",
"max_data_per_page": 16,
"max_rows_per_page": 24,
"status": true,
"fixed_key_password": "string",
"master_password": "string"
}
Field description¶
| Field | Description | Required |
|---|---|---|
| name | PDF template name. | Yes |
| max_data_per_page | In dynamic tables, indicates how many rows will be filled with data. | Yes |
| max_rows_per_page | In dynamic tables, indicates how many rows the table will have. | Yes |
| status | Template status. | Yes |
| fixed_key_password | Dynamic password field for each document. | No |
| master_password | Master password. | No |
Sample JSON payload¶
POST https://opg.obmessage.ai/api/v1/templates/
Authorization: Bearer {{JWT_TOKEN}}
Content-Type: application/json
{
"name": "EstadoTC",
"max_data_per_page": 16,
"max_rows_per_page": 24,
"status": true,
"fixed_key_password": "",
"master_password": ""
}
Response¶
The API returns 200 OK with the template code:
{
"id": "{{ID-TEMPLATE}}"
}
Edit template¶
Send the template code with the modified data.
PATCH https://opg.obmessage.ai/api/v1/templates/{{ID-TEMPLATE}}
Authorization: Bearer {{JWT_TOKEN}}
Content-Type: application/json
{
"name": "EstadoTC",
"max_data_per_page": 16,
"max_rows_per_page": 24,
"status": true,
"fixed_key_password": "",
"master_password": "ofimatic"
}
Template configuration¶
Send the template code with the document configuration.
POST https://opg.obmessage.ai/api/v1/templates/{{ID-TEMPLATE}}/settings
Authorization: Bearer {{JWT_TOKEN}}
Content-Type: application/json
{
"orientation": "string",
"margin_left": 0.0,
"margin_right": 0.0,
"margin_top": 0.0,
"margin_bottom": 0.0,
"page_height": 279.4,
"page_width": 215.9,
"dpi": 200
}
Field description¶
| Field | Description | Required |
|---|---|---|
| orientation | Document orientation. Example: portrait. | Yes |
| margin_left | Left document margin in millimeters. | Yes |
| margin_right | Right document margin in millimeters. | Yes |
| margin_top | Top document margin in millimeters. | Yes |
| margin_bottom | Bottom document margin in millimeters. | Yes |
| page_height | Document height in millimeters. | Yes |
| page_width | Document width in millimeters. | Yes |
| dpi | Pixel resolution. | Yes |
Sample JSON payload¶
POST https://opg.obmessage.ai/api/v1/templates/{{ID-TEMPLATE}}/settings
Authorization: Bearer {{JWT_TOKEN}}
Content-Type: application/json
{
"orientation": "portrait",
"margin_left": 0.0,
"margin_right": 0.0,
"margin_top": 0.0,
"margin_bottom": 10.0,
"page_height": 279.4,
"page_width": 215.9,
"dpi": 200
}
Edit template configuration¶
Send the template code with the modified configuration.
PATCH https://opg.obmessage.ai/api/v1/templates/{{ID-TEMPLATE}}/settings
Authorization: Bearer {{JWT_TOKEN}}
Content-Type: application/json
{
"orientation": "portrait",
"margin_left": 0.0,
"margin_right": 0.0,
"margin_top": 0.0,
"margin_bottom": 10.0,
"page_height": 279.4,
"page_width": 215.9,
"dpi": 200
}
Variable field mapping¶
Creation and editing¶
Send the template code with the data mapping.
PUT https://opg.obmessage.ai/api/v1/templates/{{ID-TEMPLATE}}/mappings
Authorization: Bearer {{JWT_TOKEN}}
Content-Type: application/json
{
"fixed_keys": [
"NAME",
"EMAIL",
"ADDRESS",
"CARDTYPE",
"CARDNUMBER",
"CORTE",
"CICLO",
"FACTURACION",
"DISPONIBLE",
"BALANCEANTERIOR",
"PAGOS",
"COMPRAS",
"BALANCECORTE",
"PAGUEANTESFECHA",
"DISPONIBLEUS",
"BALANCEANTERIORUS",
"PAGOSUS",
"COMPRASUS",
"BALANCECORTEUS",
"CUOTASVENCIDAS",
"IMPORTEVENCIDO",
"PAGOMINIMOPUNTOSOFIMATIC",
"PAGOMINIMO",
"PAGOTOTALPUNTOSOFIMATIC",
"PAGOTOTAL",
"CUOTASVENCIDASUS",
"IMPORTEVENCIDOUS",
"PAGOMINIMOPUNTOSOFIMATICUS",
"PAGOMINIMOUS",
"CARDNUMBERUS",
"PAGOTOTALPUNTOSOFIMATICUS",
"PAGOTOTALUS",
"TOTALDECOMPRAS",
"CUOTAPUNTOSOFIMATIC"
],
"dynamic_keys": [
{
"key": "fecha_transaccion",
"td_code": "<td style=\"text-align:center\">",
"index": 0
},
{
"key": "fecha_entrada",
"td_code": "<td style=\"text-align:center\">",
"index": 1
},
{
"key": "numero_referencia",
"td_code": "<td style=\"text-align:center\">",
"index": 2
},
{
"key": "concepto",
"td_code": "<td style=\"text-align:center\">",
"index": 3
},
{
"key": "debito",
"td_code": "<td style=\"text-align:center\">",
"index": 4
},
{
"key": "credito",
"td_code": "<td style=\"text-align:center\">",
"index": 5
}
]
}
| Field | Description | Required |
|---|---|---|
| fixed_keys | Fields with fixed values inside the document. | Yes |
| dynamic_keys | Fields with dynamic values inside a table. | Yes |
Create document¶
Create document body using an HTML template¶
The document is built using HTML templates, which can be uploaded using the html_content, html_header, and html_footer tags associated with the created template ID.
For more details about building the template, see the html_readme.pdf file.
POST https://opg.obmessage.ai/api/v1/templates/{{ID-TEMPLATE}}/html
Authorization: Bearer {{JWT_TOKEN}}
Content-Type: multipart/form-data
--form 'html_content=@"/path/to/file"' \
--form 'html_header=@"/path/to/file"' \
--form 'html_footer=@"/path/to/file"'
| Field | Description | Required |
|---|---|---|
| html_content | Document content. | Yes |
| html_header | Document header. | No |
| html_footer | Document footer. | No |
Edit HTML template¶
PUT https://opg.obmessage.ai/api/v1/templates/{{ID-TEMPLATE}}/html
Authorization: Bearer {{JWT_TOKEN}}
Content-Type: multipart/form-data
--form 'html_content=@"/path/to/file"' \
--form 'html_header=@"/path/to/file"' \
--form 'html_footer=@"/path/to/file"'
Generate document¶
Authentication¶
The client authenticates using an API_KEY, which will be provided by Ofimatic SRL.
This API_KEY must be sent in the X-Api-Key header of each HTTP request.
Generate PDF¶
POST https://opg.obmessage.ai/api/v1/templates/{{ID-TEMPLATE}}/generate-pdf
X-Api-Key: {{API_KEY}}
Content-Type: application/json
{
"fixed_data": {},
"dynamic_data": [
{}
]
}
| Field | Description | Required |
|---|---|---|
| fixed_data | Fixed fields defined with their values. | Yes |
| dynamic_data | Array of objects containing dynamic fields and their values. | Yes |
Sample JSON payload¶
{
"fixed_data": {
"NAME": "Juan Ant. Perez de Los Santos",
"EMAIL": "demo@ofimatic.com",
"ADDRESS": "Calle Nicolás Ureña de Mendoza #3, Los Prados, Santo Domingo",
"CARDTYPE": "Clasica Internacional",
"CARDNUMBER": "**** **** **** 1111",
"CORTE": "30/04/2022",
"CICLO": "5",
"FACTURACION": "21",
"DISPONIBLE": "100,000.00",
"BALANCEANTERIOR": "40,000.00",
"PAGOS": "10,000.00",
"COMPRAS": "50.00",
"BALANCECORTE": "5,900.00",
"PAGUEANTESFECHA": "24/05/2022",
"DISPONIBLEUS": "2,000.00",
"BALANCEANTERIORUS": "1,000.00",
"PAGOSUS": "1.00",
"COMPRASUS": "165.00",
"BALANCECORTEUS": "235.55",
"CUOTASVENCIDAS": "2",
"IMPORTEVENCIDO": "100.00",
"PAGOMINIMOPUNTOSOFIMATIC": "2,300.00",
"PAGOMINIMO": "523.00",
"PAGOTOTALPUNTOSOFIMATIC": "963.00",
"PAGOTOTAL": "3,543.22",
"CUOTASVENCIDASUS": "2",
"IMPORTEVENCIDOUS": "522.00",
"PAGOMINIMOPUNTOSOFIMATICUS": "12.00",
"PAGOMINIMOUS": "1,232.00",
"CARDNUMBERUS": "**** **** **** 1112",
"PAGOTOTALPUNTOSOFIMATICUS": "1,235.55",
"PAGOTOTALUS": "3,543.01",
"TOTALDECOMPRAS": "1,235.22",
"CUOTAPUNTOSOFIMATIC": "0",
"BALANCEALCORTE": "242.00",
"CREDITODISPONIBLE": "50.00"
},
"dynamic_data": [
{
"fecha_transaccion": "2020-01-01",
"fecha_entrada": "2020-01-01",
"numero_referencia": "123456789123456789",
"concepto": "Pruebas",
"debito": "RD$ 1,000.00",
"credito": "RD$ 2,000.00"
},
{
"fecha_transaccion": "2020-01-01",
"fecha_entrada": "2020-01-01",
"numero_referencia": "123456789123456789",
"concepto": "Pruebas",
"debito": "RD$ 3,000.00",
"credito": "RD$ 4,000.00"
}
]
}
Response¶
The API returns 200 OK with the generation code and the document in base64:
{
"data": {
"id": "{{ID-FILE}}",
"file": "{{BASE-FILE}}"
}
}
Query¶
Query generated documents¶
POST https://opg.obmessage.ai/api/v1/templates/{{ID-TEMPLATE}}/requests/{{ID-REQUEST}}
Authorization: Bearer {{JWT_TOKEN}}
Content-Type: application/json