API Keys | Moloni ON API
Moloni ONGuidesAPI ReferenceExplorer
Guides

API Keys

API Keys provide direct authentication for machine-to-machine integrations. Unlike API Clients which require an OAuth flow with user interaction, API Keys can be used immediately, with no redirects, no authorization codes and no token exchanges.

When to use API Keys

API Keys are ideal for:

  • Server-side scripts: automated syncing, data imports/exports
  • Cron jobs: scheduled reports, periodic data pulls
  • Backend integrations: connecting Moloni ON with other systems
  • Development and testing: quick API access during development

If your use case involves a user logging in through a browser, use an API Client with OAuth 2.0 instead.

Creating an API Key

  1. Log in to Moloni ON
  2. Go to Account → API
  3. Open the API Keys tab
  4. Click Create
  5. Enter a name (e.g. "Warehouse Sync", "Report Generator")
  6. Optionally set an expiration date (defaults to 1 year; leave blank for no expiry)
  7. Save. You'll be shown the API Key token

Using the API Key

Pass the token directly in the Authorization header, with no OAuth flow needed:

curl -X POST https://api.molonion.pt/v1 \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer apik:550e8400-e29b-41d4-a716-446655440000:3f8c9a2b1d4e7a5f" \
  -d '{
    "query": "query { customers(companyId: 1) { data { customerId name } } }"
  }'

That's it: no token exchange, no refresh flow. The API Key works directly as a Bearer token.

Permissions

An API Key inherits the permissions of the user who created it. If the user has read-only access to a company, the API Key will too.

Expiration

SettingBehavior
With expiration dateKey stops working after that date
Without expiration dateKey works indefinitely until deleted

The default suggestion when creating a key is 1 year from today.

Regenerating a token

If a token is compromised, you can regenerate it from the Account → API → API Keys tab:

  1. Find the key in the list
  2. Click Regenerate
  3. The old token is immediately invalidated
  4. A new token is shown; store it before closing

The key ID and name stay the same; only the secret portion changes.

Revoking a key

To revoke an API Key, delete it from the Account → API → API Keys tab. This is immediate; any requests using that token will fail with a 401 Unauthorized error.

API Key vs API Client

API KeyAPI Client (OAuth 2.0)
SetupCreate key → use tokenCreate client → OAuth flow → manage tokens
User interactionNoneRequired (user authorizes via browser)
Token managementSingle permanent tokenAccess token (1h) + refresh token (14d)
ExpirationOptional (configurable)Access token expires hourly, refresh every 14 days
Best forScripts, cron jobs, integrationsWeb apps acting on behalf of users

Next steps