Error in Executing regular orders api using curl

prashantgangurde
I have subscribed for Kite API services and trying to put the trade using API with below command:


curl https://api.kite.trade/orders/regular \
-H "X-Kite-Version: 3" \
-H "Authorization:token wewewew:xcxc332sdsdsds" \
-d "tradingsymbol=BORORENEW" \
-d "exchange=NSE" \
-d "transaction_type=BUY" \
-d "order_type=LIMIT" \
-d "quantity=1" \
-d "product=CNC" \
-d "price=455" \
-d "validity=DAY"


{"status":"error","message":"Invalid `api_key` or `access_token`.","data":null,"error_type":"InputException"}%
Could you please send me proper way of adding headers to above command?
  • prashantgangurde
    @sujith
    @SRIJAN

    Can you please have a look into this?
  • rakeshr
    Make sure, you are requesting the header content-type as application/x-www-form-urlencoded.
  • prashantgangurde
    @rakeshr This I have followed as per Document given by Zerodha:
    https://kite.trade/docs/connect/v3/orders/

    Even I have tried below command on Terminal:

    curl --request POST https://api.kite.trade/orders/regular \
    -H "X-Kite-Version: 3" \
    -H "content-type: application/x-www-form-urlencoded" \
    -H "Authorization: token sdsds:sdfsdf4fddffd454dfdfd" \
    -d "tradingsymbol=BORORENEW" \
    -d "exchange=NSE" \
    -d "transaction_type=BUY" \
    -d "order_type=LIMIT" \
    -d "quantity=1" \
    -d "product=CNC" \
    -d "price=455" \
    -d "validity=DAY"

    I am getting the same error message:
    {"status":"error","message":"Incorrect `api_key` or `access_token`.","data":null,"error_type":"TokenException"}%
  • prashantgangurde
    Can we discuss over email? if you have some time for discussions?
  • rakeshr
    Are you sure about sending the correct access_token?
    You need to follow the login flow as mentioned in the documentation.
  • prashantgangurde
    How I can generate the access token? the webinar has not explained in proper manner. I have successfully generated the request token.
    Could you please help me in generating the access Token?

    I tried with below scenario:
    curl https://api.kite.trade/session/token \
    -H "X-Kite-Version: 3" \
    -d "api_key=xxx" \
    -d "request_token=yyy" \
    -d "checksum=zzz"

    Where Checksum - (SHA-256 of api_key + request_token + api_secret)
    and request token generated from:
    https://kite.zerodha.com/connect/login?v=3&api_key=dsddsd

    Now when I am executing above command:
    curl https://api.kite.trade/session/token \
    -H "X-Kite-Version: 3" \
    -d "api_key=xxx" \
    -d "request_token=yyy" \
    -d "checksum=zzz"

    I am getting below error:
    {"status":"error","message":"Token is invalid or has expired.","data":null,"error_type":"TokenException"}%

    How I can proceed with the same?
  • prashantgangurde
    @rakeshr

    Please send me your email.
  • rakeshr
    How I can generate the access token?
    The whole login flow is explained in detail in the documentation.
    Could you please help me in generating the access Token?
    Please send me your email.
    We don't assist in providing coding support. You have to take other members' help and refer to our documentation and FAQs section for basic queries.
  • prashantgangurde
    Thanks a lot @rakeshr

    I have below questions now:
    I got the Access Token from below code:
    User user = kiteConnect.generateSession("asasa", "asasa");
    kiteConnect.setAccessToken(user.accessToken);
    kiteConnect.setPublicToken(user.publicToken);

    As per comments is stating that This access Token is valid valid for whole day right?
    But I have below observations:
    1.
    KiteConnect kiteConnect = new KiteConnect("ssasasa");
    kiteConnect.setUserId("XX3700");
    String url = kiteConnect.getLoginURL();

    kiteConnect.setSessionExpiryHook((SessionExpiryHook) new SessionExpiryHook() {
    @Override
    public void sessionExpired() {
    System.out.println("session expired");
    }
    });
    // Request Token, API Secret
    User user = kiteConnect.generateSession("sasa", "sasa");
    kiteConnect.setAccessToken(user.accessToken);
    kiteConnect.setPublicToken(user.publicToken);

    If we execute this code snippet the Java Process continues runs and never stopped.

    2. Can we use this access token for full day trade activities in other session?
    3. If we stopped the process at point 1, the Access token still valid?
    4. If we logged out and from point 1, can we still use the stored access token for other API call?
  • sujith
    You may refer to this thread.
This discussion has been closed.