Get New Access Token Using Existing Refresh Token
Endpoint Name: getaccesstokenfromrefreshtoken
Request type : POST
Authorization : Bearer Token as header
Note: Please call this endpoint at certain interval before the token expiration time, 10 mins will be an appropriate amount of time as per our implementation. An expired access token can give 401 unauthorized error.
Endpoint Details: The getaccesstokenfromrefreshtoken
endpoint will be used to get access token from refresh token.
Method
URL
POST
URL/access/klearstack/getaccesstokenfromrefreshtoken
Parameters
Description
Required or Optional
refresh_token
Refresh token must be passed in request body to get new access token
Required
company_name
Name of the company for which the user is logging in
Required
Request Code samples
Shell
Request Body
curl -X POST URL/access/klearstack/getaccesstokenfromrefreshtoken \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Authorization: Bearer YOUR_EXISTING_ACCESS_TOKEN" \
-d "refresh_token=Replace_Refresh_Token_Here&company_name=Replace_Company_Name_Here"
Python
Request Body
import requests
url = "URL/access/klearstack/getaccesstokenfromrefreshtoken"
headers = {
"Authorization": "Bearer YOUR_EXISTING_ACCESS_TOKEN",
"Content-Type": "application/x-www-form-urlencoded"
}
data = {
'refresh_token': 'Replace_Refresh_Token_Here',
'company_name': 'Replace_Company_Name_Here'
}
response = requests.post(url, headers=headers, data=data)
print(response.json())
Java
Request Body
import okhttp3.*;
import java.io.IOException;
public class ApiRequestExample {
public static void main(String[] args) {
OkHttpClient client = new OkHttpClient();
// Form data (refresh_token, company_name)
RequestBody formBody = new FormBody.Builder()
.add("refresh_token", "Replace_Refresh_Token_Here")
.add("company_name", "Replace_Company_Name_Here")
.build();
Request request = new Request.Builder()
.url("URL/access/klearstack/getaccesstokenfromrefreshtoken")
.post(formBody)
.addHeader("Authorization", "Bearer YOUR_EXISTING_ACCESS_TOKEN")
.addHeader("Content-Type", "application/x-www-form-urlencoded")
.build();
// Execute the request and handle the response
try (Response response = client.newCall(request).execute()) {
if (response.isSuccessful()) {
System.out.println("Response: " + response.body().string());
} else {
System.out.println("Error: " + response.body().string());
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Node.js
Request Body
var request = require('request');
const form_data = {
'refresh_token': 'Replace_Refresh_Token_Here',
'company_name': 'Replace_Company_Name_Here'
};
const options = {
url: 'URL/access/klearstack/getaccesstokenfromrefreshtoken',
form: form_data,
headers: {
'Authorization': 'Bearer YOUR_EXISTING_ACCESS_TOKEN',
'Content-Type': 'application/x-www-form-urlencoded'
}
};
request.post(options, function(err, httpResponse, body) {
if (err) {
console.error('Request failed:', err);
return;
}
console.log('Response:', body);
});
JavaScript (XMLHttpRequest)
Request Body
var data = new FormData();
data.append('refresh_token', 'Replace_Refresh_Token_Here');
data.append('company_name', 'Replace_Company_Name_Here');
var xhr = new XMLHttpRequest();
xhr.addEventListener("readystatechange", function () {
if (this.readyState === this.DONE) {
console.log(this.responseText);
}
});
xhr.open("POST", "URL/access/klearstack/getaccesstokenfromrefreshtoken");
xhr.setRequestHeader("Authorization", "Bearer YOUR_EXISTING_ACCESS_TOKEN");
xhr.send(data);
API Response
Status code
Example Response
200
{
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjU2NTc2MDM4LCJpYTY1NzU5MTgsImp0aSI6IjQwMWZlYmJhODg4NDQ1MmRhN2Q3ZTA5ZjEwZmYwOWFkIiwidXNlcl9pZCI6MjZ9.sjU6iVbRRp7dTDt-l4rj7K7tKpPpaL7yskjstAUn2Zs",
"release_version": “7.8.9”
}
500
One or Many Required parameters from company name must be missing, E.g error “refresh_token”,
Last updated