MENU navbar-image

Introduction

The MoodSync API is a robust platform for developing mental health applications that empower users to track emotional well-being and enable professionals to detect and respond to potential crises. Built on Laravel with Sanctum authentication, it provides endpoints for user registration (POST /api/register), login (POST /api/login), mood tracking (POST /api/mood-entries), and admin crisis management (GET /api/admin/crises). A sophisticated crisis detection system identifies risks by analyzing user inactivity (e.g., sudden cessation of logging after consistent use) and crisis-related keywords in notes (e.g., "hopeless," "want to die"), triggering alerts for professional intervention.

Real-World Impact

This API serves:

Developed by Abdallah Khattab.

See the Getting Started section below for usage instructions.

Getting Started

The MoodSync API enables developers to create mental health applications with secure mood tracking and advanced crisis detection. Built with Laravel and Sanctum, it offers endpoints for user authentication, mood logging, and admin crisis management. The crisis detection system monitors user inactivity (e.g., no mood entries after consistent logging) and scans notes for keywords like "hopeless" or "want to die," triggering alerts for professionals. Most endpoints require a Bearer token, and admin-only endpoints (e.g., http://localhost/api/admin/crises) require an admin role. This API addresses real-world mental health challenges by promoting self-awareness, enabling early crisis intervention, and supporting professional care.

Authentication

Authenticate using Laravel Sanctum to access protected endpoints:

  1. Register or Log In:

    • Use POST http://localhost/api/register to create a user account and receive a Bearer token.
    • Use POST http://localhost/api/login to authenticate and obtain a token.
    • Example login request:
      curl -X POST http://localhost/api/login \
       -H "Content-Type: application/json" \
       -H "Accept: application/json" \
       -d '{"email": "[email protected]", "password": "password123"}'
    • The response includes a token (e.g., 1|abcdef1234567890).
  2. Use the Token:

    • Include the token in the Authorization header:
      Authorization: Bearer 1|abcdef1234567890
    • Example authenticated request:
      curl -X POST http://localhost/api/mood-entries \
       -H "Authorization: Bearer 1|abcdef1234567890" \
       -H "Content-Type: application/json" \
       -H "Accept: application/json" \
       -d '{"mood": "sad", "intensity": 8, "notes": "Feeling hopeless today"}'
  3. Admin Access:

    • Admin endpoints (e.g., GET http://localhost/api/admin/crises) require an admin role.
    • admin credentials email:[email protected] password:password

Real-World Applications

Testing Endpoints

Warning

Explore the endpoint sections below for detailed usage.

Authenticating requests

This API is not authenticated.

Admin Management

APIs for managing users and their mood data, accessible only by admin users. to access these endpoints login in with these credentials email:"[email protected]" password:"password"

Get users overview

requires authentication

Retrieves an overview of all users with their recent mood entries (up to 5 per user) and mood entry counts.

Example request:
curl --request GET \
    --get "https://nawasrah.site/moodsync/api/admin/users" \
    --header "Authorization: Bearer {token} Example: Bearer 1|abcdef1234567890" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json"
const url = new URL(
    "https://nawasrah.site/moodsync/api/admin/users"
);

const headers = {
    "Authorization": "Bearer {token} Example: Bearer 1|abcdef1234567890",
    "Content-Type": "application/json",
    "Accept": "application/json",
};

fetch(url, {
    method: "GET",
    headers,
}).then(response => response.json());

Example response (200):


{
    "success": true,
    "data": {
        "data": [
            {
                "id": 1,
                "name": "John Doe",
                "email": "[email protected]",
                "mood_entries_count": 10,
                "recent_mood_entries": [
                    {
                        "id": 1,
                        "mood": "happy",
                        "intensity": 7,
                        "notes": "Feeling great today!",
                        "date": "2025-06-12"
                    }
                ]
            }
        ]
    },
    "message": "Users overview fetched successfully"
}
 

Example response (401):


{
    "success": false,
    "data": [],
    "message": "Unauthenticated",
    "status": 401
}
 

Example response (403):


{
    "success": false,
    "data": [],
    "message": "Unauthorized: Admin role required",
    "status": 403
}
 

Request      

GET api/admin/users

Headers

Authorization      

Example: Bearer {token} Example: Bearer 1|abcdef1234567890

Content-Type      

Example: application/json

Accept      

Example: application/json

Get user details

requires authentication

Retrieves detailed information about a specific user, including their mood entries and admin notes, filtered by month and year if provided.

Example request:
curl --request GET \
    --get "https://nawasrah.site/moodsync/api/admin/users/1?month=6&year=2025" \
    --header "Authorization: Bearer {token} Example: Bearer 1|abcdef1234567890" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json"
const url = new URL(
    "https://nawasrah.site/moodsync/api/admin/users/1"
);

const params = {
    "month": "6",
    "year": "2025",
};
Object.keys(params)
    .forEach(key => url.searchParams.append(key, params[key]));

const headers = {
    "Authorization": "Bearer {token} Example: Bearer 1|abcdef1234567890",
    "Content-Type": "application/json",
    "Accept": "application/json",
};

fetch(url, {
    method: "GET",
    headers,
}).then(response => response.json());

Example response (200):


{
    "success": true,
    "data": {
        "user": {
            "id": 1,
            "name": "John Doe",
            "email": "[email protected]",
            "role": "user",
            "mood_entries": [
                {
                    "id": 1,
                    "mood": "sad",
                    "intensity": 8,
                    "notes": "Feeling hopeless",
                    "date": "2025-06-12"
                }
            ],
            "admin_notes": [
                {
                    "id": 1,
                    "note": "User reported low mood.",
                    "user_id": 1,
                    "admin_id": 2,
                    "created_at": "2025-06-12 17:16:00"
                }
            ]
        },
        "stats": {
            "total_entries": 5,
            "mood_distribution": {
                "sad": 3,
                "happy": 2
            },
            "average_intensity": 7.2,
            "most_common_mood": "sad",
            "recommendations": [
                "🌷 It's okay to feel sad sometimes. Consider reaching out to loved ones or doing something comforting."
            ]
        }
    },
    "message": "User details fetched successfully"
}
 

Example response (401):


{
    "success": false,
    "data": [],
    "message": "Unauthenticated",
    "status": 401
}
 

Example response (403):


{
    "success": false,
    "data": [],
    "message": "Unauthorized: Admin role required",
    "status": 403
}
 

Example response (404):


{
    "success": false,
    "data": [],
    "message": "No data found for the selected month/year.",
    "status": 404
}
 

Request      

GET api/admin/users/{userId}

Headers

Authorization      

Example: Bearer {token} Example: Bearer 1|abcdef1234567890

Content-Type      

Example: application/json

Accept      

Example: application/json

URL Parameters

userId   integer   

The ID of the user. Example: 1

Query Parameters

month   integer  optional  

optional Filter mood entries and notes by month (1-12). Example: 6

year   integer  optional  

optional Filter mood entries and notes by year. Example: 2025

Add a note for a user

requires authentication

Allows an admin to add a note for a specific user.

Example request:
curl --request POST \
    "https://nawasrah.site/moodsync/api/admin/users/architecto/notes" \
    --header "Authorization: Bearer {token} Example: Bearer 1|abcdef1234567890" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    --data "{
    \"note\": \"User reported low mood.\"
}"
const url = new URL(
    "https://nawasrah.site/moodsync/api/admin/users/architecto/notes"
);

const headers = {
    "Authorization": "Bearer {token} Example: Bearer 1|abcdef1234567890",
    "Content-Type": "application/json",
    "Accept": "application/json",
};

let body = {
    "note": "User reported low mood."
};

fetch(url, {
    method: "POST",
    headers,
    body: JSON.stringify(body),
}).then(response => response.json());

Example response (200):


{
    "success": true,
    "data": {
        "data": {
            "id": 1,
            "note": "User reported low mood.",
            "user_id": 1,
            "admin_id": 2,
            "created_at": "2025-06-12 17:16:00",
            "admin": {
                "id": 2,
                "name": "Admin User",
                "email": "[email protected]"
            }
        }
    },
    "message": "Note added successfully"
}
 

Example response (401):


{
    "success": false,
    "data": [],
    "message": "Unauthenticated",
    "status": 401
}
 

Example response (403):


{
    "success": false,
    "data": [],
    "message": "Unauthorized: Admin role required",
    "status": 403
}
 

Example response (422):


{
    "success": false,
    "data": {
        "errors": {
            "note": [
                "The note field is required."
            ]
        }
    },
    "message": "Validation failed",
    "status": 422
}
 

Request      

POST api/admin/users/{user}/notes

Headers

Authorization      

Example: Bearer {token} Example: Bearer 1|abcdef1234567890

Content-Type      

Example: application/json

Accept      

Example: application/json

URL Parameters

user   string   

The user. Example: architecto

userId   integer   

The ID of the user. Example: 1

Body Parameters

note   string   

The note content. Example: User reported low mood.

Authentication

APIs for user authentication and token management.

Register a new user

Creates a new user account and returns a Sanctum token.

Example request:
curl --request POST \
    "https://nawasrah.site/moodsync/api/register" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    --data "{
    \"name\": \"John Doe\",
    \"email\": \"[email protected]\",
    \"password\": \"Password123\",
    \"password_confirmation\": \"Password123\"
}"
const url = new URL(
    "https://nawasrah.site/moodsync/api/register"
);

