Skip to main content
POST
/
api
/
users
/
createprofile
Create or Update User Profile
curl --request POST \
  --url https://api.example.com/api/users/createprofile \
  --header 'Content-Type: application/json' \
  --data '
{
  "name": "<string>",
  "address": "<string>",
  "age": 123,
  "dob": "<string>",
  "phoneNumber": 123
}
'
{
  "success": true,
  "message": "<string>",
  "data": {
    "data._id": "<string>",
    "data.name": "<string>",
    "data.address": "<string>",
    "data.age": 123,
    "data.dob": "<string>",
    "data.phoneNumber": 123,
    "data.authDetails": {},
    "data.createdAt": "<string>",
    "data.updatedAt": "<string>"
  }
}
Create a new user profile or update an existing one. This endpoint automatically determines whether to create or update based on whether a profile already exists for the authenticated user.

Authentication

This endpoint requires JWT authentication. Include the bearer token in the Authorization header.

Request Body

name
string
required
Full name of the user
address
string
required
Residential address of the user
age
number
required
Age of the user (must be between 13 and 99)
dob
string
required
Date of birth in YYYY-MM-DD format. Must be a past date.
phoneNumber
number
required
Contact phone number of the user

Response

success
boolean
Indicates if the operation was successful
message
string
Response message indicating “Profile Created” or “Profile Updated”
data
object
The created or updated profile object
data._id
string
Unique identifier for the profile
data.name
string
Full name of the user
data.address
string
Residential address
data.age
number
Age of the user
data.dob
string
Date of birth (ISO 8601 format)
data.phoneNumber
number
Contact phone number
data.authDetails
object
Populated authentication details (excluding password and internal fields)
data.createdAt
string
Timestamp when the profile was created
data.updatedAt
string
Timestamp when the profile was last updated

Request Example

curl -X POST https://api.yourchurch.com/api/users/createprofile \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -H "Content-Type: application/json" \
  -d '{
    "name": "John Doe",
    "address": "123 Main Street, Springfield",
    "age": 35,
    "dob": "1989-05-15",
    "phoneNumber": 5551234567
  }'

Response Example

Success Response (Profile Created)

{
  "success": true,
  "message": "Profile Created",
  "data": {
    "_id": "60d5ec49f1b2c72b8c8e4f3a",
    "name": "John Doe",
    "address": "123 Main Street, Springfield",
    "age": 35,
    "dob": "1989-05-15T00:00:00.000Z",
    "phoneNumber": 5551234567,
    "authDetails": {
      "email": "[email protected]",
      "isProfileComplete": true
    },
    "createdAt": "2024-03-15T10:30:00.000Z",
    "updatedAt": "2024-03-15T10:30:00.000Z"
  }
}

Success Response (Profile Updated)

{
  "success": true,
  "message": "Profile Updated",
  "data": {
    "_id": "60d5ec49f1b2c72b8c8e4f3a",
    "name": "John Doe",
    "address": "456 Oak Avenue, Springfield",
    "age": 35,
    "dob": "1989-05-15T00:00:00.000Z",
    "phoneNumber": 5551234567,
    "authDetails": {
      "email": "[email protected]",
      "isProfileComplete": true
    },
    "createdAt": "2024-03-15T10:30:00.000Z",
    "updatedAt": "2024-03-15T14:20:00.000Z"
  }
}

Error Responses

400 - Access Denied (Missing Token)

{
  "success": false,
  "message": "Acceess Denied",
  "data": "Access Token not Found"
}

400 - Access Denied (Missing Authorization Header)

{
  "success": false,
  "message": "Acceess Denied",
  "data": "Authorization missing"
}

500 - Invalid or Expired Token

{
  "success": false,
  "message": "Acccess Denied",
  "data": "jwt expired"
}

500 - Profile Creation/Update Failed

{
  "success": false,
  "message": "Profile Creation not successful",
  "data": "User validation failed: age: Path `age` (12) is less than minimum allowed value (13)."
}

Notes

  • The endpoint automatically creates a new profile if none exists for the authenticated user, or updates the existing profile
  • Upon successful profile creation or update, the user’s isProfileComplete flag is set to true in the authentication record
  • The dob field must be in YYYY-MM-DD format and must be a past date
  • Age must be between 13 and 99 years
  • All fields are required for profile creation

Build docs developers (and LLMs) love