Skip to main content

Create Document

Create a new document with optional file upload.
curl -X POST https://api.vigia.com/api/v1/documentos \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -F "codigo=FO-FMV-002" \
  -F "titulo=Notificación de Sospecha de Reacción Adversa" \
  -F "categoria=Formato" \
  -F "area=Farmacovigilancia" \
  -F "version=1.0" \
  -F "vigente=true" \
  -F "file=@/path/to/document.docx"

Request Parameters

codigo
string
required
Unique document code (e.g., “FO-FMV-002”). Must be unique across the system.
titulo
string
required
Document title or description.
categoria
string
Document category (e.g., “Formato”, “Procedimiento”). Defaults to null.
area
string
Responsible area or department (e.g., “Farmacovigilancia”).
version
string
default:"1.0"
Initial version number. Defaults to “1.0”.
vigente
string
default:"true"
Document validity status (“true” or “false”). Defaults to “true”.
file
file
Document file to upload. Supported formats: .docx, .pdf, .txt

Response

id
integer
Unique document identifier
codigo
string
Document code
titulo
string
Document title
version
string
Current version
file_url
string
Download URL for the document
file_name
string
Name of the uploaded file

Example Response

{
  "id": 1,
  "codigo": "FO-FMV-002",
  "titulo": "Notificación de Sospecha de Reacción Adversa",
  "categoria": "Formato",
  "area": "Farmacovigilancia",
  "version": "1.0",
  "vigente": true,
  "updated_at": "2026-03-03T10:30:00Z",
  "file_url": "/api/v1/documentos/1/download",
  "file_name": "FO-FMV-002_v1.0.docx"
}

List Documents

Retrieve a paginated list of documents with optional filtering.
curl -X GET "https://api.vigia.com/api/v1/documentos?query=FO-FMV&vigente=true&area=Farmacovigilancia" \
  -H "Authorization: Bearer YOUR_TOKEN"

Query Parameters

query
string
Search text for codigo, titulo, or categoria (case-insensitive partial match).
vigente
boolean
Filter by validity status. Omit to return all documents.
area
string
Filter by area (case-insensitive partial match).

Response

{
  "items": [
    {
      "id": 1,
      "codigo": "FO-FMV-002",
      "titulo": "Notificación de Sospecha de Reacción Adversa",
      "categoria": "Formato",
      "area": "Farmacovigilancia",
      "version": "1.0",
      "vigente": true,
      "updated_at": "2026-03-03T10:30:00Z",
      "file_url": "/api/v1/documentos/1/download",
      "file_name": "FO-FMV-002_v1.0.docx"
    }
  ],
  "total": 1
}

Update Document

Update document metadata and optionally upload a new file for the current version.
curl -X PUT https://api.vigia.com/api/v1/documentos/1 \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -F "titulo=Updated Title" \
  -F "vigente=false" \
  -F "file=@/path/to/updated.docx"

Path Parameters

doc_id
integer
required
Document ID to update

Request Parameters

All parameters are optional. Only provided fields will be updated.
codigo
string
New document code (must be unique)
titulo
string
Updated title
categoria
string
Updated category
area
string
Updated area
version
string
Updated version number
vigente
string
Validity status (“true” or “false”)
file
file
New file to replace the current version’s file

Create New Version

Create a new version of an existing document with a file upload.
curl -X POST https://api.vigia.com/api/v1/documentos/1/version \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -F "version=2.0" \
  -F "file=@/path/to/version2.docx"

Path Parameters

doc_id
integer
required
Document ID to create a new version for

Request Parameters

version
string
required
Version number (e.g., “2.0”, “1.1”). Must be unique for this document.
file
file
required
Document file for the new version

Response

Returns the updated document with the new version set as current.

Download Document

Download the current version of a document.
curl -X GET "https://api.vigia.com/api/v1/documentos/1/download?disposition=attachment" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -o document.docx

Path Parameters

doc_id
integer
required
Document ID to download

Query Parameters

disposition
string
default:"attachment"
Download behavior: “attachment” (download) or “inline” (preview in browser)

Response

Returns the file binary content with appropriate Content-Type and Content-Disposition headers.

Preview Document (PDF)

Generate and preview a PDF version of a DOCX document.
curl -X GET "https://api.vigia.com/api/v1/documentos/1/preview?disposition=inline" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -o preview.pdf

