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
| Header | Value | Required |
|---|---|---|
| Content-Type | application/json | Yes |
| Accept | application/json | Yes |
| Authorization | Bearer YOUR_API_TOKEN | Yes |
Request Body Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| name | string | No | User's full name |
| string | No | User's email address (ignored for Apple Private Relay emails) | |
| phone | string | No | User's phone number (must be valid format based on country) |
| marital_status | string | No | User's marital status (SINGLE/MARRIED/OTHER) |
| date_of_birth | string | No | User's date of birth (YYYY-MM-DD) |
| gender | string | No | User's gender (MALE/FEMALE) |
| country_id | integer | No | ID of user's country |
| nationality | integer | No | ID of user's nationality |
| income_level_id | integer | No | ID of user's income level |
| education_level_id | integer | No | ID of user's education level |
| language_app | string | No | Preferred app language (ARABIC/ENGLISH) |
| background_type | string | No | Background preference (AUTO/FIXED) |
| interest_ids | array | No | Array of valid interest IDs |
| hobby_ids | array | No | Array of valid hobby IDs |
| avatar | file | No | Profile 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
- Get the user's API token from storage
- Prepare the update data object with only the fields to be updated
- Make PATCH request to
/api/users/profile - Upon success:
- Update local user profile state
- Show success message to user
- Refresh UI to show updated information
- Note the new profile completion percentage
- 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
| Header | Value | Required |
|---|---|---|
| Content-Type | multipart/form-data | Yes |
| Accept | application/json | Yes |
| Authorization | Bearer YOUR_API_TOKEN | Yes |
Request Body Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| avatar | file | Yes | Image 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