const headers = {
    "Content-Type": "application/json",
    "Accept": "application/json",
};

let body = {
    "name": "John Doe",
    "email": "[email protected]",
    "password": "Password123",
    "password_confirmation": "Password123"
};

fetch(url, {
    method: "POST",
    headers,
    body: JSON.stringify(body),
}).then(response => response.json());

Example response (201):


{
    "success": true,
    "data": {
        "user": {
            "id": 1,
            "name": "John Doe",
            "email": "[email protected]",
            "created_at": "2025-06-12T17:16:00.000000Z",
            "updated_at": "2025-06-12T17:16:00.000000Z"
        },
        "token": "1|abcdef1234567890",
        "token_type": "Bearer"
    },
    "message": "User Registered successfully"
}
 

Example response (422):


{
    "success": false,
    "data": {
        "errors": {
            "email": [
                "The email field is required."
            ]
        }
    },
    "message": "Validation failed",
    "status": 422
}
 

Request      

POST api/register

Headers

Content-Type      

Example: application/json

Accept      

Example: application/json

Body Parameters

name   string   

The name of the user. Example: John Doe

email   string   

The email address of the user. Must be a valid email. Example: [email protected]

password   string   

The password for the user. Must be at least 8 characters. Example: Password123

password_confirmation   string   