Path Parameters

doc_id
integer
required
Document ID to preview

Query Parameters

disposition
string
default:"inline"
Display behavior: “inline” (view in browser) or “attachment” (download)

Conversion Methods

The system attempts PDF conversion using:
  1. LibreOffice (preferred, cross-platform)
  2. docx2pdf (Windows with MS Word)
PDFs are cached and regenerated only when the source DOCX is updated.

Toggle Document Validity

Toggle or set a document’s validity status.
curl -X POST "https://api.vigia.com/api/v1/documentos/1/toggle?vigente=false" \
  -H "Authorization: Bearer YOUR_TOKEN"

Path Parameters

doc_id
integer
required
Document ID to toggle

Query Parameters

vigente
boolean
Explicit validity state. Omit to toggle the current state.

Generate from Template

Generate a document from a predefined template with dynamic data.
curl -X POST https://api.vigia.com/api/v1/documentos/generar \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "codigo": "FO-FMV-002",
    "version": "1.0",
    "data": {
      "paciente": "J.D.",
      "producto": "Paracetamol 500mg",
      "rs": "RS-12345",
      "emision": "2026-03-03",
      "descripcion": "Paciente presenta urticaria generalizada",
      "elaborado_por": "Dr. Juan Pérez",
      "cargo_elabora": "Químico Farmacéutico",
      "revisado_por": "Dra. María García",
      "cargo_revisa": "Jefe de Farmacovigilancia",
      "aprobado_por": "Dr. Carlos López",
      "cargo_aprueba": "Director Técnico"
    }
  }'

Request Body

codigo
string
required
Template code to use (e.g., “FO-FMV-002”, “FO-FMV-008”, “PD-FMV-010”)
version
string
default:"1.0"
Version number for the generated document
data
object
required
Key-value pairs for template field substitution. Required fields depend on the template.

Template Processing

  1. If a DOCX template exists at app/templates/docs/{codigo}.docx, it’s rendered using docxtpl
  2. Otherwise, generates PDF/TXT using the template body with placeholder substitution
  3. Automatically calculates vigencia date (+3 years) if emision is provided

Available Templates

  • FO-FMV-002: Notificación de Sospecha de Reacción Adversa
  • FO-FMV-008: Registro de Seguimiento de Paciente
  • PD-FMV-010: Procedimiento de Gestión de Reacciones Adversas
Use GET /api/v1/documentos/plantillas to retrieve the full list of available templates and their required fields.

Version Management

List Document Versions

Get all versions of a document.
GET /api/v1/documentos/{doc_id}/versions
curl -X GET https://api.vigia.com/api/v1/documentos/1/versions \
  -H "Authorization: Bearer YOUR_TOKEN"
Response:
[
  {
    "version": "2.0",
    "file_name": "FO-FMV-002_v2.0.docx",
    "file_mime": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
    "file_size": 48932,
    "updated_at": "2026-03-04T15:20:00Z"
  },
  {
    "version": "1.0",
    "file_name": "FO-FMV-002_v1.0.docx",
    "file_mime": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
    "file_size": 45678,
    "updated_at": "2026-03-03T10:30:00Z"
  }
]

Switch to Specific Version

Set a specific version as the current active version.
POST /api/v1/documentos/{doc_id}/use-version
curl -X POST https://api.vigia.com/api/v1/documentos/1/use-version \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"version": "1.0"}'

Download Specific Version

Download a specific version instead of the current one.
GET /api/v1/documentos/{doc_id}/versions/{version}/download
curl -X GET https://api.vigia.com/api/v1/documentos/1/versions/1.0/download \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -o document_v1.0.docx

Error Codes

Status CodeDescription
400Bad Request - Invalid parameters, duplicate code, or version already exists
404Not Found - Document, version, or file not found
500Internal Server Error - PDF conversion failed or file system error

Best Practices

  1. Unique Codes: Always use unique document codes (e.g., FO-FMV-XXX)
  2. Version Numbering: Follow semantic versioning (1.0, 1.1, 2.0)
  3. File Formats: Prefer DOCX for documents requiring template processing
  4. Preview Before Export: Use the preview endpoint to verify documents before final export
  5. Version Control: Create new versions instead of overwriting existing files

Next: Digital Signatures

Learn how to add digital signatures to documents

Build docs developers (and LLMs) love