Kite Connect Api using C#

tejashree
Hello,

I'm trying to use Kite connect using C#. I am able to get request_token but unable to go further.
I'm facing an issue when I try to get access_token from the authentication process. It's showing me 403 forbidden error.
please help me to resolve this, thanks in advance.
  • Kailash
    @tejashree Please provide some context/code samples. Are you computing the SHA-256 checksum correctly?
  • tejashree
    @Kailash I'm using following method:
    plz suggest me whether it is correct or not?

    //checksum calculation
    SHA256Managed crypt = new SHA256Managed();
    StringBuilder hash = new StringBuilder();

    //here token is request_token which I'm getting after login process,
    byte[] temp = Encoding.UTF8.GetBytes(ApiKey + token + ApiSecretKey);

    byte[] crypto = crypt.ComputeHash(temp);
    string checksum = string.Empty;
    foreach (byte x in crypto)
    {
    checksum += String.Format("{0:x2}", x);
    }
  • Kailash
    Given these input values, can you check if you're getting the given checksum?

    ApiKey = xxxx
    token = yyyy
    ApiSecretKey = zzzz

    checksum = 20ffb2c3e9532153b96b956845381adc06095f8342fa2db1aafba6b0e9594d68
    I am not familiar C#, but I did some quick research and it could be a UTF8 encoding issue. Can you try this http://stackoverflow.com/a/17001289 ?
  • tejashree
    tejashree edited February 2016
    Hello Kailash,

    I tried with your given inputs, I'm getting correct checksum as you mentioned above. But still its giving 403 Forbidden. I'm not able to connect with Kite. Plz elaborate.

    Waiting for your reply.
  • Kailash
    @tejashree what's your API key?
  • tejashree
    @Kailash please share mail id so I can share you API key.
  • Kailash
    @tejashree Have you figured this out yet? @vivek says he spoke to you over e-mail.
  • Amol
    @tejashree can u share c# code of login preocess it will very help full.
  • pankajiit_cse
    I am also facing the same issue...any fix on the same
  • rajeshreddyrr@gmail.com
    Hi All, I faced the same issue with Java.
    My solution for this issue is adding all request parameters to URL string directly.
    I am not sure why i get 403 if i set request properties through API call..Below is my URL.

    String sha256hex = sha256String(api_key+request_token+secret_key);
    URL url = new URL("https://api.kite.trade/session/token?api_key=zrvn5zt7yybwbg0z&request_token="+request_token+"&checksum="+sha256hex);
    HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
    conn.setRequestMethod("POST");
    conn.connect();
  • k365
    can anybody please share the c# code for connecting to kite..
    i am unable to get access code..
    it shows
    {"status": "error", "message": "Route not found", "error_type": "GeneralException"}

    any code for proper connection and to get live price will be really helpful
    i hope someone had figured out the problem ?
  • Vivek
    @k365 You need to set request as POST not GET.

    conn.setRequestMethod("POST");
  • chaudhariapurva
    chaudhariapurva edited September 2016
    Hi,
    USE REST SHARP FOR MAKING THE GET POST PUT DEL REQ
  • chaudhariapurva
    chaudhariapurva edited September 2016
    I use this function to get the check sum
    whis is same as tejashree

    private static string Sha256(string password)
    {
    var crypt = new SHA256Managed();
    var hash = new StringBuilder();
    if (password != null)
    {
    byte[] crypto = crypt.ComputeHash(Encoding.UTF8.GetBytes(password), 0,
    Encoding.UTF8.GetByteCount(password));
    foreach (byte theByte in crypto)
    {
    hash.Append(theByte.ToString("x2"));
    }
    }
    return hash.ToString();
    }


  • Kailash
    @chaudhariapurva What is the value of the password argument. It has to be api_key + request_token + secret
  • chaudhariapurva
    Yes it is concatenated string of elements mentioned by you
  • Kailash
    Hm, what is the error response (JSON body) that you're getting?
Sign In or Register to comment.