The password for the user. Must be at least 8 characters. Example: Password123

Log in a user if you want login as admin use these credintials => email = "[email protected]" => password = "password" Authenticates a user and returns a Sanctum token.

Example request:
curl --request POST \
    "https://nawasrah.site/moodsync/api/login" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    --data "{
    \"email\": \"[email protected]\",
    \"password\": \"Password123\"
}"
const url = new URL(
    "https://nawasrah.site/moodsync/api/login"
);

const headers = {
    "Content-Type": "application/json",
    "Accept": "application/json",
};

let body = {
    "email": "[email protected]",
    "password": "Password123"
};

fetch(url, {
    method: "POST",
    headers,
    body: JSON.stringify(body),
}).then(response => response.json());

Example response (200):


{
    "success": true,
    "data": {
        "user": {
            "id": 1,
            "name": "John Doe",
            "email": "[email protected]",
            "created_at": "2025-06-12T17:16:00.000000Z",
            "updated_at": "2025-06-12T17:16:00.000000Z"
        },
        "token": "2|xyz1234567890",
        "token_type": "Bearer"
    },
    "message": "Login successful"
}
 

Example response (401):


{
    "success": false,
    "data": [],
    "message": "Invalid credentials",
    "status": 401
}
 

Request      

POST api/login

Headers

