Authentication
WalletHero API supports two authentication methods: API tokens for server-to-server communication and session tokens for user-based access.
API Token Authentication (Recommended)
API tokens are long-lived tokens ideal for server-side integrations.
Obtaining an API Token
- Log in to your WalletHero account
- Navigate to Settings > API Token
- Click "Generate Token"
- Copy and securely store the token (it won't be shown again)
Or via API after logging in:
bash
curl -X POST https://api.wallethero.app/wallethero-api/user/api-token/regenerate \
-H "Authorization: Bearer your-session-token"Response:
json
{
"message": "API token regenerated successfully",
"token": "abc123def456..."
}Using the API Token
Include the token in the Authorization header:
bash
curl https://api.wallethero.app/wallethero-api/workspace/WORKSPACE_ID/pass-templates \
-H "Authorization: Bearer your-api-token"SDK Usage
typescript
import { WalletHero } from '@wallethero/sdk';
const client = new WalletHero({
apiToken: 'your-api-token'
});Session Token Authentication
Session tokens are obtained through the login flow and are used for user-based access.
Login Flow
bash
curl -X POST https://api.wallethero.app/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "[email protected]",
"password": "your-password"
}'Response:
json
{
"data": {
"access_token": "eyJhbGciOiJIUzI1NiIs...",
"refresh_token": "abc123...",
"expires": 900000
}
}Refreshing Tokens
bash
curl -X POST https://api.wallethero.app/auth/refresh \
-H "Content-Type: application/json" \
-d '{
"refresh_token": "abc123..."
}'Logout
bash
curl -X POST https://api.wallethero.app/auth/logout \
-H "Content-Type: application/json" \
-d '{
"refresh_token": "abc123..."
}'Note:
/auth/login,/auth/refresh, and/auth/logoutare native Directus endpoints and are not under the/wallethero-apiprefix.
Token Management
Check if API Token Exists
bash
curl https://api.wallethero.app/wallethero-api/user/api-token \
-H "Authorization: Bearer your-session-token"Response:
json
{
"has_token": true
}Revoke API Token
bash
curl -X DELETE https://api.wallethero.app/wallethero-api/user/api-token \
-H "Authorization: Bearer your-session-token"Response:
json
{
"message": "API token revoked successfully"
}Security Best Practices
- Never expose tokens in client-side code - API tokens should only be used server-side
- Rotate tokens periodically - Regenerate API tokens every 90 days
- Use environment variables - Store tokens in environment variables, not in code
- Monitor token usage - Check for unusual API activity regularly
- Revoke compromised tokens immediately - If a token is exposed, regenerate it right away
Error Codes
| Code | Status | Description |
|---|---|---|
INVALID_TOKEN | 401 | The provided token is invalid or expired |
TOKEN_EXPIRED | 401 | The session token has expired |
FORBIDDEN | 403 | Token doesn't have permission for this operation |
RATE_LIMITED | 429 | Too many requests, please slow down |