Overview
Frappe Helpdesk provides a robust backend API system built on the Frappe Framework. You can create custom API endpoints to extend functionality and integrate with external systems.API Structure
All API endpoints are located inhelpdesk/api/ directory. Each module focuses on a specific domain (tickets, agents, contacts, etc.).
Basic API Endpoint
Create a new Python file inhelpdesk/api/ or add to an existing one:
- Use
@frappe.whitelist()decorator to expose the function as an API endpoint - Add type hints for better code quality (required by
require_type_annotated_api_methods = Truein hooks.py) - Include docstrings for documentation
Real-World Examples
Example 1: Simple Action API (from agent.py)
Example 2: Document Manipulation API (from ticket.py)
Example 3: Complex List API (from doc.py)
Using Query Builder
Always preferfrappe.qb.get_query() over frappe.db.get_all() for new code:
Permission Utilities
Using Custom Decorators
Manual Permission Checks
Error Handling
Use Frappe’s built-in error handling:Real-time Updates
Publish real-time events to connected clients:Database Operations
Create Document
Update Document
Delete Document
Bulk Operations
Caching
Use Redis caching for expensive operations:Testing Your API
Test API endpoints using the Frappe console:Best Practices
- Type Annotations: Always use type hints (required in Helpdesk)
- Validation: Validate input parameters before processing
- Permissions: Always check permissions before data access
- Error Messages: Use translatable error messages with
_() - Logging: Log errors using
frappe.log_error()for debugging - Transactions: Use
frappe.db.commit()for bulk operations - Query Builder: Prefer Query Builder over raw SQL
- Documentation: Add docstrings to all API functions
- Real-time: Publish events for UI updates when data changes
- Caching: Cache expensive read operations with
@redis_cache()