Content-Type      

Example: application/json

Accept      

Example: application/json

Body Parameters

email   string   

The email address of the user. Must be a valid email. Example: [email protected]

password   string   

The password for the user. Example: Password123

Log out the current session

requires authentication

Revokes the current access token, logging out the user from the current session.

Example request:
curl --request POST \
    "https://nawasrah.site/moodsync/api/logout" \
    --header "Authorization: Bearer {token} Example: Bearer 1|abcdef1234567890" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json"
const url = new URL(
    "https://nawasrah.site/moodsync/api/logout"
);

const headers = {
    "Authorization": "Bearer {token} Example: Bearer 1|abcdef1234567890",
    "Content-Type": "application/json",
    "Accept": "application/json",
};

fetch(url, {
    method: "POST",
    headers,
}).then(response => response.json());

Example response (200):


{
    "success": true,
    "data": [],
    "message": "Successfully logged out"
}
 

Request      

POST api/logout

Headers

Authorization      

Example: Bearer {token} Example: Bearer 1|abcdef1234567890

Content-Type      

Example: application/json

Accept      

Example: application/json

Log out from all devices

requires authentication

Revokes all access tokens for the authenticated user, logging them out from all devices.

Example request:
curl --request POST \
    "https://nawasrah.site/moodsync/api/logout-all" \
    --header "Authorization: Bearer {token} Example: Bearer 1|abcdef1234567890" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json"
const url = new URL(
    "https://nawasrah.site/moodsync/api/logout-all"
);

const headers = {
    "Authorization": "Bearer {token} Example: Bearer 1|abcdef1234567890",
    "Content-Type": "application/json",
    "Accept": "application/json",
};

fetch(url, {
    method: "POST",
    headers,
}).then(response => response.json());

Example response (200):


{
    "success": true,
    "data": [],
    "message": "Successfully logged out from all devices"
}
 

Request      

POST api/logout-all

Headers

Authorization      

Example: Bearer {token} Example: Bearer 1|abcdef1234567890

Content-Type      

Example: application/json

Accept      

Example: application/json

Get user tokens

requires authentication

Returns a list of active tokens for the authenticated user.

Example request:
curl --request GET \
    --get "https://nawasrah.site/moodsync/api/tokens" \
    --header "Authorization: Bearer {token} Example: Bearer 1|abcdef1234567890" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json"
const url = new URL(
    "https://nawasrah.site/moodsync/api/tokens"
);

const headers = {
    "Authorization": "Bearer {token} Example: Bearer 1|abcdef1234567890",
    "Content-Type": "application/json",
    "Accept": "application/json",
};

fetch(url, {
    method: "GET",
    headers,
}).then(response => response.json());

Example response (200):


{
    "success": true,
    "data": {
        "tokens": [
            {
                "id": 1,
                "name": "auth_token",
                "created_at": "2025-06-12T17:16:00.000000Z"
            },
            {
                "id": 2,
                "name": "auth_token",
                "created_at": "2025-06-12T17:17:00.000000Z"
            }
        ]
    },
    "message": ""
}
 

Example response (401):


{
    "success": false,
    "data": [],
    "message": "Unauthenticated",
    "status": 401
}
 

Request      

GET api/tokens

Headers

Authorization      

Example: Bearer {token} Example: Bearer 1|abcdef1234567890

Content-Type      

Example: application/json

Accept      

Example: application/json

Revoke a specific token

requires authentication

Revokes a specific token by its ID for the authenticated user.

Example request:
curl --request DELETE \
    "https://nawasrah.site/moodsync/api/tokens/architecto" \
    --header "Authorization: Bearer {token} Example: Bearer 1|abcdef1234567890" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    --data "{
    \"token_id\": 1
}"
const url = new URL(
    "https://nawasrah.site/moodsync/api/tokens/architecto"
);

