Frappe Framework supports multiple authentication methods for API requests. Choose the method that best fits your use case.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/frappe/frappe/llms.txt
Use this file to discover all available pages before exploring further.
Authentication methods
API key and secret
The recommended method for programmatic access. API keys are generated per user and provide secure authentication without exposing passwords.Generating API keys
API keys can be generated from the User form or programmatically: From the UI:- Navigate to User list
- Open the user for which you want to generate keys
- Click on “API Access” section
- Click “Generate Keys”
Using API keys
API keys can be sent using two authentication schemes: Basic authentication:Custom authorization source
You can authenticate using API keys from DocTypes other than User by specifying theFrappe-Authorization-Source header:
api_keyfield (Data)api_secretfield (Password)userfield (Link to User)enabledfield (Check)
OAuth 2.0
Frappe supports OAuth 2.0 for third-party application access using Bearer tokens.Using OAuth tokens
- Validates bearer tokens against the OAuth Bearer Token DocType
- Checks required scopes for the endpoint
- Sets the user from the token’s associated user
Session-based authentication
For web applications, you can use session cookies after logging in:Login endpoint
Using the session
Logout endpoint
Custom authentication hooks
Implement custom authentication logic using theauth_hooks hook in your app:
hooks.py:
CSRF tokens
For session-based authentication, CSRF tokens are required for unsafe HTTP methods (POST, PUT, DELETE, PATCH).Getting the CSRF token
The CSRF token is available in the session data after login:Sending the CSRF token
Include the token in one of these ways: As a header:Bypassing CSRF
CSRF validation is skipped when:- Using API key/secret authentication
- Using OAuth bearer tokens
ignore_csrfis set in site configuration- Request comes from an allowed referrer (configured in
allowed_referrers)
Security best practices
Protect your API keys
Protect your API keys
- Never commit API keys to version control
- Store keys in environment variables or secure vaults
- Rotate keys regularly
- Use separate keys for different environments
Use HTTPS
Use HTTPS
Always use HTTPS in production to encrypt API keys and data in transit.
Implement IP restrictions
Implement IP restrictions
Configure IP restrictions on User documents to limit API access to specific IP addresses.
Monitor API usage
Monitor API usage
Enable API request logging in System Settings to track and audit API usage.
Principle of least privilege
Principle of least privilege
Grant users only the minimum permissions needed for their API operations.
Authentication errors
Common authentication errors and their meanings:| Error | Description |
|---|---|
401 Unauthorized | Missing or invalid authentication credentials |
403 Forbidden | Valid credentials but insufficient permissions |
InvalidAuthorizationToken | Malformed or invalid token format |
AuthenticationError | Generic authentication failure |
CSRFTokenError | Missing or invalid CSRF token for session auth |
Example: Complete authentication flow
Here’s a complete example using API keys in Python:Next steps
Resource endpoints
Learn CRUD operations on DocTypes
Method endpoints
Call custom Python methods