Skip to main content

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 an access-token header:

Admin Authentication

Admin endpoints also require a merchant-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

Never expose access tokens in client-side code or URLs. Always store tokens securely and transmit them over HTTPS.
  1. Secure Storage: Store tokens in secure, HTTP-only cookies or encrypted local storage
  2. HTTPS Only: Always use HTTPS for API requests containing tokens
  3. Token Rotation: Implement token refresh mechanisms for long-lived applications
  4. Device Management: Generate unique device IDs for each client installation
  5. 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