const headers = {
    "Authorization": "Bearer {token} Example: Bearer 1|abcdef1234567890",
    "Content-Type": "application/json",
    "Accept": "application/json",
};

let body = {
    "token_id": 1
};

fetch(url, {
    method: "DELETE",
    headers,
    body: JSON.stringify(body),
}).then(response => response.json());

Example response (200):


{
    "success": true,
    "data": [],
    "message": "Token revoked successfully"
}
 

Example response (404):


{
    "success": false,
    "data": {
        "message": "Token not found"
    },
    "message": "Token not found",
    "status": 404
}
 

Example response (422):


{
    "success": false,
    "data": {
        "errors": {
            "token_id": [
                "The token_id field is required."
            ]
        }
    },
    "message": "Validation failed",
    "status": 422
}
 

Request      

DELETE api/tokens/{token_id}

Headers

Authorization      

Example: Bearer {token} Example: Bearer 1|abcdef1234567890

Content-Type      

Example: application/json

Accept      

Example: application/json

URL Parameters

token_id   string   

The ID of the token. Example: architecto

Body Parameters

token_id   integer   

The ID of the token to revoke. Example: 1

Crisis Management

APIs for managing crisis alerts. These endpoints are restricted to admin users.

Get active crisis alerts

requires authentication

Retrieves all active crisis alerts, sorted by crisis level and triggered date.

Example request:
curl --request GET \
    --get "https://nawasrah.site/moodsync/api/admin/crises" \
    --header "Authorization: Bearer {token} Example: Bearer 1|abcdef1234567890" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json"
const url = new URL(
    "https://nawasrah.site/moodsync/api/admin/crises"
);

const headers = {
    "Authorization": "Bearer {token} Example: Bearer 1|abcdef1234567890",
    "Content-Type": "application/json",
    "Accept": "application/json",
};

fetch(url, {
    method: "GET",
    headers,
}).then(response => response.json());

Example response (200):


{
    "success": true,
    "data": {
        "data": [
            {
                "id": 1,
                "user_id": 1,
                "mood_entry_id": 1,
                "crisis_level": 5,
                "status": "active",
                "triggered_at": "2025-06-12T17:16:00.000000Z",
                "keywords_found": [
                    "hopeless",
                    "want to die"
                ],
                "context": {
                    "consecutive_negative_days": 3,
                    "mood_decline": true,
                    "recent_entries": []
                },
                "user": {
                    "id": 1,
                    "name": "John Doe",
                    "email": "[email protected]"
                },
                "mood_entry": {
                    "id": 1,
                    "mood": "sad",
                    "intensity": 8,
                    "notes": "Feeling hopeless and want to die",
                    "date": "2025-06-12"
                }
            }
        ]
    },
    "message": "Crises retrieved successfully"
}
 

Example response (401):


{
    "success": false,
    "data": [],
    "message": "Unauthenticated",
    "status": 401
}
 

Request      

GET api/admin/crises

Headers

Authorization      

Example: Bearer {token} Example: Bearer 1|abcdef1234567890

Content-Type      

Example: application/json

Accept      

Example: application/json

Get responded crisis alerts

requires authentication

Retrieves all crisis alerts that have been responded to, sorted by crisis level and triggered date.

Example request:
curl --request GET \
    --get "https://nawasrah.site/moodsync/api/admin/crises/responded" \
    --header "Authorization: Bearer {token} Example: Bearer 1|abcdef1234567890" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json"
const url = new URL(
    "https://nawasrah.site/moodsync/api/admin/crises/responded"
);

const headers = {
    "Authorization": "Bearer {token} Example: Bearer 1|abcdef1234567890",
    "Content-Type": "application/json",
    "Accept": "application/json",
};

fetch(url, {
    method: "GET",
    headers,
}).then(response => response.json());

