Skip to main content
The create_collaborator function creates a Firebase Authentication user and writes a document to the u_collaborators Firestore collection. Collaborators are users who operate under a parent client account.

Endpoint

POST https://<region>-<project>.cloudfunctions.net/create_collaborator

Request body

All fields are nested under a top-level data key.

Required fields

data.name
string
required
Full name of the collaborator.
data.email
string
required
Email address. Used as the Firebase Authentication login credential.
data.password
string
required
Initial password for the Firebase Authentication account. Not stored in Firestore.
data.client
string
required
UID of the parent client (u_clients document ID) this collaborator belongs to.

Optional fields

data.phone
string
Contact phone number.
data.status
string
Account status. Set to true (boolean) by the validate_user_email function when the collaborator confirms their email.
data.account_type
string
Account classification used for role-based access checks by validate_user_type.
data.id
string
Government-issued identification number.
data.id_type
string
Type of identification document.

Address fields

data.city
string
City. Stored under address.city in Firestore.
data.country
string
Country. Stored under address.country in Firestore.
data.line
string
Street address line. Stored under address.line in Firestore.
data.zip_code
string
Postal code. Stored under address.zipcode in Firestore.

Example request

{
  "data": {
    "name": "Luis Ramírez",
    "email": "[email protected]",
    "password": "SecurePass123!",
    "client": "abc123xyz",
    "phone": "+58-414-555-0200",
    "status": "inactive",
    "account_type": "collaborator",
    "id": "V-18765432",
    "id_type": "cedula",
    "city": "Caracas",
    "country": "Venezuela",
    "line": "Calle 5, Residencia Las Palmas",
    "zip_code": "1060"
  }
}

What is written to Firestore

The function writes a document to u_collaborators/{uid} with the following structure:
{
  "name": "Luis Ramírez",
  "email": "[email protected]",
  "phone": "+58-414-555-0200",
  "status": "inactive",
  "account_type": "collaborator",
  "client": "abc123xyz",
  "id": "V-18765432",
  "id_type": "cedula",
  "address": {
    "city": "Caracas",
    "country": "Venezuela",
    "line": "Calle 5, Residencia Las Palmas",
    "zipcode": "1060"
  },
  "date": {
    "create": "<Firestore Timestamp>",
    "last_access": "",
    "last_update": ""
  }
}
The document ID in Firestore is the Firebase Authentication UID. The client field stores the UID of the parent client document in u_clients. The password field is never written to Firestore.

Response

Success

message
string
Confirmation message including the new UID.
status
number
200 on success.
data
object
{
  "message": " Ingresado con el ID: def456uvw .",
  "status": 200,
  "data": {
    "uid": "def456uvw"
  }
}

Error

{
  "message": "Error creando nuevo usuario:",
  "status": 400,
  "data": {
    "error": {
      "code": "auth/email-already-exists",
      "message": "The email address is already in use by another account."
    }
  }
}
If auth.createUser() fails, no Firestore document is written. The function returns 400 and stops processing.

Account activation

Collaborator accounts are typically created with an inactive status and activated through email confirmation. After creation, call validate_user_email with the collaborator’s uid and email to verify the address and set status to true in Firestore.

Build docs developers (and LLMs) love