Skip to main content

Overview

The Mensajes API allows you to manage contact form messages in the MTB Backend system. Each message includes sender information, content, submission date, and response status.
This endpoint supports draft and publish functionality. Use the publishedAt field to control publication status.

List All Mensajes

Retrieve a list of all contact messages with optional filtering, sorting, and pagination.

Query Parameters

filters
object
Filter messages by field values. Example: filters[respondido][$eq]=false
sort
string
Sort messages by field(s). Example: fecha:desc for newest first
pagination[page]
number
default:"1"
Page number for pagination
pagination[pageSize]
number
default:"25"
Number of items per page

Response

data
array
Array of mensaje objects
meta
object
Pagination metadata

Example Request

curl -X GET "https://api.example.com/api/mensajes?filters[respondido][$eq]=false&sort=fecha:desc" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_TOKEN"

Example Response

{
  "data": [
    {
      "id": 1,
      "attributes": {
        "nombre": "Pedro Martínez",
        "email": "[email protected]",
        "mensaje": [
          {
            "type": "paragraph",
            "children": [
              {"type": "text", "text": "Hola, quisiera información sobre las próximas competencias..."}
            ]
          }
        ],
        "fecha": "2024-01-22T14:30:00.000Z",
        "respondido": false,
        "publishedAt": "2024-01-22T14:30:00.000Z",
        "createdAt": "2024-01-22T14:30:00.000Z",
        "updatedAt": "2024-01-22T14:30:00.000Z"
      }
    }
  ],
  "meta": {
    "pagination": {
      "page": 1,
      "pageSize": 25,
      "pageCount": 1,
      "total": 1
    }
  }
}

Get a Single Mensaje

Retrieve a specific message by its ID.

Path Parameters

id
number
required
The unique identifier of the message

Response

data
object
The mensaje object (see List All Mensajes for structure)

Example Request

curl -X GET "https://api.example.com/api/mensajes/1" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_TOKEN"

Example Response

{
  "data": {
    "id": 1,
    "attributes": {
      "nombre": "Pedro Martínez",
      "email": "[email protected]",
      "mensaje": [
        {
          "type": "paragraph",
          "children": [
            {"type": "text", "text": "Hola, quisiera información sobre las próximas competencias..."}
          ]
        }
      ],
      "fecha": "2024-01-22T14:30:00.000Z",
      "respondido": false,
      "publishedAt": "2024-01-22T14:30:00.000Z",
      "createdAt": "2024-01-22T14:30:00.000Z",
      "updatedAt": "2024-01-22T14:30:00.000Z"
    }
  }
}

Create a Mensaje

Create a new contact message. This is typically used by contact forms on the frontend.

Request Body

data
object
required

Response

data
object
The created mensaje object

Example Request

curl -X POST "https://api.example.com/api/mensajes" \
  -H "Content-Type: application/json" \
  -d '{
    "data": {
      "nombre": "Sofía López",
      "email": "[email protected]",
      "mensaje": [
        {
          "type": "paragraph",
          "children": [{"type": "text", "text": "Me gustaría inscribirme en la próxima carrera. ¿Cuáles son los requisitos?"}]
        }
      ],
      "fecha": "2024-01-25T16:00:00.000Z"
    }
  }'

Example Response

{
  "data": {
    "id": 2,
    "attributes": {
      "nombre": "Sofía López",
      "email": "[email protected]",
      "mensaje": [
        {
          "type": "paragraph",
          "children": [{"type": "text", "text": "Me gustaría inscribirme en la próxima carrera. ¿Cuáles son los requisitos?"}]
        }
      ],
      "fecha": "2024-01-25T16:00:00.000Z",
      "respondido": false,
      "publishedAt": null,
      "createdAt": "2024-01-25T16:00:00.000Z",
      "updatedAt": "2024-01-25T16:00:00.000Z"
    }
  }
}

Update a Mensaje

Update an existing message by its ID. Commonly used to mark messages as responded.

Path Parameters

id
number
required
The unique identifier of the message to update

Request Body

data
object
required
Mensaje fields to update (same structure as Create)

Response

data
object
The updated mensaje object

Example Request

curl -X PUT "https://api.example.com/api/mensajes/1" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -d '{
    "data": {
      "respondido": true
    }
  }'

Example Response

{
  "data": {
    "id": 1,
    "attributes": {
      "nombre": "Pedro Martínez",
      "email": "[email protected]",
      "mensaje": [...],
      "fecha": "2024-01-22T14:30:00.000Z",
      "respondido": true,
      "publishedAt": "2024-01-22T14:30:00.000Z",
      "createdAt": "2024-01-22T14:30:00.000Z",
      "updatedAt": "2024-01-25T17:00:00.000Z"
    }
  }
}

Delete a Mensaje

Delete a message by its ID.

Path Parameters

id
number
required
The unique identifier of the message to delete

Response

data
object
The deleted mensaje object

Example Request

curl -X DELETE "https://api.example.com/api/mensajes/1" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_TOKEN"

Example Response

{
  "data": {
    "id": 1,
    "attributes": {
      "nombre": "Pedro Martínez",
      "email": "[email protected]",
      "mensaje": [...],
      "fecha": "2024-01-22T14:30:00.000Z",
      "respondido": true,
      "publishedAt": "2024-01-22T14:30:00.000Z",
      "createdAt": "2024-01-22T14:30:00.000Z",
      "updatedAt": "2024-01-25T17:00:00.000Z"
    }
  }
}
Important: Deleting a message is permanent and cannot be undone. Consider archiving messages instead of deleting them for record-keeping purposes.

Message Management Tips

Filtering Unresponded Messages

To get all messages that haven’t been responded to:
GET /api/mensajes?filters[respondido][$eq]=false&sort=fecha:asc

Marking Messages as Responded

After responding to a message via email or other means, update the message:
PUT /api/mensajes/:id
{
  "data": {
    "respondido": true
  }
}

Date Filtering

To get messages from a specific date range:
GET /api/mensajes?filters[fecha][$gte]=2024-01-01&filters[fecha][$lte]=2024-01-31

Build docs developers (and LLMs) love