Skip to main content

Overview

The Smartbills API uses JWT Bearer token authentication. Every API request must include a valid token in the Authorization 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 the Authorization header of every request:
The header format is:
Where {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 the x-tenant-id header to specify the business context:
This header tells the API which business’s data you want to access. Your token must have permission to access the specified business.

Locale Header

Use the Accept-Language header to receive localized responses:
Supported locales: 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:
Response:

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 Endpoint
Step 2: Exchange Authorization Code for Access Token
Response:

Code Examples

Token Expiration and Refresh

Access tokens expire after a set period (typically 3600 seconds / 1 hour). Use the expires_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:
Refresh Token Response:
Refresh token rotation: Each time you use a refresh token, a new refresh token is returned. The old refresh token is invalidated. Always store the latest refresh token.

Using the SDKs

The official SDKs handle authentication, token refresh, and header management automatically:

Authentication Errors

Example Error Response

Security Best Practices

  • 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
  • Request only the scopes your application needs
  • Use read-only scopes when you do not need write access
  • Review and audit scopes regularly
  • Check the expires_in value after obtaining tokens
  • Implement automatic token refresh before expiration
  • Handle 401 errors by refreshing and retrying
  • Rotate API keys every 90 days
  • Revoke compromised keys immediately
  • Use separate keys for each environment

API Keys

Create and manage API keys

Environments

Sandbox and production environments

Error Handling

Handle authentication errors

Rate Limits

Understand rate limiting