{"status":"error","message":"Incorrect `api_key` or `access_token`.","data":null,"error_type":"Token

iamsiddhant edited September 2021 in API clients
Following the below steps:
created a new app at https://developers.kite.trade/apps
obtained the `API key` from the app details page
obtained the `API secret` from the app details page

called the instrument API -> working fine
called the quote or quote ohlc API -> giving API key error
called the historic API -> giving API key error

have regenerated the API secret as well. Am I missing anything?
  • sujith
    You need to pass a valid header. It seems like you are passing wrong api_key or access token.
  • sujith
    Did you create access token using generateSession API?
  • iamsiddhant
    no I just took the api key and api secret from https://developers.kite.trade/apps/ and passing header as

    " -H 'Authorization: token api_key:api_secret

    I cannot find anywhere in the documentation to generate API token separately?
  • sujith
    You can refer to the login flow here.
  • iamsiddhant
    ok, do I need to go through the login flow even when I just want to use the quote and historic API for my script? I don't have any requirements related to order or any other API?
  • sujith
    Every request sent is authenticated against the api_key and access token.
  • iamsiddhant
    ok, thank you so much. One last question, once I get the access token, will it expire or I can use the same one daily. The reason why I am asking this because I just want to run the API script daily and if it will expire automatically, I will have to keep on updating the request token manually. Pls suggest
  • iamsiddhant
    iamsiddhant edited September 2021
    I am generating sha 256 in ruby and sending post using curl as per the doc and getting the following error:

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

    I am using following command to generate sha256:
    Digest::SHA256.hexdigest(@api_key + @request_token + @api_secret)
  • iamsiddhant
    tried it with your official python lib as well, the error is same i.e kiteconnect.exceptions.TokenException: Token is invalid or has expired.

    this is the debug log:
    DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.kite.trade:443
    DEBUG:urllib3.connectionpool:https://api.kite.trade:443 "POST /session/token HTTP/1.1" 403 None
    Traceback (most recent call last):
    File "", line 1, in
    File "/usr/local/lib/python3.9/site-packages/kiteconnect/connect.py", line 257, in generate_session
    resp = self._post("api.token", params={
    File "/usr/local/lib/python3.9/site-packages/kiteconnect/connect.py", line 840, in _post
    return self._request(route, "POST", url_args=url_args, params=params, is_json=is_json, query_params=query_params)
    File "/usr/local/lib/python3.9/site-packages/kiteconnect/connect.py", line 912, in _request
    raise exp(data["message"], code=r.status_code)
  • sujith
    You can know more here.
Sign In or Register to comment.