Overview
The Digitzs API uses a two-step authentication process to ensure secure access to your merchant services:- Authentication - Verifying your identity
- Authorization - Granting access to API resources
All API requests require proper authentication headers. Tokens expire after one hour and must be refreshed.
Before You Begin
You will need the following credentials provided during onboarding:API Key
Your unique API key (
x-api-key)Application ID
Your application identifier (
appId)Authentication Flow
1
Generate App Key
Create an app key using your API key and application ID
2
Create App Token
Use the app key to generate a temporary access token
3
Make Authenticated Requests
Include the token in your API requests
Step 1: Generate App Key
Create an app key that will be used to generate access tokens.Creating a new app key renders the old key unusable. Store your app key securely.
Endpoint
Request Headers
| Header | Value | Description |
|---|---|---|
x-api-key | Your API key | Provided during onboarding |
Content-Type | application/json | Standard REST header |
Request Body
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
data | object | Yes | Container for API data |
data.type | string | Yes | Must be “auth” |
data.attributes | object | Yes | Container for authentication attributes |
data.attributes.appId | string | Yes | Your application ID from onboarding |
Response
Response Parameters
| Parameter | Type | Description |
|---|---|---|
data.id | string | Your API key (same as request header) |
data.attributes.appKey | string | Generated app key for token creation |
Code Examples
Step 2: Create App Token
Generate a temporary access token using your app key. This token is required for all subsequent API calls.Tokens expire after one hour. You must generate a new token when the previous one expires.
Endpoint
Request Headers
| Header | Value | Description |
|---|---|---|
x-api-key | Your API key | Provided during onboarding |
Content-Type | application/json | Standard REST header |
Request Body
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
data | object | Yes | Container for API data |
data.type | string | Yes | Must be “auth” |
data.attributes | object | Yes | Container for authentication attributes |
data.attributes.appKey | string | Yes | The app key from Step 1 |
Response
Response Parameters
| Parameter | Type | Description |
|---|---|---|
data.id | string | Your API key |
data.attributes.appToken | string | The access token to use in Authorization header |
Code Examples
Step 3: Making Authenticated Requests
Once you have an app token, include it in all API requests using the required headers.Required Headers for API Calls
| Header | Value | Description |
|---|---|---|
Authorization | Bearer {appToken} | Your access token with “Bearer ” prefix |
x-api-key | Your API key | Your API key from onboarding |
appId | Your application ID | Your application ID from onboarding |
Content-Type | application/json | Standard REST header |
The
Authorization header value must be formatted as Bearer {token} with:- A capital “B” in “Bearer”
- A space between “Bearer” and your token
Example Authenticated Request
Token Management
Token Expiration
App tokens expire after one hour from creation. When a token expires, you will receive a401 Unauthorized error.
Refreshing Tokens
To refresh an expired token, simply call the/auth/token endpoint again with your app key. You do not need to regenerate the app key unless you want to invalidate all existing tokens.
Best Practices
Store Securely
Store your API key and app key securely using environment variables or secret management services
Implement Retry Logic
Automatically refresh tokens when you receive a 401 error
Cache Tokens
Cache tokens and reuse them until they expire to reduce API calls
Monitor Expiration
Track token creation time and proactively refresh before expiration
Complete Authentication Example
Here’s a complete example that handles the full authentication flow:Troubleshooting
401 Unauthorized Error
401 Unauthorized Error
403 Forbidden Error
403 Forbidden Error
This error indicates:
- Your account is not authorized to access the requested resource
- Your API key has been revoked or suspended
Invalid App Key
Invalid App Key
If you receive an error when creating a token:
- Your app key may have been regenerated
- The app key was not properly stored from Step 1
/auth/key and try again.Missing Headers
Missing Headers
All authenticated requests require three headers:
Authorization: Bearer {token}x-api-key: {your-api-key}appId: {your-app-id}
Security Best Practices
Never Expose Keys
Never commit API keys or tokens to version control or expose them in client-side code
Use Environment Variables
Store credentials in environment variables or secure secret management systems
Rotate Keys Regularly
Periodically regenerate your app keys to maintain security
Use HTTPS Only
Always make requests over HTTPS to encrypt data in transit

