Authentication
Learn how to authenticate with the CargoLint API using an organization API key or a user's sign-in token.
Authentication Methods
CargoLint supports two authentication methods: an API key for server-to-server integration, and a JWT bearer token for a signed-in user. Choose the method that fits your use case.
API Keys (Recommended for Server-to-Server)
API keys are available on the Business and Enterprise plans. The plan is checked on every request: when the organization moves to a plan without API access, or a Business trial ends, the key is answered 403 with the code PLAN_FEATURE_UNAVAILABLE until the organization is back on Business or Enterprise.
Generate an API Key
- Log in to your CargoLint dashboard as an Owner or Admin
- Go to Settings > Integrations > API Keys
- Click Generate Key
- Copy the key and store it securely. It is shown once and cannot be retrieved again
An organization has one API key. Generating a new one replaces the old key, which stops working at once; Revoke removes it.
Using API Keys in Requests
Include your API key in the X-API-Key header:
curl -X GET https://api.cargolint.com/api/v1/documents \
-H "X-API-Key: cl_YOUR_API_KEY"
import os
import requests
headers = {
"X-API-Key": os.environ["CARGOLINT_API_KEY"]
}
response = requests.get(
"https://api.cargolint.com/api/v1/documents",
headers=headers
)
Requests made with an API key are rate limited per minute: 60 on Business, 300 on Enterprise. Each response carries X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset; a request over the limit gets 429 with a Retry-After header.
An API key acts for the organization, not for a person. Endpoints that need a user’s role, such as team management, webhook management and billing changes, need a signed-in Owner’s or Admin’s token instead.
Best Practices for API Keys
- Store the key in an environment variable, such as
CARGOLINT_API_KEY - Never commit API keys to version control
- Replace the key when someone who had it leaves, or if it may have been exposed
- Revoke the key immediately if it is compromised
JWT Bearer Tokens (For User Sessions)
Obtaining a JWT Token
Use your credentials to request a token from the login endpoint:
curl -X POST https://api.cargolint.com/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "your-secure-password"
}'
Response (abridged):
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"email": "user@example.com",
"role": "Admin",
"organizationId": "a1b2c3d4-0000-4000-8000-000000000001",
"twoFactorRequired": false
}
If the account has two-factor authentication on, token is empty, twoFactorRequired is true, and the response carries a short-lived tempToken. Complete the sign-in with POST /api/v1/auth/2fa-challenge, sending Authorization: Bearer <tempToken> and a body of { "totpCode": "123456" } (or { "recoveryCode": "..." }). The temporary token lasts 5 minutes.
Using JWT Tokens in Requests
Include the token in the Authorization header with the Bearer scheme:
curl -X GET https://api.cargolint.com/api/v1/documents \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
Token Lifetime
Tokens expire after 60 minutes. There is no refresh token: when a token expires, sign in again.
When to Use Each Method
| Method | Use Case | Expiration | Rotation |
|---|---|---|---|
| API Key | Server-to-server, integrations | Never (until replaced, revoked, or the plan no longer includes the API) | Manual: an Owner or Admin generates a new key |
| JWT Token | A signed-in user, actions that need a user’s role | 60 minutes | Sign in again |
Security Considerations
- API keys: Best for long-lived, automated processes. Keep the one key in a secret store your services share.
- JWT tokens: Tied to a person and their role, and expire on their own.
- Always use HTTPS when transmitting authentication credentials
- Owners and Admins can review account activity in Settings > Audit Log
Need help? Contact our support team.