Token is invalid or has expired while generatesession function

epraveen92
epraveen92 edited February 2022 in PHP client
Hi,
I am calling this function after getting my request token,
$user = $kite->generateSession("request_token_obtained", "XXXXXXXXXXX");
It is always giving this error "Token is invalid or has expired".

For creating API, I have connected zerodha funds for paying API charges, money was deducted multiple times. I have raised the complaint to get the non used funds, after getting the funds only it is not working. It is working before that perfectly.
I have not changed anything in the code.

Kindly solve this issue.
  • SRIJAN
    Hide any app credentials when posting on this forum. A request token is vaild only for a few minutes,after that it expires.
  • epraveen92
    epraveen92 edited February 2022
    Ok sure, I will hide.
    After redirecting to my page, I am getting the request token, immediately I am calling generateSession function, that time itself it says Token is invalid or expired. It is not being for even 30 seconds .
  • SRIJAN
    Is your app active on developer console??
  • epraveen92
    It is active. It shows error code 403
  • SRIJAN
    Are you actually passing the request token obtained from the url in the generate_session function?? Or are you literally passing the string "request_token_obtained" instead of the value of request token ??
  • epraveen92
    I'm 100% sure, I am passing the exact request token. I have tried with variable and directly passing the token & api_secret.. Both are failed.
  • rakeshr
    $user = $kite->generateSession("request_token_obtained", "XXXXXXXXXXX");
    It is always giving this error "Token is invalid or has expired".
    You won't get 403 unless you are sending the wrong access_token, api_secret, or request_token(obtained after the login flow). You need to recheck on all these three params at your end. Also, make sure all the tokens are passed as string.
  • SRIJAN
    Then only Sujith Sir or Rakesh Sir can help you.
  • epraveen92
    Right now I am using old KiteConnect. Should I use composer kiteconnect ?
    Whether this makes the conflict.
    I have checked all the params are correct in my end.
  • SRIJAN
    Yes,and make sure the version is >8.0.0
  • epraveen92
    1.include_once( "kiteconnect.php");
    2.$req = isset($_GET['request_token']) ? $_GET['request_token'] : '';
    3.$kite = new KiteConnect("apicode");
    I have created a sample code for testing, even this it cause error code 500 if i execute 3rd line.
    I am using old kiteconnect.
  • SRIJAN
    Using old versions and asking for help is not right. When you use latest versions and then you have a issue related to KiteConnect,you may post on this forum.
  • sujith
    Why don't you run it in debug mode and paste the complete stacktrace as a private message?
  • rakeshr
    I am using old kiteconnect.
    Old kiteconnect PHP client will work fine for basic API requests, but recent API additions like(basket margin, etc) won't be available in the same. So, it's recommended to use the latest composer package.
    I have created a sample code for testing, even this it cause error code 500 if i execute 3rd line.
    $kite = new KiteConnect("apicode");
    You are using the wrong API key. Recheck on that.
  • sujith
    You may also refer to this thread once.
  • epraveen92
    It was working fine until API funds credited back to me due to multiple times deducted.
    Can I delete my existing API key and create new one. I have 20 days more with this API.
    Shall I delete and create new one ?
  • epraveen92
    With the example given in the above thread, I have tried when I connect with the API Key, it gives error 500.
    That's why I am asking to delete this API and creating new one ?
  • epraveen92
    I am getting this message when I run in debug mode
    {"status":"error","message":"The user is not enabled for the app.","data":null,"error_type":"InputException"}
  • epraveen92
    Thanks. My problem is resolved now.
This discussion has been closed.