Facing an API Error Authentication failed1

DV3508
I am facing this error while connecting to API

Authentication failed1: Missing request_token
Fatal error: Uncaught InputException (400) 'Missing request_token' thrown in /home/mystock/public_html/kiteconnect.php on line 668

Can any one please help me to resolve it, Thanks in Advance.
  • k365
    i think these people are making money nothing else will happen properly...
    we should raise voice and get our refund... also should complaint against them
  • Vivek
    Vivek edited August 2016
    @k365 RTFM or use one of the official clients to use the APIs. Most of the issues posted here are because people doesn't have much expertise to integrate the APIs. We have many people who have integrated easily by just reading our docs properly.
  • Vivek
    Vivek edited August 2016
    @DV3508 are you using official php client? It seems like your are not calling with required parameters. In this case request_token is not passed.
  • DV3508
    Dear Vivek,

    i have followed all the standards given, even then it is not working. here is my code.

    <?php
    include dirname(__FILE__)."/kiteconnect.php";
    $api_key = "ial1sco22dpi9awi";
    $api_secret = "My_sec Key";

    // Incoming request token from the redirect.
    // $request_token = @$_GET["request_token"];
    // Initialise.
    $kite = new KiteConnect($api_key);

    // Assuming you have obtained the `request_token`
    // after the auth flow redirect by redirecting the
    // user to $kite->login_url()
    try {
    $request_token=@$_GET['request_token'] ;
    $user = $kite->requestAccessToken($request_token, $api_secret);

    echo "Authentication successful. \n";
    print_r($user);

    $kite->setAccessToken($user->access_token);
    } catch(Exception $e) {
    echo "Authentication failed: ".$e->getMessage();
    throw $e;
    }

    echo $user->user_id." has logged in";

    // Get the list of positions.
    echo "Positions: \n";
    print_r($kite->positions());

    // Place order.
    $order_id = $kite->orderPlace([
    "tradingsymbol" => "INFY",
    "exchange" => "NSE",
    "quantity" => 1,
    "transaction_type" => "BUY",
    "order_type" => "MARKET",
    "product" => "NRML"
    ], "regular");

    echo "Order id is ".$order_id;
    ?>

    Can any one help me please.
  • Kailash
    @DV3508 The request token comes to the redirect url after a successful login. I checked your app and your redirect url is just the url to your website, not the PHP script you have posted above. Obviously, without the request token coming as a query param, it won't work. Please read the manual and understand how the login and authentication flow works.
  • Kailash
    @k365 Your app's redirect URL is set to '127.0.0.1'. How do you expect to get the request token after the login without even setting a proper redirect url? Please do not make inflammatory comments and throw accusations at us if you do not have the technical knowledge to implement the APIs. There's a reason why you have to check and agree to the "I have read the API Documentation and have the technical know-how to use it" option while you sign up.
  • Kailash
    @DV3508 Try logging in here (this is my app) https://kite.trade/connect/login?api_key=tfvg166w243x6qp0

    The redirect end point is the exact script you've pasted above and it works fine. Once the login's done, it redirects to the script and you can see a successful response.
  • DV3508
    I really thank you so Much Kailash for your kind help. and from next time will read given the parameters carefully.
This discussion has been closed.