Skip to main content
Three functions manage the tickets_blocked PostgreSQL table, which temporarily holds tickets during the purchase flow.

Functions overview

FunctionActionTable
tickets_lockReserve tickets for a time windowINSERT into tickets_blocked
tickets_unlockRelease all expired holdsDELETE from tickets_blocked where locked_up <= now
tickets_unlock_paramRelease specific tickets by IDDELETE from tickets_blocked by ticket_id

tickets_lock

Reserves a set of tickets for a specified time window. Before inserting, the function checks that all requested tickets are available (not sold, not already blocked).

Endpoint

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

Request body

data.ticketd_reserved
array
required
Array of ticket_id strings to lock.
data.reserved_time
number
required
Duration of the hold in seconds. The locked_up expiry timestamp is calculated as now + reserved_time.

Example

curl -X POST https://{region}-{project}.cloudfunctions.net/tickets_lock \
  -H "Content-Type: application/json" \
  -d '{
    "data": {
      "ticketd_reserved": [
        "JAOTIiQrtU1fMWZZY2IZ-nGxHQ00YzCg9PphEwlYb",
        "JAOTIiQrtU1fMWZZY2IZ-LqQTJHAGEkdwzrbcScWe"
      ],
      "reserved_time": 600
    }
  }'

What it does

  1. Queries tickets to verify all requested tickets have status = true (available). Returns 400 with a nodisponible list if any are sold.
  2. Queries tickets_blocked to check none of the tickets are already locked. Returns 400 with a nodisponible list if any are already held.
  3. Inserts a row for each ticket into tickets_blocked with ticket_id, locked_up (expiry), and date_created.

Response

message
string
Outcome description.
status
number
200 on success, 400 if any tickets are unavailable.
data
object
Success (200):
{
  "message": "Tickets blocked",
  "status": 200,
  "data": {
    "valido": true,
    "tickets": [
      "JAOTIiQrtU1fMWZZY2IZ-nGxHQ00YzCg9PphEwlYb",
      "JAOTIiQrtU1fMWZZY2IZ-LqQTJHAGEkdwzrbcScWe"
    ]
  }
}
Tickets unavailable (400):
{
  "message": "Tickets no disponibles",
  "status": 400,
  "data": {
    "valido": false,
    "nodisponible": ["JAOTIiQrtU1fMWZZY2IZ-nGxHQ00YzCg9PphEwlYb"]
  }
}

tickets_unlock

Deletes all rows from tickets_blocked where the locked_up expiry timestamp is in the past. Run this on a schedule or before displaying ticket availability to clear stale holds.

Endpoint

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

Request body

No request body is required.

Example

curl -X POST https://{region}-{project}.cloudfunctions.net/tickets_unlock \
  -H "Content-Type: application/json" \
  -d '{}'

Response

{
  "message": "Actualizado",
  "status": 200,
  "data": { "valido": true }
}
This function always returns 200. It does not report how many rows were deleted.

tickets_unlock_param

Deletes specific tickets from tickets_blocked by their ticket_id. Use this to explicitly release a hold when a user abandons their cart or when a payment fails.

Endpoint

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

Request body

data.ticketd_reserved
array
required
Array of ticket_id strings to unlock. Each value must match a ticket_id in the tickets_blocked table.

Example

curl -X POST https://{region}-{project}.cloudfunctions.net/tickets_unlock_param \
  -H "Content-Type: application/json" \
  -d '{
    "data": {
      "ticketd_reserved": [
        "JAOTIiQrtU1fMWZZY2IZ-nGxHQ00YzCg9PphEwlYb",
        "JAOTIiQrtU1fMWZZY2IZ-LqQTJHAGEkdwzrbcScWe"
      ]
    }
  }'

Response

{
  "message": "Actualizado",
  "status": 200,
  "data": { "valido": true }
}
This function always returns 200. If none of the specified ticket IDs exist in tickets_blocked, the delete is a no-op.

Build docs developers (and LLMs) love