Refresh Access Token
curl --request POST \
--url https://api.fyatu.com/api/v3/auth/refresh \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.fyatu.com/api/v3/auth/refresh"
headers = {"Authorization": "Bearer <token>"}
response = requests.post(url, headers=headers)
print(response.text)const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.fyatu.com/api/v3/auth/refresh', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.fyatu.com/api/v3/auth/refresh",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.fyatu.com/api/v3/auth/refresh"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.fyatu.com/api/v3/auth/refresh")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.fyatu.com/api/v3/auth/refresh")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"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"
}
}{
"success": false,
"status": 401,
"message": "Token refresh failed. Token may be too old or invalid.",
"error": {
"code": "AUTH_TOKEN_REFRESH_FAILED"
},
"meta": {
"requestId": "req_abc123def456",
"timestamp": "2026-01-05T10:30:00+00:00"
}
}Authentication
Refresh Token
Refresh an expiring Fyatu API access token without re-authenticating. POST /auth/refresh.
POST
/
auth
/
refresh
Refresh Access Token
curl --request POST \
--url https://api.fyatu.com/api/v3/auth/refresh \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.fyatu.com/api/v3/auth/refresh"
headers = {"Authorization": "Bearer <token>"}
response = requests.post(url, headers=headers)
print(response.text)const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.fyatu.com/api/v3/auth/refresh', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.fyatu.com/api/v3/auth/refresh",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.fyatu.com/api/v3/auth/refresh"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.fyatu.com/api/v3/auth/refresh")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.fyatu.com/api/v3/auth/refresh")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"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"
}
}{
"success": false,
"status": 401,
"message": "Token refresh failed. Token may be too old or invalid.",
"error": {
"code": "AUTH_TOKEN_REFRESH_FAILED"
},
"meta": {
"requestId": "req_abc123def456",
"timestamp": "2026-01-05T10: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
| Code | Description |
|---|---|
AUTH_TOKEN_MISSING | No Authorization header provided |
AUTH_TOKEN_INVALID | Token is malformed |
AUTH_TOKEN_REFRESH_FAILED | Token too old (>5 min after expiry) or invalid |
Refresh tokens proactively before they expire to ensure uninterrupted API access.
⌘I

