getting error as Unhandled rejection StatusCodeError: 403 - "Token is invalid or expired"

rbt
Dear team,
i am getting error of 403 as token is invalid or expired ,while getting data for ticker data with node js
I have both the subscription of historical and api subscription.while accessing to historical data i am getting it easily while accessing to ticker data i am getting error of 403.

Attaching you the code:--
var instrument_token = 3463169;

var KiteTicker = require("./views/scripts/kiteconnect").KiteTicker;
var ticker = null;

app.get('/callAPI', function (req, res) {

var request_token = req.query.request_token;
//var instrument_token = 3463169;

//if (redirectpage == 'http://localhost:8383/chart') {
kc.requestAccessToken(request_token, "*************")
.then(function (res) {
var access_token = res.data.access_token
kc.setAccessToken(access_token);
console.log(access_token);
var date = dateFormat(Date.now(), "yyyy-mm-dd");
kc.historical(instrument_token, date, date, "minute").then(function (response) {
var filename = './views/data/LastTradePrice.json';
var data = response.data.candles;
console.log(data);
});


}


})
})



ticker = new KiteTicker("Api key", "Client_id", request_token);

ticker.connect();
ticker.on("tick", setTick);
ticker.on("connect", subscribe);

ticker.on("noreconnect", function () {
// console.log("noreconnect")
});

ticker.on("reconnecting", function (reconnect_interval, reconnections) {
//console.log("Reconnecting: attempet - ", reconnections, " innterval - ", reconnect_interval);
});
function subscribe() {
var items = [instrument_token];
ticker.subscribe(items);
ticker.setMode(ticker.modeFull, items);
}
});

Kindly help me as earliest,Thanks in advance
  • sujith
    You need to pass a valid access token It seems like you are passing an invalid access token.
  • rbt
    no i am not passing access token for kite ticker, you may see here

    ticker = new KiteTicker("Api key", "Client_id", request_token);

    10 to 15 days earlier i amn sending the request token only and i am getting the tick data

    but now i am not getting the data
    and also access token is not invalid
    as it is generated every time when i run the application over web
  • sujith
    In the new version of Kite Ticker, it is mandatory to send a valid access token for connecting to Kite Ticker.
    You are referring to the old version of Kite Ticker which was deprecated last month.
  • rbt
    Can you show me the whole new code for new version of kit ticker so that i can work forward .
  • sujith
    You can check out the example here.
  • rbt
    i have update the code but its not working i am not able to get the tick data but i am getting the historical data in node js do we need to update any package also,if yes
    then tell me all the step in detail how to do it and which are the package that we need to update .

    kindly mention all the detail how to get the tick data with node js.
  • tonystark
    tonystark edited June 2018
    @rbt You can find the latest nodejs package and ticker examples here.
  • rbt
    where ??

    I am not getting any link.
  • tonystark
    @rbt Forgot about it. Updated the reply. :smile:
  • rbt
    after updating node js package with npm install kiteconnect i have changed my code as var ticker = new KiteTicker("************", access_token); but even then i am not able to get the tick data as the token is showing is invalid or expired.

    I am really stuck in between

    please help @sujith @tonystark
  • sujith
    Did you try making any other API call?
    Check if you have a valid access token.
  • rbt
    Yes it is valid it give me the historical data of one minute during market hour.
  • sujith
    Are you calling generateSession after you receive historical data response?
  • rbt
    No i am not calling generate Session after receiving historical data.
  • sujith
    Can you paste the code here with Kite Connect 3 changes?
Sign In or Register to comment.