Not able to connect to the api

sanjays442 edited August 2022 in Node JS client
var KiteConnect = require("kiteconnect").KiteConnect;

var kc = new KiteConnect({
api_key: "your_api_key"

kc.generateSession("request_token", "api_secret")
.then(function(response) {
.catch(function(err) {

function init() {
// Fetch equity margins.
// You can have other api calls here.

.then(function(response) {
// You got user's margin details.
}).catch(function(err) {
// Something went wrong.

status: 'error',
message: 'Token is invalid or has expired.',
data: null,
error_type: 'TokenException'

I'm using this code to connect but it is showing Token expired. Please let me know what is wrong
    A request token is valid only for a couple of minutes, after that it expires.

    Make sure to use your request token immediately after logging in to your KiteConnect app.
    You need to have a KiteConnect app to use the KiteConnect APIs.
    When you create this,you will get both api_key and api_secret.

    After that,you have to login as told here:

    A KitePublisher app only allows you to place orders.
Sign In or Register to comment.