Example response (200):


{
    "success": true,
    "data": {
        "data": [
            {
                "id": 2,
                "user_id": 1,
                "mood_entry_id": 2,
                "crisis_level": 4,
                "status": "responded",
                "triggered_at": "2025-06-11T14:00:00.000000Z",
                "keywords_found": [
                    "I’m alone"
                ],
                "context": {
                    "consecutive_negative_days": 2,
                    "mood_decline": false,
                    "recent_entries": []
                },
                "user": {
                    "id": 1,
                    "name": "John Doe",
                    "email": "[email protected]"
                },
                "mood_entry": {
                    "id": 2,
                    "mood": "anxious",
                    "intensity": 7,
                    "notes": "I’m alone and overwhelmed",
                    "date": "2025-06-11"
                }
            }
        ]
    },
    "message": "Crises retrieved successfully"
}
 

Example response (401):


{
    "success": false,
    "data": [],
    "message": "Unauthenticated",
    "status": 401
}
 

Request      

GET api/admin/crises/responded

Headers

Authorization      

Example: Bearer {token} Example: Bearer 1|abcdef1234567890

Content-Type      

Example: application/json

Accept      

Example: application/json

Get resolved crisis alerts

requires authentication

Retrieves all resolved crisis alerts, sorted by crisis level and triggered date.

Example request:
curl --request GET \
    --get "https://nawasrah.site/moodsync/api/admin/crises/resolved" \
    --header "Authorization: Bearer {token} Example: Bearer 1|abcdef1234567890" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json"
const url = new URL(
    "https://nawasrah.site/moodsync/api/admin/crises/resolved"
);

const headers = {
    "Authorization": "Bearer {token} Example: Bearer 1|abcdef1234567890",
    "Content-Type": "application/json",
    "Accept": "application/json",
};

fetch(url, {
    method: "GET",
    headers,
}).then(response => response.json());

Example response (200):


{
    "success": true,
    "data": {
        "data": [
            {
                "id": 4,
                "user_id": 1,
                "mood_entry_id": 4,
                "crisis_level": 4,
                "status": "resolved",
                "triggered_at": "2025-06-09T08:00:00.000000Z",
                "keywords_found": [
                    "hopeless"
                ],
                "context": {
                    "consecutive_negative_days": 2,
                    "mood_decline": true,
                    "recent_entries": []
                },
                "user": {
                    "id": 1,
                    "name": "John Doe",
                    "email": "[email protected]"
                },
                "mood_entry": {
                    "id": 4,
                    "mood": "sad",
                    "intensity": 9,
                    "notes": "Feeling hopeless",
                    "date": "2025-06-09"
                }
            }
        ]
    },
    "message": "Crises retrieved successfully"
}
 

Example response (401):


{
    "success": false,
    "data": [],
    "message": "Unauthenticated",
    "status": 401
}
 

Request      

GET api/admin/crises/resolved

Headers

Authorization      

Example: Bearer {token} Example: Bearer 1|abcdef1234567890

Content-Type      

Example: application/json

Accept      

Example: application/json

Respond to a crisis alert

requires authentication

Records a response to a specific crisis alert, updating its status to 'responded' and logging the response time.

Example request:
curl --request POST \
    "https://nawasrah.site/moodsync/api/admin/crises/1/respond" \
    --header "Authorization: Bearer {token} Example: Bearer 1|abcdef1234567890" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    --data "{
    \"response\": \"Contacted user and provided support.\",
    \"action_taken\": \"Referred to counselor.\"
}"
const url = new URL(
    "https://nawasrah.site/moodsync/api/admin/crises/1/respond"
);

const headers = {
    "Authorization": "Bearer {token} Example: Bearer 1|abcdef1234567890",
    "Content-Type": "application/json",
    "Accept": "application/json",
};

let body = {
    "response": "Contacted user and provided support.",
    "action_taken": "Referred to counselor."
};

