Invalid session credentials

avinashsringeri
Its failing in authentication. "Invalid session credentials" error message is thrown. My login id is [email protected]. I am giving the right api key and the token as given in the website. But it fails with invalid session credentials error. I can't share my credentials on this forum. Could you please look into this? I am running the sample program Test to test the connectivity.
  • sujith
    Hi @avinashsringeri,
    Please make sure you are not doing the following,
    1. Use the same client id with which you have created the app.
    2. Request token validity is for 5 min and it can only be used only once. So once you get access token store it and use the same, don't call requestAccessToken() every time you run app.
  • avinashsringeri
    This is the sample code I am executing. In the kite trade site I got API key and the secret. I am using those values in this code to connect.



    // First you should get request_token, public_token using kitconnect login and then use request_token, public_token, api_secret to make any kiteconnect api call.
    // Initialize KiteSdk with your apiKey.
    KiteConnect kiteconnect = new KiteConnect("api_key");

    // set userId
    // kiteconnect.setUserId("[email protected]");

    kiteconnect.setUserId("[email protected]");


    //set proxy is optional, if you want to set proxy.
    // kiteconnect.setProxy(new HttpHost("host_name"))

    // Get login url
    String url = kiteconnect.getLoginUrl();

    // Set session expiry callback.
    kiteconnect.registerHook(new SessionExpiryHook() {
    @Override
    public void sessionExpired() {
    System.out.println("session expired");
    }
    });

    // Set request token and public token which are obtained from login process.
    UserModel userModel = kiteconnect.requestAccessToken("api_key", "secret");
    System.out.println(userModel.accessToken);
    System.out.println(userModel.publicToken);
    kiteconnect.setAccessToken(userModel.accessToken);
    kiteconnect.setPublicToken(userModel.publicToken);

    Examples examples = new Examples();
    examples.getMargins(kiteconnect);

    examples.placeOrder(kiteconnect);

    examples.placeBracketOrder(kiteconnect);

    examples.getTriggerRange(kiteconnect);

    examples.placeCoverOrder(kiteconnect);

    examples.getOrders(kiteconnect);

    examples.getTrades(kiteconnect);

    examples.getTradesWithOrderId(kiteconnect);

    examples.modifyOrder(kiteconnect);

    examples.cancelOrder(kiteconnect);

    examples.getPositions(kiteconnect);

    examples.getHoldings(kiteconnect);

    examples.modifyProduct(kiteconnect);

    examples.getAllInstruments(kiteconnect);

    examples.getInstrumentsForExchange(kiteconnect);

    examples.getQuote(kiteconnect);

    examples.getHistoricalData(kiteconnect);

    examples.logout(kiteconnect);

    examples.tickerUsage(kiteconnect);

  • sujith
    Hi @avinashsringeri,
    kiteconnect.setUserId must be your zerodha client id.
    Client id with which you want to trade.
  • avinashsringeri
    I tried with my Zerodha id.Results is same. I seriously need someone to close this thread. I been requesting this for a long time.
  • avinashsringeri
    I didnt get any response from you folks. So I deleted app to recreate and try again. Now its asking me to credit 2000. What should I do now?
  • avinashsringeri
    avinashsringeri edited March 2017
    Its working. The sample code with class name "Test" given as part of Kite Connect is very misleading. The other users could also experience the same problem as I did.
    This sample code should have an request_token as an mandatory input parameter or at runtime this code should get request token and move on with other operations.

    Hanan thanks for your call. Thanks for all the help I received from the support group.
Sign In or Register to comment.