Skip to main content

Overview

The Documents API allows users to retrieve company documents and administrators to manage the document library. All endpoints require authentication.

Endpoints

Get Documents

Retrieve all documents or filter by category

Create Document

Create a new document (Admin only)

Update Document

Update document metadata or file (Admin only)

Delete Document

Remove a document from the library (Admin only)

Get Documents

curl -X GET "https://api.example.com/api/documentos?id_categoria=1" \
  -H "Authorization: Bearer YOUR_TOKEN"
Retrieves a list of documents, optionally filtered by category.

Query Parameters

id_categoria
integer
Filter documents by category ID

Response

[
  {
    "id_documento": 1,
    "titulo": "Employee Handbook",
    "contenido": "Complete guide for employees",
    "id_categoria": 1,
    "url_documento": "https://storage.example.com/docs/handbook.pdf",
    "fecha_creacion": "2024-01-15T10:30:00Z"
  },
  {
    "id_documento": 2,
    "titulo": "Safety Protocols",
    "contenido": "Workplace safety guidelines",
    "id_categoria": 1,
    "url_documento": "https://storage.example.com/docs/safety.pdf",
    "fecha_creacion": "2024-02-20T14:15:00Z"
  }
]

Create Document

curl -X POST "https://api.example.com/api/documentos/admin" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "titulo": "New Policy Document",
    "contenido": "Updated company policies",
    "id_categoria": 2,
    "url_documento": "https://storage.example.com/docs/policy.pdf"
  }'
This endpoint requires Admin or RRHH role permissions.

Request Body

titulo
string
required
Document title
contenido
string
Document description or summary
id_categoria
integer
Category ID for document classification
url_documento
string
required
URL of the uploaded document file

Response

{
  "message": "Documento y registro creados exitosamente.",
  "documento": {
    "id_documento": 15,
    "titulo": "New Policy Document",
    "contenido": "Updated company policies",
    "id_categoria": 2,
    "url_documento": "https://storage.example.com/docs/policy.pdf"
  }
}

Update Document

curl -X PUT "https://api.example.com/api/documentos/admin/15" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "titulo": "Updated Policy Document",
    "contenido": "Revised company policies",
    "id_categoria": 2,
    "url_documento": "https://storage.example.com/docs/policy-v2.pdf"
  }'
This endpoint requires Admin or RRHH role permissions.

Path Parameters

id
integer
required
Document ID to update

Request Body

titulo
string
Updated document title
contenido
string
Updated document description
id_categoria
integer
Updated category ID
url_documento
string
Updated document URL (for new file versions)

Response

{
  "message": "Documento actualizado exitosamente."
}

Delete Document

curl -X DELETE "https://api.example.com/api/documentos/admin/15" \
  -H "Authorization: Bearer YOUR_TOKEN"
This endpoint requires Admin or RRHH role permissions.

Path Parameters

id
integer
required
Document ID to delete

Response

{
  "message": "Documento eliminado exitosamente."
}

Implementation Reference

Source files:
  • Routes: src/routes/documentacionRoutes.js:13-23
  • Controller: src/controllers/documentacionController.js:7-100

Build docs developers (and LLMs) love