This is the most consequential endpoint in the API. Calling it triggers the randomised Secret Santa algorithm, persists the resulting pairings to MongoDB, and immediately dispatches personalised HTML reveal emails to every participant. Because emails are sent the moment this endpoint is called, the operation cannot be undone.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Sufianeh7/AmigoInvisible/llms.txt
Use this file to discover all available pages before exploring further.
Request
Method:POSTURL:
/api/sorteos/:adminToken/lanzarHeaders:
Content-Type: application/jsonBody: Empty JSON object —
{}
Path Parameters
The UUID returned when the group was created. Must match an existing group document in MongoDB whose
estado is "borrador".Example Request
What Happens
Load the group from MongoDB
The controller performs a
Sorteo.findOne({ adminToken }) lookup. If no matching document exists, a 404 is returned immediately and no further processing occurs.Validate participant count
The number of entries in
participantes is checked. At least 3 participants are required to run a valid draw. If fewer than 3 are registered, a 404 is returned with the message "Se necesitan al menos 3 participantes.".Run the draw algorithm
generarEmparejamientos(participantes) is called. The algorithm shuffles the participant list and checks each candidate pairing against two rules:- A participant cannot be assigned to gift themselves (matched by
email). - A participant cannot be assigned to someone listed in their
exclusionesarray (matched bynombre).
Persist results to MongoDB
The generated pairings are written to
sorteo.emparejamientosActuales and the group’s estado is set to "completado". The document is saved with sorteo.save().Send reveal emails
enviarCorreosSorteo() is called with the pairings, participant list, and group name. Each participant receives a personalised HTML email revealing the name of the person they will be gifting.Response
Status:200 OK
Human-readable confirmation. Value is always
"¡Sorteo realizado y correos enviados con éxito!".Example Response
Error Responses
| Status | Scenario | Body |
|---|---|---|
404 | No group found for the supplied adminToken | { "error": "Sorteo no encontrado." } |
404 | Fewer than 3 participants registered in the group | { "error": "Se necesitan al menos 3 participantes." } |
400 | Algorithm exhausted 1,000 retries without finding a valid pairing (unsolvable exclusion conflict) | { "error": "No se pudo encontrar una combinación válida. Revisa las exclusiones." } |