Overview
The Zochil API uses token-based authentication with access tokens and device IDs. All API requests must include proper authentication headers to access protected resources.Authentication Methods
Access Token Authentication
Most API endpoints require anaccess-token header:
Admin Authentication
Admin endpoints also require amerchant-id header:
Required Headers
string
required
JWT token for user authentication. Obtained from login or registration
endpoints.
string
required
Unique identifier for the client device. Used for session management and
security.
string
Required for admin and order API endpoints. Identifies the merchant/shop
context.
User Authentication Flow
1. User Registration
2. User Login
3. Using the Access Token
Once you have an access token, include it in all subsequent requests:Admin Authentication
Admin users have additional privileges and can access merchant-specific data:Token Storage and Management
Token Storage
- User tokens: Stored in Redis with expiration
- Admin tokens: Stored in Redis with role-based metadata
- Device tokens: Stored in the devices table for session tracking
Token Expiration
- Tokens typically expire after 24 hours
- Refresh tokens may be available for long-lived sessions
- Always handle token expiration gracefully in your application
Security Best Practices
Recommended Practices
- Secure Storage: Store tokens in secure, HTTP-only cookies or encrypted local storage
- HTTPS Only: Always use HTTPS for API requests containing tokens
- Token Rotation: Implement token refresh mechanisms for long-lived applications
- Device Management: Generate unique device IDs for each client installation
- Logout Handling: Properly invalidate tokens on logout
Example Secure Implementation
Error Handling
Common authentication errors and their meanings:Next Steps
User API Reference
Detailed user authentication endpoints
Error Handling
Learn about API error responses

