Get Open Sessions (Admin)
Get all unclaimed chat sessions that are available for admins to claim.
Endpoint
Authentication
Required: Admin authentication token
Request
No request body required.
Response
Success (200 OK)
Returns a list of open (unclaimed) sessions.
{
"data": [
{
"id": 5,
"store_id": 12,
"admin_id": null,
"status": "open",
"last_message_at": "2025-12-16T11:05:00Z",
"created": "2025-12-16T11:00:00Z",
"updated": "2025-12-16T11:05:00Z",
"store": {
"id": 12,
"name": "Tech Store",
"logo_url": "https://example.com/logo.jpg",
"email": "store@example.com"
},
"last_message": {
"id": 123,
"session_id": 5,
"sender_type": "store",
"sender_id": 12,
"content": "I need help with shipping",
"attachment_url": "",
"attachment_type": "",
"status": "sent",
"created": "2025-12-16T11:05:00Z"
}
},
{
"id": 6,
"store_id": 15,
"admin_id": null,
"status": "open",
"last_message_at": "2025-12-16T11:10:00Z",
"created": "2025-12-16T11:10:00Z",
"updated": "2025-12-16T11:10:00Z",
"store": {
"id": 15,
"name": "Fashion Boutique",
"logo_url": "https://example.com/logo2.jpg",
"email": "info@fashionboutique.com"
},
"last_message": {
"id": 124,
"session_id": 6,
"sender_type": "store",
"sender_id": 15,
"content": "Hello?",
"attachment_url": "",
"attachment_type": "",
"status": "sent",
"created": "2025-12-16T11:10:00Z"
}
}
],
"count": 2
}
No Open Sessions
Error (401 Unauthorized)
Response Fields
| Field | Type | Description |
|---|---|---|
data |
array | Array of session objects |
count |
integer | Total number of open sessions |
Session Object Fields
| Field | Type | Description |
|---|---|---|
id |
integer | Unique session ID |
store_id |
integer | ID of the store |
admin_id |
null | Always null for open sessions |
status |
string | Always "open" for this endpoint |
last_message_at |
string | ISO 8601 timestamp of last message |
created |
string | ISO 8601 timestamp when session was created |
updated |
string | ISO 8601 timestamp of last update |
store |
object | Store information |
last_message |
object|null | Last message in the session (if any) |
The last_message object contains all message fields (id, session_id, sender_type, sender_id, content, attachment_url, attachment_type, status, created).
Example Usage
JavaScript/Fetch
async function getOpenSessions() {
const response = await fetch('/v1/chat/admin/sessions/open/', {
method: 'GET',
headers: {
'Authorization': `Token ${adminToken}`
}
});
const data = await response.json();
console.log('Open sessions:', data.count);
data.data.forEach(session => {
console.log(`Session ${session.id} from ${session.store.name}`);
});
}
Axios
import axios from 'axios';
const getOpenSessions = async () => {
try {
const response = await axios.get('/v1/chat/admin/sessions/open/', {
headers: {
'Authorization': `Token ${adminToken}`
}
});
return response.data.data; // Returns the array of sessions
} catch (error) {
console.error('Failed to get open sessions:', error);
}
};
cURL
curl -X GET "http://localhost:8000/v1/chat/admin/sessions/open/" \
-H "Authorization: Token your_admin_token_here"
Notes
- Only sessions with
status="open"andadmin_id=nullare returned - Sessions are ordered by
last_message_atdescending (most recent activity first) - The
storeobject provides information about the store for display purposes - Each session includes the
last_messageobject if messages exist - To claim a session, use the Claim Session endpoint
Typical Workflow
- Admin calls this endpoint to see available sessions
- Admin selects a session to handle
- Admin calls Claim Session with the session ID
- Session moves from "open" to "active" and appears in My Sessions
Related Endpoints
- Get My Sessions - Get sessions claimed by this admin
- Claim Session - Claim an open session
- Get Session - Get full session info with messages
- Admin WebSocket - Real-time updates