Introduction

Welcome to the Real-time Chat API. This documentation covers all endpoints for authentication, user management, and messaging features.

Demo Accounts

After running php artisan migrate --seed, you can use these pre-defined accounts to test the API permissions and features.

Email: user@example.com

Pass: password

Email: user2@example.com

Pass: password

Email: user3@example.com

Pass: password

Base URL

https://chat.yuldoshew.uz/api

Authentication & Verification

This API uses Laravel Sanctum for authentication.

AUTH: SANCTUM Requires Bearer Token
VERIFIED Requires Email Verification Account
POST

Register

/auth/register
name* string
email* string
password* string
password_confirmation* string
201 Created
{
  "status": "success",
  "status_code": 201,
  "message": "User registered successfully",
  "data": {
    "user": { "id": 4, "name": "Test", "email": "test@example.com" },
    "access_token": "1|hVX5q...",
    "token_type": "Bearer"
  }
}
POST

Login

/auth/login
email* string
password* string
200 OK
{
  "status": "success",
  "status_code": 200,
  "message": "Logged in successfully",
  "data": {
    "user": { "id": 4, "email": "test@example.com" },
    "access_token": "2|3EnW...",
    "token_type": "Bearer"
  }
}
POST

Forgot Password

/auth/forgot-password
email* string
200 OK
{
  "status": "success",
  "status_code": 200,
  "message": "We have emailed your password reset link.",
  "data": null
}
POST

Reset Password

/auth/reset-password
token* string
email* string
password* string
password_confirmation* string
200 OK
{
  "status": "success",
  "status_code": 200,
  "message": "Your password has been reset.",
  "data": null
}
GET

Current User

/user/me AUTH REQUIRED
200 OK
{
  "status": "success",
  "status_code": 200,
  "message": "User profile retrieved",
  "data": {
    "id": 4,
    "name": "Test",
    "email": "test@example.com"
  }
}
POST

Logout

/auth/logout AUTH REQUIRED
200 OK
{
  "status": "success",
  "status_code": 200,
  "message": "Successfully logged out",
  "data": null
}
POST

Resend Verification

/auth/email/verification-notification AUTH REQUIRED
200 OK
{
  "status": "success",
  "message": "Verification link sent.",
  "data": null
}
GET

Verify Email

/auth/email/verify/{id}/{hash} AUTH REQUIRED
200 OK
{
  "status": "success",
  "message": "Email verified successfully.",
  "data": null
}
DELETE

Delete Account

/user/delete AUTH REQUIRED
200 OK
{
  "status": "success",
  "message": "Account deleted successfully",
  "data": null
}
PATCH

Update Profile

/user/update AUTH REQUIRED VERIFIED
name string
email string
200 OK
{
  "status": "success",
  "message": "Profile updated successfully",
  "data": {
    "id": 4,
    "name": "New Name",
    "email": "new@example.com"
  }
}
PATCH

Update Password

/user/password/update AUTH REQUIRED VERIFIED
current_password* string
password* string
password_confirmation* string
200 OK
{
  "status": "success",
  "message": "Password updated successfully",
  "data": null
}
GET

User Search

/users/search?q={query} AUTH REQUIRED VERIFIED
q* query Search term
200 OK
{
  "status": "success",
  "message": "3 user(s) found",
  "data": [
    { "id": 1, "name": "Marjory", "email": "user@example.com" },
    { "id": 2, "name": "Rosemary", "email": "user2@example.com" }
  ]
}
GET

User Status

/users/{user_id}/status AUTH REQUIRED VERIFIED
200 OK
{
  "status": "success",
  "message": "User status retrieved",
  "data": {
    "id": 5,
    "email_verified": true,
    "created_at": "2026-01-31 17:45:40"
  }
}
GET

Group Search

/groups/search?q={query} AUTH REQUIRED VERIFIED
200 OK
{
  "status": "success",
  "message": "Public groups retrieved successfully",
  "data": [
    {
      "id": 1,
      "name": "New Group",
      "type": "group",
      "users_count": 1
    }
  ]
}
GET

List Conversations

/conversations AUTH REQUIRED VERIFIED
200 OK
{
  "status": "success",
  "data": [
    {
      "id": 2,
      "name": "My Friend",
      "type": "private",
      "unread_count": 0,
      "users": [ ... ]
    }
  ]
}
POST

Create Conversation

