Skip to main content
POST
/
auth
/
refresh
Refresh Access Token
curl --request POST \
  --url https://api.fyatu.com/api/v3/auth/refresh \
  --header 'Authorization: Bearer <token>'
{
  "success": true,
  "status": 200,
  "message": "Token refreshed successfully",
  "data": {
    "accessToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJBMUIyQzNENEU1RjZHN0g4IiwiYnVzIjoiTjFTMFczUThQMFYxRTVNNlE0UjNEOFo5IiwidHlwZSI6ImNvbGxlY3Rpb24iLCJzY29wZXMiOlsiY29sbGVjdDp3cml0ZSIsImNvbGxlY3Q6cmVhZCIsInBheW91dDp3cml0ZSIsInBheW91dDpyZWFkIl0sImlhdCI6MTczNjE2MjIwMCwiZXhwIjoxNzM2MjQ4NjAwLCJqdGkiOiJqd3RfMmM0ZjVhOGIxZDNlNjc5MCJ9.pR8mK3nW5vL7qY1tS0xF4gH9jB6eA2cD4uW3iZ9vX1mO",
    "tokenType": "Bearer",
    "expiresIn": 86400,
    "expiresAt": "2026-01-07T10:30:00+00:00",
    "appType": "collection",
    "scopes": [
      "collect:write",
      "collect:read",
      "payout:write",
      "payout:read"
    ]
  },
  "meta": {
    "requestId": "req_2c4f5a8b1d3e6790",
    "timestamp": "2026-01-06T10:30:00+00:00"
  }
}

Overview

Refresh an existing JWT token to obtain a new one without re-authenticating with credentials. Tokens can be refreshed up to 5 minutes after expiry.

When to Refresh

  • Token is about to expire (less than 5 minutes remaining)
  • Token just expired (within 5-minute grace period)
  • You want to extend an active session
If your token expired more than 5 minutes ago, you must obtain a new token using the Generate Token endpoint.

Token Refresh Strategy

Implement automatic token refresh in your application:
class TokenManager {
  constructor(appId, secretKey) {
    this.appId = appId;
    this.secretKey = secretKey;
    this.token = null;
    this.expiresAt = null;
  }

  async getToken() {
    if (!this.token || this.isExpiringSoon()) {
      await this.refreshOrAuthenticate();
    }
    return this.token;
  }

  isExpiringSoon() {
    if (!this.expiresAt) return true;
    const fiveMinutes = 5 * 60 * 1000;
    return (new Date(this.expiresAt) - new Date()) < fiveMinutes;
  }

  async refreshOrAuthenticate() {
    if (this.token && this.canRefresh()) {
      try {
        const res = await fetch('https://api.fyatu.com/api/v3/auth/refresh', {
          method: 'POST',
          headers: { 'Authorization': `Bearer ${this.token}` }
        });
        const data = await res.json();
        if (data.success) {
          this.token = data.data.accessToken;
          this.expiresAt = data.data.expiresAt;
          return;
        }
      } catch (e) { /* Fall through to authenticate */ }
    }
    // Get fresh token
    const res = await fetch('https://api.fyatu.com/api/v3/auth/token', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({
        appId: this.appId,
        secretKey: this.secretKey,
        grantType: 'client_credentials'
      })
    });
    const data = await res.json();
    if (data.success) {
      this.token = data.data.accessToken;
      this.expiresAt = data.data.expiresAt;
    }
  }
}

Error Codes

CodeDescription
AUTH_TOKEN_MISSINGNo Authorization header provided
AUTH_TOKEN_INVALIDToken is malformed
AUTH_TOKEN_REFRESH_FAILEDToken too old (>5 min after expiry) or invalid
Refresh tokens proactively before they expire to ensure uninterrupted API access.

Authorizations

Authorization
string
header
required

JWT access token obtained from /auth/token

Response

Token refreshed successfully

success
boolean
Example:

true

status
integer
Example:

200

message
string
Example:

"Token generated successfully"

data
object
meta
object