fetch(url, {
    method: "POST",
    headers,
    body: JSON.stringify(body),
}).then(response => response.json());

Example response (200):


{
    "success": true,
    "data": {
        "data": 30
    },
    "message": "Crisis response recorded"
}
 

Example response (401):


{
    "success": false,
    "data": [],
    "message": "Unauthenticated",
    "status": 401
}
 

Example response (404):


{
    "success": false,
    "data": [],
    "message": "Crisis alert not found",
    "status": 404
}
 

Example response (422):


{
    "success": false,
    "data": {
        "errors": {
            "response": [
                "The response field is required."
            ],
            "action_taken": [
                "The action taken field is required."
            ]
        }
    },
    "message": "Validation failed",
    "status": 422
}
 

Request      

POST api/admin/crises/{alert_id}/respond

Headers

Authorization      

Example: Bearer {token} Example: Bearer 1|abcdef1234567890

Content-Type      

Example: application/json

Accept      

Example: application/json

URL Parameters

alert_id   integer   

The ID of the crisis alert to respond to. Example: 1

Body Parameters

response   string   

The admin's response to the crisis. Example: Contacted user and provided support.

action_taken   string   

The actions taken to address the crisis. Example: Referred to counselor.

Endpoints

POST api/forgot-password

Example request:
curl --request POST \
    "https://nawasrah.site/moodsync/api/forgot-password" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    --data "{
    \"email\": \"[email protected]\"
}"
const url = new URL(
    "https://nawasrah.site/moodsync/api/forgot-password"
);

const headers = {
    "Content-Type": "application/json",
    "Accept": "application/json",
};

let body = {
    "email": "[email protected]"
};

fetch(url, {
    method: "POST",
    headers,
    body: JSON.stringify(body),
}).then(response => response.json());

Request      

POST api/forgot-password

Headers

Content-Type      

Example: application/json

Accept      

Example: application/json

Body Parameters

email   string   

Must be a valid email address. Example: [email protected]

POST api/reset-password

Example request:
curl --request POST \
    "https://nawasrah.site/moodsync/api/reset-password" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    --data "{
    \"token\": \"architecto\",
    \"email\": \"[email protected]\",
    \"password\": \"-0pBNvYgxw\"
}"
const url = new URL(
    "https://nawasrah.site/moodsync/api/reset-password"
);

const headers = {
    "Content-Type": "application/json",
    "Accept": "application/json",
};

let body = {
    "token": "architecto",
    "email": "[email protected]",
    "password": "-0pBNvYgxw"
};

fetch(url, {
    method: "POST",
    headers,
    body: JSON.stringify(body),
}).then(response => response.json());

Request      

POST api/reset-password

Headers

Content-Type      

Example: application/json

Accept      

Example: application/json

Body Parameters

token   string   

Example: architecto

email   string   

Must be a valid email address. Example: [email protected]

password   string   

Must be at least 8 characters. Example: -0pBNvYgxw

GET api/user

Example request:
curl --request GET \
    --get "https://nawasrah.site/moodsync/api/user" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json"
const url = new URL(
    "https://nawasrah.site/moodsync/api/user"
);

const headers = {
    "Content-Type": "application/json",
    "Accept": "application/json",
};

fetch(url, {
    method: "GET",
    headers,
}).then(response => response.json());

Example response (404):

Show headers
cache-control: no-cache, private
content-type: application/json
 

{
    "message": "The route moodsync/api/user could not be found."
}
 

Request      

GET api/user

Headers

Content-Type      

Example: application/json

Accept      

Example: application/json

Mood Entries

APIs for managing user mood entries and retrieving mood statistics.

Create a mood entry

requires authentication

Stores a new mood entry for the authenticated user. If a mood entry already exists for the given date, an error is returned.