/conversations AUTH REQUIRED VERIFIED
type* string 'private' or 'group'
name string Group name
user_id int Required if private
username string Required if group
201 Created (Group)
{
  "status": "success",
  "message": "Conversation created successfully",
  "data": {
    "id": 1,
    "name": "New Group",
    "type": "group"
  }
}
201 Created (Private)
{
  "status": "success",
  "message": "Conversation created successfully",
  "data": {
    "id": 2,
    "name": "My Friend",
    "type": "private"
  }
}
GET

Show Conversation

/conversations/show?conversation_id={id} AUTH REQUIRED VERIFIED
200 OK
{
  "status": "success",
  "message": "Conversation details retrieved",
  "data": {
    "id": 1,
    "name": "New Group",
    "type": "group"
  }
}
POST

Add Participant

/conversations/add-participant AUTH REQUIRED VERIFIED
conversation_id* int
user_id* int
200 OK
{
  "status": "success",
  "message": "User added successfully",
  "data": {
    "id": 1,
    "users": [ ... ]
  }
}
POST

Remove Participant

/conversations/remove-participant AUTH REQUIRED VERIFIED
conversation_id* int
user_id* int
200 OK
{
  "status": "success",
  "message": "Participant removed successfully",
  "data": null
}
POST

Leave Group

/conversations/leave AUTH REQUIRED VERIFIED
conversation_id* int
200 OK
{
  "status": "success",
  "message": "You left the group",
  "data": null
}
DELETE

Delete Conversation

/conversations/delete AUTH REQUIRED VERIFIED
conversation_id* int
200 OK
{
  "status": "success",
  "message": "Conversation deleted",
  "data": null
}
GET

Get Messages

/conversations/{id}/messages AUTH REQUIRED VERIFIED
200 OK
{
  "status": "success",
  "message": "Messages retrieved successfully",
  "data": {
    "data": [
      {
        "id": 1,
        "text": "hi",
        "user_id": 5,
        "read_at": null
      }
    ],
    "total": 1
  }
}
POST

Send Message

/messages AUTH REQUIRED VERIFIED
conversation_id* int
text* string
201 Created
{
  "status": "success",
  "status_code": 201,
  "message": "Message sent successfully",
  "data": {
    "id": 1,
    "text": "hi",
    "conversation_id": 1,
    "user_id": 5
  }
}
PATCH

Read Message

/messages/{id}/read AUTH REQUIRED VERIFIED
200 OK
{
  "status": "success",
  "status_code": 200,
  "message": "Message marked as read",
  "data": null
}
DELETE

Delete Message

/messages/{id} AUTH REQUIRED VERIFIED
200 OK
{
  "status": "success",
  "status_code": 200,
  "message": "Message deleted successfully",
  "data": null
}

Broadcasting

Example for Frontend

This application uses Pusher to broadcast server-side events to the frontend. All connections require Bearer Token authentication via the built-in /broadcasting/auth endpoint.

How it works:

1

Authentication

Client connects to Pusher and requests auth for private channels using the Bearer Token.

2

Subscription

Client subscribes to specific channels (e.g., chat.15) to listen for events.

3

Event Execution

When a message is sent via API, the server broadcasts an event, and the client receives the payload instantly.

Available Channels

Channel Name Event Class
chat.{id} MessageSent, MessageRead
App.Models.User.{id} ConversationCreated
online Presence (User list)
bootstrap.js / echo-config
import Echo from 'laravel-echo';
window.Pusher = require('pusher-js');

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: 'PUSHER_APP_KEY',
    cluster: 'YOUR_CLUSTER',
    forceTLS: true,
    authEndpoint: '/api/broadcasting/auth',
    auth: {
        headers: {
            Authorization: 'Bearer ' + token
        }
    }
});
Listening to Events
// 1. Listen for new messages in a chat
window.Echo.private(`chat.${convId}`)
    .listen('MessageSent', (e) => {
        console.log("New Message:", e.text);
        // Payload: {id, text, user: {id, name}, created_at}
    })
    .listen('MessageRead', (e) => {
        // Update UI read status
        console.log("Message ID " + e.message_id + " was read");
    });

// 2. Listen for new conversations (on User channel)
window.Echo.private(`App.Models.User.${userId}`)
    .listen('ConversationCreated', (e) => {
        // Add new chat item to sidebar
        console.log("New conversation with:", e.name);
    });