/api/mail/drafts
GETRetrieve a paginated list of saved email drafts from your QMail account.
GET /api/mail/drafts
Description
The /api/mail/drafts endpoint returns a list of email drafts that have been saved but not yet sent. This endpoint supports pagination to efficiently handle large numbers of drafts.
Pagination
Results are paginated with a default page size of 50 drafts. You can adjust the limit up to 200 drafts per page using the limit query parameter.
Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
page |
integer | No | Page number for pagination (default: 1). |
limit |
integer | No | Number of drafts per page (min: 1, max: 200, default: 50). |
Response
Returns a 200 OK response with a JSON object containing the drafts and pagination metadata.
Response Properties
drafts
array of objects
Array of draft objects, each containing draft details such as ID, subject, body, recipients, and timestamps.
pagination
object
Pagination metadata object.
pagination.page
integer
Current page number.
pagination.limit
integer
Number of items per page.
pagination.total
integer
Total number of drafts.
pagination.total_pages
integer
Total number of pages available.
Example Response
{
"drafts": [
{
"id": "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6",
"subject": "Quarterly Report",
"body": "Dear team,\n\nPlease find attached...",
"recipient_ids": [101, 102],
"cc_ids": [103],
"created_at": "2025-12-15T10:30:00Z",
"updated_at": "2025-12-15T11:45:00Z"
},
{
"id": "f6e5d4c3b2a1f0e9d8c7b6a5f4e3d2c1",
"subject": "Meeting Notes",
"body": "Following up on today's meeting...",
"recipient_ids": [104],
"cc_ids": [],
"created_at": "2025-12-14T14:20:00Z",
"updated_at": "2025-12-14T14:20:00Z"
}
],
"pagination": {
"page": 1,
"limit": 50,
"total": 2,
"total_pages": 1
}
}
Try It Out
Examples
JavaScript (fetch)
const API_BASE = 'http://localhost:8080/api';
async function getDrafts(page = 1, limit = 50) {
try {
const params = new URLSearchParams({
page: page,
limit: limit
});
const response = await fetch(`${API_BASE}/mail/drafts?${params}`);
const result = await response.json();
if (response.ok) {
console.log('Drafts retrieved successfully!');
console.log(`Total drafts: ${result.pagination.total}`);
console.log(`Showing page ${result.pagination.page} of ${result.pagination.total_pages}`);
console.log('Drafts:', result.drafts);
} else {
console.error('Failed to retrieve drafts:', result.message);
}
} catch (error) {
console.error('Error retrieving drafts:', error);
}
}
// Get first page with default limit
getDrafts();
// Get second page with custom limit
getDrafts(2, 100);
cURL
# Get drafts with default pagination
curl -X GET "http://localhost:8080/api/mail/drafts"
# Get specific page with custom limit
curl -X GET "http://localhost:8080/api/mail/drafts?page=2&limit=100"
Python
import requests
API_BASE = 'http://localhost:8080/api'
def get_drafts(page=1, limit=50):
params = {
'page': page,
'limit': limit
}
try:
response = requests.get(f'{API_BASE}/mail/drafts', params=params)
result = response.json()
if response.ok:
print('Drafts retrieved successfully!')
print(f'Total drafts: {result["pagination"]["total"]}')
print(f'Showing page {result["pagination"]["page"]} of {result["pagination"]["total_pages"]}')
print(f'Drafts: {result["drafts"]}')
else:
print(f'Failed to retrieve drafts: {result.get("message", "Unknown error")}')
except Exception as e:
print(f'Error retrieving drafts: {str(e)}')
# Get first page with default limit
get_drafts()
# Get second page with custom limit
get_drafts(page=2, limit=100)