POST /api/access-code
Validates an access code and attempts to add the authenticated user as a participant to the corresponding virtual class. Returns the Google Meet link if successful.
Authentication
This endpoint requires authentication. The user must be logged in with a valid session.
Request Body
The request body should be a plain string containing the access code.
8-character uppercase alphanumeric access code for the class Example: "A1B2C3D4"
Response
Response object containing class information or error message Unique identifier for the virtual class
User ID of the class creator/host
Google Meet link URL for joining the class Example: "https://meet.google.com/abc-defg-hij"
ISO 8601 datetime when the class starts
ISO 8601 datetime when the class ends
Type of class: "individual" or "grupal"
Updated count of current participants after joining
Maximum number of participants allowed
Error message describing why the access code validation failed Possible messages:
"El creador de la clase no puede unirse como participante" - Class creator cannot join as participant
"La clase ya ha finalizado." - Class has already ended
"No se encontro ninguna clase asociada a este codigo: {code}" - No class found for this code
"El usuario ya está registrado en la clase" - User is already registered in the class
"La clase ya alcanzó el número máximo de participantes" - Class has reached maximum capacity
Example Request
curl -X POST https://your-domain.com/api/access-code \
-H "Content-Type: application/json" \
-H "Cookie: authjs.session-token=YOUR_SESSION_TOKEN" \
-d '"A1B2C3D4"'
Example Success Response
{
"response" : {
"id" : "65f8a3b2c1d4e5f6a7b8c9d0" ,
"bookedById" : "65f7a2b1c0d3e4f5a6b7c8d9" ,
"htmlLink" : "https://meet.google.com/abc-defg-hij" ,
"startTime" : "2026-03-15T10:00:00.000Z" ,
"endTime" : "2026-03-15T11:00:00.000Z" ,
"classType" : "grupal" ,
"currentParticipants" : 3 ,
"maxParticipants" : 5
}
}
Example Error Responses
Show Creator Cannot Join as Participant
{
"response" : {
"message" : "El creador de la clase no puede unirse como participante"
}
}
The user who created the class is automatically added as the host and cannot join as a participant.
{
"response" : {
"message" : "La clase ya ha finalizado."
}
}
The class end time has already passed. Users cannot join classes that have finished.
{
"response" : {
"message" : "No se encontro ninguna clase asociada a este codigo: A1B2C3D4"
}
}
No virtual class was found with the provided access code.
{
"response" : {
"message" : "El usuario ya está registrado en la clase"
}
}
The user is already a participant in this class. Each user can only join once.
{
"response" : {
"message" : "La clase ya alcanzó el número máximo de participantes"
}
}
The class has reached its maximum capacity and cannot accept more participants.
Show 500 Internal Server Error
{
"error" : "Failed to fetch Google Meet link"
}
An unexpected error occurred on the server while processing the request.
Validation Flow
When an access code is submitted, the system:
Looks up the virtual class by access code
Validates that the class exists
Checks if the requesting user is the class creator (not allowed to join as participant)
Verifies the class has not ended
Confirms the class has not reached maximum capacity
Checks if the user is already registered
Adds the user as a participant in a transaction:
Creates a UserActivity record with role "participante"
Increments currentParticipants counter
Adds user ID to participantsIds array
Returns the class details including the Google Meet link
Notes
Access codes are 8-character uppercase alphanumeric strings generated automatically when a class is scheduled
The access code validation uses a database transaction to ensure data consistency
Users can only join classes that haven’t ended yet
The class creator cannot join their own class as a participant (they are automatically the host)
Each user can only join a class once