Skip to main content

Update Profile

These endpoints allow you to update the user's profile information and avatar.

Update Profile Information​

Endpoint​

  • Method: PATCH
  • URL: /api/users/profile

Request Headers​

HeaderValueRequired
Content-Typeapplication/jsonYes
Acceptapplication/jsonYes
AuthorizationBearer YOUR_API_TOKENYes

Request Body Parameters​

ParameterTypeRequiredDescription
namestringNoUser's full name
emailstringNoUser's email address (ignored for Apple Private Relay emails)
phonestringNoUser's phone number (must be valid format based on country)
marital_statusstringNoUser's marital status (SINGLE/MARRIED/OTHER)
date_of_birthstringNoUser's date of birth (YYYY-MM-DD)
genderstringNoUser's gender (MALE/FEMALE)
country_idintegerNoID of user's country
nationalityintegerNoID of user's nationality
income_level_idintegerNoID of user's income level
education_level_idintegerNoID of user's education level
language_appstringNoPreferred app language (ARABIC/ENGLISH)
background_typestringNoBackground preference (AUTO/FIXED)
interest_idsarrayNoArray of valid interest IDs
hobby_idsarrayNoArray of valid hobby IDs
avatarfileNoProfile image (jpeg, png, jpg, max: 1MB)

Success Response​

{
"success": true,
"message": "Data has been updated successfully",
"data": {
"id": 1,
"name": "John Doe",
"email": "john@example.com",
"profile": {
"phone": "+966500000000",
"gender": "MALE",
"marital_status": "SINGLE",
"date_of_birth": "1990-01-01",
"country_id": 1,
"nationality": 1,
"income_level_id": 2,
"education_level_id": 3,
"language_app": "ENGLISH",
"profile_progress": 85,
"reminders_per_day": 5,
"start_time": "09:00",
"end_time": "21:00",
"background_type": "AUTO"
},
"interests": [
{
"id": 1,
"name": "Technology"
}
],
"hobbies": [
{
"id": 1,
"name": "Reading"
}
]
},
"status_code": 200
}

Error Responses​

Validation Error (422)​

{
"success": false,
"message": "The email has already been taken",
"data": null,
"status_code": 422
}

Note: The response will contain only the first validation error message encountered.

Profile Not Found (404)​

{
"success": false,
"message": "Record not found",
"data": null,
"status_code": 404
}

Unauthorized (401)​

{
"success": false,
"message": "Unauthenticated",
"data": null,
"status_code": 401
}

Validation Rules​

  • email: Must be a valid email address and unique (except for Apple Private Relay emails)
  • phone: Must be unique and in valid international format based on the selected country
  • marital_status: Must be one of: SINGLE, MARRIED, OTHER
  • date_of_birth: Must be a valid date in YYYY-MM-DD format
  • gender: Must be either MALE or FEMALE
  • country_id: Must exist in countries table
  • income_level_id: Must exist in income_levels table
  • language_app: Must be either ARABIC or ENGLISH
  • background_type: Must be either AUTO or FIXED
  • interest_ids: Must be an array of existing interest IDs
  • hobby_ids: Must be an array of existing hobby IDs
  • avatar: Must be jpeg, png, or jpg format and less than 1MB

Example Implementation Flow​

  1. Get the user's API token from storage
  2. Prepare the update data object with only the fields to be updated
  3. Make PATCH request to /api/users/profile
  4. Upon success:
    • Update local user profile state
    • Show success message to user
    • Refresh UI to show updated information
    • Note the new profile completion percentage
  5. Upon error:
    • Display validation errors next to respective fields
    • Show appropriate error message for other types of errors
    • If unauthorized, redirect to login

Upload Avatar​

Endpoint​

  • Method: POST
  • URL: /api/users/upload-avatar

Request Headers​

HeaderValueRequired
Content-Typemultipart/form-dataYes
Acceptapplication/jsonYes
AuthorizationBearer YOUR_API_TOKENYes

Request Body Parameters​

ParameterTypeRequiredDescription
avatarfileYesImage file to upload (JPEG, PNG, or GIF)

Success Response​

{
"success": true,
"message": "Avatar has been uploaded successfully",
"data": {
"avatar_url": "https://example.com/storage/avatars/user_1_avatar.jpg"
},
"status_code": 200
}

Avatar Error Responses​

Validation Error (422)​

{
"success": false,
"message": "The given data was invalid",
"data": {
"avatar": [
"The avatar field is required",
"The avatar must be an image",
"The avatar must be less than 2MB"
]
},
"status_code": 422
}

Avatar Validation Rules​

  • File must be an image (JPEG, PNG, or GIF)
  • Maximum file size: 2MB
  • Minimum dimensions: 100x100 pixels
  • Maximum dimensions: 2000x2000 pixels

General Notes​

  • The profile progress is automatically calculated based on the completeness of the profile
  • Phone numbers are automatically formatted to E.164 format
  • Interests and hobbies are completely replaced when new arrays are provided
  • Empty or null values are ignored and won't update the existing values
  • Old avatar files are automatically deleted when a new one is uploaded
  • Uploaded images are processed and optimized for web use
  • The system generates unique filenames to prevent conflicts