Example request:
curl --request POST \
    "https://nawasrah.site/moodsync/api/mood-entries" \
    --header "Authorization: Bearer {token} Example: Bearer 1|abcdef1234567890" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    --data "{
    \"mood\": \"happy\",
    \"intensity\": 5,
    \"notes\": \"Feeling optimistic today.\",
    \"date\": \"2025-06-12\"
}"
const url = new URL(
    "https://nawasrah.site/moodsync/api/mood-entries"
);

const headers = {
    "Authorization": "Bearer {token} Example: Bearer 1|abcdef1234567890",
    "Content-Type": "application/json",
    "Accept": "application/json",
};

let body = {
    "mood": "happy",
    "intensity": 5,
    "notes": "Feeling optimistic today.",
    "date": "2025-06-12"
};

fetch(url, {
    method: "POST",
    headers,
    body: JSON.stringify(body),
}).then(response => response.json());

Example response (201):


{
    "success": true,
    "data": {
        "data": {
            "id": 1,
            "mood": "happy",
            "note": "Feeling optimistic today.",
            "date": "2025-06-12",
            "created_at": "2025-06-12T17:16:00.000000Z"
        }
    },
    "message": "Mood entry created successfully"
}
 

Example response (400):


{
    "success": false,
    "data": [],
    "message": "You have already logged your mood for this date",
    "status": 400
}
 

Example response (401):


{
    "success": false,
    "data": [],
    "message": "Unauthenticated",
    "status": 401
}
 

Example response (422):


{
    "success": false,
    "data": {
        "errors": {
            "mood": [
                "The mood field is required."
            ],
            "intensity": [
                "The intensity must be between 1 and 10."
            ]
        }
    },
    "message": "Validation failed",
    "status": 422
}
 

Request      

POST api/mood-entries

Headers

Authorization      

Example: Bearer {token} Example: Bearer 1|abcdef1234567890

Content-Type      

Example: application/json

Accept      

Example: application/json

Body Parameters

mood   string   

The user's mood. Must be one of: happy, sad, stressed, anxious, calm, angry, excited, neutral. Example: happy

intensity   integer   

The intensity of the mood (1-10). Example: 5

notes   string  optional  

optional Additional notes about the mood entry (max 1000 characters). Example: Feeling optimistic today.

date   string  optional  

optional The date of the mood entry in YYYY-MM-DD format. Defaults to today if not provided. Example: 2025-06-12

Get monthly mood statistics

requires authentication

Retrieves mood statistics for the authenticated user for a specific month and year.

Example request:
curl --request GET \
    --get "https://nawasrah.site/moodsync/api/mood-entries/monthly-stats?month=6&year=2025" \
    --header "Authorization: Bearer {token} Example: Bearer 1|abcdef1234567890" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json"
const url = new URL(
    "https://nawasrah.site/moodsync/api/mood-entries/monthly-stats"
);

const params = {
    "month": "6",
    "year": "2025",
};
Object.keys(params)
    .forEach(key => url.searchParams.append(key, params[key]));

const headers = {
    "Authorization": "Bearer {token} Example: Bearer 1|abcdef1234567890",
    "Content-Type": "application/json",
    "Accept": "application/json",
};

fetch(url, {
    method: "GET",
    headers,
}).then(response => response.json());

Example response (200):


{
    "success": true,
    "data": {
        "data": {
            "total_entries": 10,
            "mood_counts": {
                "happy": 4,
                "sad": 2,
                "neutral": 3,
                "calm": 1
            },
            "average_intensity": 4.5
        }
    },
    "message": "Monthly stats retrieved successfully"
}
 

Example response (401):


{
    "success": false,
    "data": [],
    "message": "Unauthenticated",
    "status": 401
}
 

Request      

GET api/mood-entries/monthly-stats

Headers

Authorization      

Example: Bearer {token} Example: Bearer 1|abcdef1234567890

Content-Type      

Example: application/json

Accept      

Example: application/json

Query Parameters

month   integer  optional  

optional The month for which to retrieve stats (1-12). Defaults to the current month. Example: 6

year   integer  optional  

optional The year for which to retrieve stats. Defaults to the current year. Example: 2025