"token is invalid or has expired", while generating session token

rajatjain677
Hi Team,
I have gone through the faq, but did not find the solution, I have not got the session token even once.
kindly help TIA.

error object i am getting is below
{
status: 'error',
message: 'Token is invalid or has expired.',
data: null,
error_type: 'TokenException'
}

please find below the code, I am using

var KiteConnect = require("kiteconnect").KiteConnect;
var FormData = require('form-data');
const axios = require("axios");


var url = require("url");
var kc = new KiteConnect({
api_key: "XXXXXXXXX",
});
var URL_generate_request_token = "https://kite.zerodha.com/connect/login";

var api_secret = "XXXXXXXX";
var api_key = "XXXXXXXXXX" ;
const headers = {
"X-Kite-Version": 3,
"Content-Type": "application/x-www-form-urlencoded"
}


axios({
method: "GET",
url: URL_generate_request_token,
params: {
"api_key": api_key,
},
}).then((response) => {
console.log("response", response.request._redirectable._options.href);

var q = url.parse(response.request._redirectable._options.href, true);

var qdata = q.query;

var request_token = qdata.sess_id;
console.log(qdata.sess_id,request_token.length);



kc.generateSession(request_token, api_secret)
.then(function (response) {
console.log("inside generate session success function");
init();
})
.catch(function (err) {
console.log("inside error handler of session ");
console.log(err);
});






}).catch((error) => {
console.log("error", error);
});





Sign In or Register to comment.