Skip to content
English
  • There are no suggestions because the search field is empty.

API authentication

 
 
Reloadly · API & Authentication

How to Automatically Renew Your Reloadly API Access Token

Keep your integration running without interruptions by renewing your access token automatically, before it expires.

● Intermediate ⏱ 5 min read For developers
60
minutes

Reloadly API access tokens are valid for 60 minutes. To maintain uninterrupted access to Reloadly APIs, your integration should automatically request a new access token before the current token expires.

⚠ Important: You should not rely on manually generating or replacing access tokens.

Why should access token renewal be automated?

Once an access token expires, API requests using that token will no longer be authenticated. This may result in authentication errors such as:

HTTP 401 Unauthorized

If your application continues sending requests with an expired token, transactions or other API operations may fail until a new token is obtained.

Automating token renewal helps prevent unnecessary service interruptions.

Recommended implementation

Your application should manage the access token lifecycle automatically. We recommend the following process:

1

Request an access token

Authenticate using your Reloadly client_id and client_secret and obtain an access token through the Reloadly OAuth authentication endpoint.

EXAMPLE REQUEST
POST https://auth.reloadly.com/oauth/token
Content-Type: application/json

{
  "client_id": "YOUR_CLIENT_ID",
  "client_secret": "YOUR_CLIENT_SECRET",
  "grant_type": "client_credentials",
  "audience": "https://topups.reloadly.com"
}
2

Store the access token securely

Store the returned access token securely within your application. Do not expose your access token, client ID, or client secret in client-side applications, logs, public repositories, or other insecure locations.

3

Track the token expiry

Reloadly access tokens are valid for 60 minutes. Your application should track when the token was issued and when it will expire.

4

Renew the token before expiry

Request a new access token before the existing token reaches its 60-minute expiry. We recommend including a small safety buffer rather than waiting until the final second before expiration.

 
 
0 min · Token issued ~55 min · Renew 60 min · Expires

💡 Example: Your application could request a new token approximately 5 minutes before expiry.

5

Use the new token

Once the new access token has been successfully issued, use it for subsequent Reloadly API requests.

6

Handle authentication failures

Your integration should include appropriate error handling. If an API request returns an authentication error because the token is no longer valid, your application should obtain a new access token and retry the request where appropriate.

EXAMPLE · JAVASCRIPT (NODE.JS)
// Renew 5 minutes before the 60-minute expiry
const SAFETY_BUFFER_MS = 5 * 60 * 1000;
let cachedToken = null;
let expiresAt = 0;

async function getAccessToken() {
  if (cachedToken && Date.now() < expiresAt - SAFETY_BUFFER_MS) {
    return cachedToken; // reuse the valid token
  }
  const res = await requestNewToken(); // calls the OAuth endpoint
  cachedToken = res.access_token;
  expiresAt = Date.now() + res.expires_in * 1000;
  return cachedToken;
}

async function callReloadly(request) {
  let res = await send(request, await getAccessToken());
  if (res.status === 401) {
    cachedToken = null; // force renewal, then retry once
    res = await send(request, await getAccessToken());
  }
  return res;
}
 

Recommended token lifecycle

A typical implementation should follow this flow:

Authenticate → Receive Access Token → Store Token → Use Token → Renew Before Expiry → Replace Existing Token → Continue API Requests

This process should happen automatically, without requiring manual intervention.

Important: Access token renewal vs. credential rotation

Access token renewal should not be confused with rotating your Reloadly API credentials.

API credentials Access token
What it is client_id and client_secret A temporary token generated using those credentials
Purpose Authenticate your application Authorize your API requests
Validity Do not change every 60 minutes Expires after 60 minutes
What to do Store securely and keep using them Renew automatically before expiry

ℹ Good to know: You do not need to change your client ID or client secret every 60 minutes. Instead, your application should automatically request a new access token.

Best practices

For a reliable production integration:

✓ Do

  • Store client_id and client_secret securely
  • Cache and reuse a valid access token instead of requesting a new token for every API call
  • Track the token expiration time
  • Renew the token shortly before expiry
  • Add retry logic for authentication failures

✗ Don’t

  • Hard-code access tokens
  • Manually manage token renewal in production
  • Expose credentials

Need help with your integration?

Our support team is here to help. Contact us at tickets@reloadly.com