Overview
The Smartbills API uses JWT Bearer token authentication. Every API request must include a valid token in theAuthorization header. Tokens can be obtained through API keys or OAuth2 flows.
Before you begin: You need a Smartbills account and API keys to authenticate. Visit developers.smartbills.io to get started.
Authentication Header
Include your token in theAuthorization header of every request:
{token} is either:
- An API key (e.g.,
sk_live_1234567890abcdef) - An OAuth2 access token obtained through the token endpoint
Multi-Tenant Header
Smartbills is a multi-tenant platform. You must include thex-tenant-id header to specify the business context:
Locale Header
Use theAccept-Language header to receive localized responses:
en-CA, fr-CA, en-US. See Localizations for details.
Complete Request Headers
A complete authenticated request includes these headers:OAuth2 Authentication
Client Credentials Flow
Use this flow for server-to-server communication where no user interaction is required. Endpoint:POST https://api.smartbills.io/auth/connect/token
Request:
Code Examples
Authorization Code Flow
Use this flow for user-facing applications where you need to act on behalf of a user. Step 1: Redirect to Authorization EndpointCode Examples
Token Expiration and Refresh
Access tokens expire after a set period (typically 3600 seconds / 1 hour). Use theexpires_in field to know when a token will expire.
Refreshing Tokens
When your access token expires, use the refresh token to obtain a new one without requiring user interaction:Using the SDKs
The official SDKs handle authentication, token refresh, and header management automatically:Authentication Errors
Example Error Response
Security Best Practices
Protect Your Credentials
Protect Your Credentials
- Store API keys and secrets in environment variables
- Never commit credentials to version control
- Never expose tokens in client-side code
- Use HTTPS for all API requests
Use Appropriate Scopes
Use Appropriate Scopes
- Request only the scopes your application needs
- Use read-only scopes when you do not need write access
- Review and audit scopes regularly
Handle Token Expiration
Handle Token Expiration
- Check the
expires_invalue after obtaining tokens - Implement automatic token refresh before expiration
- Handle 401 errors by refreshing and retrying
Rotate Keys Regularly
Rotate Keys Regularly
- Rotate API keys every 90 days
- Revoke compromised keys immediately
- Use separate keys for each environment
Related Resources
API Keys
Create and manage API keys
Environments
Sandbox and production environments
Error Handling
Handle authentication errors
Rate Limits
Understand rate limiting