Skip to main content

send_notifications

Broadcasts a push notification to all mobile app users who have at least one order for a given event. Uses Firebase Cloud Messaging (FCM) multicast. The function:
  1. Queries all u_users documents that have a non-empty fcmToken
  2. For each user, checks if they have any orders for the given event_id
  3. Batches FCM tokens in groups of 100 and sends sendEachForMulticast
  4. Records the notification and per-recipient delivery status in PostgreSQL (notifications_send and notifications_send_detail)

Endpoint

POST https://{region}-{project}.cloudfunctions.net/send_notifications

Request

data.event_id
string
required
The Firestore event document ID. Only users with orders for this event receive the notification.
data.title
string
required
Notification title displayed on the device.
data.body
string
required
Notification body text.
data.icono
string
required
URL of the notification icon image.
{
  "data": {
    "event_id": "abc123",
    "title": "Cambio de horario",
    "body": "El evento comienza a las 8pm en lugar de las 7pm.",
    "icono": "https://example.com/icon.png"
  }
}

Response

Notifications sent:
{
  "message": "Procesado",
  "status": 200,
  "data": { "valido": true }
}
No users found:
{
  "message": "No enviados no hay usuarios",
  "status": 200
}
This function scans all users in u_users and checks their orders. For large user bases this can be slow. Notifications are sent in batches of 100 FCM tokens.

list_notifications

Queries notification delivery history from PostgreSQL, joining notifications_send_detail and notifications_send tables.

Endpoint

POST https://{region}-{project}.cloudfunctions.net/list_notifications

Request

All filters are optional. Omitting a filter returns all records.
data.uid
string
Filter by user UID to see notifications for a specific user.
data.event_id
string
Filter by event ID.
data.from
string
Start date filter on date_send (ISO 8601 format).
data.to
string
End date filter on date_send (ISO 8601 format).
{
  "data": {
    "event_id": "abc123",
    "from": "2025-01-01",
    "to": "2025-12-31"
  }
}

Response

Found:
{
  "message": "Notificaciones",
  "status": 200,
  "data": {
    "valido": true,
    "response": [
      {
        "id_notifications": 1,
        "fcmtoken": "eXample_token",
        "email": "[email protected]",
        "uid": "uid123",
        "status": true,
        "date_send": "2025-03-19T10:00:00.000Z",
        "event_id": "abc123",
        "title": "Cambio de horario",
        "body": "El evento comienza a las 8pm",
        "icon": "https://example.com/icon.png"
      }
    ]
  }
}
Not found:
{
  "message": "Notificaciones no encontradas",
  "status": 400,
  "data": { "valido": false }
}

Build docs developers (and LLMs) love