Access Token Issue

maxhiten
Today, I received 'Incorrect `api_key` or `access_token`' for 8 minutes that too when market start i.e. around 9 am. In back-end, only 1-2 scripts were running which is very common as I run those almost everyday to run my site https://flyingkites.in.

What is the actual reason for facing token issue suddenly today
  • nagavenij
    You may refer to this similar discussion.
  • maxhiten
    Your link is of no use to me. Here I am not asking you to tell me how and when to generate access tokens.

    This issue might have happened due to multiple active sessions with same api key. But I also need a confirmation from you. And if it is true, please tell me how many active sessions I can have at the same time with same api key.
  • nagavenij
    Only one active session can be created for a Kite Connect app/API key. However, once the session is created, the same valid access token can be used across multiple programs . You may refer to this similar discussion.

    Hence, you do not need to create separate sessions for each application. You can generate the session once and reusing the same access token across your applications.
  • maxhiten
    I generate my access token in the morning and save it in the db. Then, I am running multiple programs independent of each other and each programs needs to have a session with kite so that I can use Kite APIs. Following lines of code I am using for each program to connect with Kite:

    kite = new Kite(apikey, Debug: false);
    kite.SetSessionExpiryHook(OnTokenExpire); //To check if token has expired
    kite.SetAccessToken(token from db); //To use my already generated token for Kite APIs

    Let me know what I am doing wrong here.
  • salim_chisty
    Only a single active session is allowed per API key. However, you can use the same `access_token` across multiple independent programs or processes.

    Please ensure that the combined API requests from all programs remain within the applicable rate limits. For more details, refer to the .net API documentation and API rate limits documentation.
  • maxhiten
    Please confirm if the process I am following is correct or not. And if it is correct then I don't think I should ever get 'api_token' error in any way. And if wrong, please tell me what I am missing.
Sign In or Register to comment.