Skip to main content
GET
/
access
/
token
/
refresh
Refresh a user access token
curl --request GET \
  --url https://authservice-staging.withbenji.com/access/token/refresh \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: <api-key>' \
  --data '
{
  "refresh_token": "<string>",
  "access_token": "<string>"
}
'
import requests

url = "https://authservice-staging.withbenji.com/access/token/refresh"

payload = {
"refresh_token": "<string>",
"access_token": "<string>"
}
headers = {
"x-api-key": "<api-key>",
"Content-Type": "application/json"
}

response = requests.get(url, json=payload, headers=headers)

print(response.text)
const options = {
method: 'GET',
headers: {'x-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({refresh_token: '<string>', access_token: '<string>'})
};

fetch('https://authservice-staging.withbenji.com/access/token/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://authservice-staging.withbenji.com/access/token/refresh",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_POSTFIELDS => json_encode([
'refresh_token' => '<string>',
'access_token' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-key: <api-key>"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"strings"
"net/http"
"io"
)

func main() {

url := "https://authservice-staging.withbenji.com/access/token/refresh"

payload := strings.NewReader("{\n \"refresh_token\": \"<string>\",\n \"access_token\": \"<string>\"\n}")

req, _ := http.NewRequest("GET", url, payload)

req.Header.Add("x-api-key", "<api-key>")
req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.get("https://authservice-staging.withbenji.com/access/token/refresh")
.header("x-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"refresh_token\": \"<string>\",\n \"access_token\": \"<string>\"\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://authservice-staging.withbenji.com/access/token/refresh")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)
request["x-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"refresh_token\": \"<string>\",\n \"access_token\": \"<string>\"\n}"

response = http.request(request)
puts response.read_body
{
    "code": "ok",
    "data": {
        "user_id": 1,
        "merchant_id": 1,
        "token_data": {
            "access_token": "0c371a1c-aa81-11ef-b28c-0a58a9feac02",
            "refresh_token": "05tghegts-aa81-sgte-hgte-u8nhgbvgtio",
            "access_token_expires_at": "Tue, 22 Oct 2024 21:57:02 GMT"
        }
    }
}
{
  "error": "invalid_token",
  "message": "Invalid refresh or access token"
}
{
  "error": "unauthorized_request",
  "message": "Token is not authorized to make this request"
}
The x-api-key header value to be used on this API is your partner API key, which can be generated through the dashboard.
refresh_token
string
required
The refresh token received from the exchange token API flow or previously received from refreshing an access token from this API
access_token
string
required
The current access token you are refreshing

Return values

user_id
integer
required
The Benji Platform ID associated with the user.
merchant_id
integer
required
Your system ID as specified on the Benji Platform.
token_data
object
required
An object representing the access_token, refresh_token to use when using the Benji Platform APIs as well as the access token expiry date. Once an access token expires, you can use the refresh token to obtain a new access token silently without requiring the user to authenticate again.
{
    "code": "ok",
    "data": {
        "user_id": 1,
        "merchant_id": 1,
        "token_data": {
            "access_token": "0c371a1c-aa81-11ef-b28c-0a58a9feac02",
            "refresh_token": "05tghegts-aa81-sgte-hgte-u8nhgbvgtio",
            "access_token_expires_at": "Tue, 22 Oct 2024 21:57:02 GMT"
        }
    }
}
{
  "error": "invalid_token",
  "message": "Invalid refresh or access token"
}
{
  "error": "unauthorized_request",
  "message": "Token is not authorized to make this request"
}
Access tokens are typically valid for 90 days. You can refresh an access token either before it expires proactively, or after calling an API and getting an expired_token 401 status code.