How to login and Generate jwt Token


  • I try to login but I fail . Please help me how to login and get token in php.
    <?php
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://apiconnect.angelbroking.com/rest/auth/angelbroking/user/v1/loginByPassword');
    $auth_data = array(
    'clientcode' => 'RKJJ1005',
    'password' => 'MY_PASSWORD'

    );
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $auth_data);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('accept: application/json'));
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('UserType: USER'));
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('SourceID: WEB'));
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('PrivateKey: MY_MARKET_FEED_API_KEY'));
    curl_setopt($ch, CURLOPT_POST,1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($ch);
    if(!$result){die("Connection Failure");}
    curl_close($ch);
    echo $result;
    ?>


  • @aksharmty Hey sorry for late reply. Variable name was not correct in my code and you need to replace $responseContent with $result. But anyways you seems to already able to login 🙂


  • Hi @taranidhi

    The SmartAPI call may display incorrect username or password error for accounts registered with our sub-brokers. We are in the process of migrating all the accounts registered with our sub-brokers to a new system in a phased manner. The activity should be completed in the coming few days. Until then to expedite the migration of your account on an immediate basis, please share your client code on this thread or on api@angelbroking.com.

    Please note that post migration, you wont be able to access SpeedPro application.

    Thank you.


  • How can used to log in smart API IAM already signup and then used to sign in not show


  • Thanks for help I logged now . my write code are ```

    <?php
    //$headers = array('Content-Type: application/json', 'Accept: application/json', 'X-UserType: USER', 'X-SourceID: WEB', 'X-ClientLocalIP: Your_Local_IPAddress', 'X-ClientPublicIP: Your_Public_IPAddress', 'X-MACAddress: Your_MAC_Address', 'X-PrivateKey: Your_Private_Key');
    	    
    $data["clientcode"] = "MY_USERNAME"; 
    $data["password"] = "MY_PASSWORD";
    
    $url = 'https://apiconnect.angelbroking.com/rest/auth/angelbroking/user/v1/loginByPassword';
    
    $jsonData = json_encode($data);
    
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    
    curl_setopt($curl, CURLOPT_POSTFIELDS, $jsonData);
    curl_setopt($curl, CURLOPT_HEADEROPT, CURLHEADER_UNIFIED);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        
    $result = curl_exec($curl);
    $http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
    
    echo '<br/>Response Status : ' . $http_status;
    echo '<br/>Response String : ' . $result;
    
    //To Convert json response to array
    $resJsonArray = json_decode($responseContent, true);
    print_r($result);
    ?>
    
    

  • @jax248
    <?php
    $headers = array('Content-Type: application/json', 'Accept: application/json', 'X-UserType: USER', 'X-SourceID: WEB', 'X-ClientLocalIP: 208.91.198.55', 'X-ClientPublicIP: 43.225.3.40', 'X-MACAddress: 20-E6-17-07-19-3F', 'X-PrivateKey: 6gFpvIUn');
    $data["clientcode"] = "rkjj1005";
    $data["password"] = "MY_PASSWORD";

    $url = 'https://apiconnect.angelbroking.com/rest/auth/angelbroking/user/v1/loginByPassword';

    $jsonData = json_encode($data);

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    curl_setopt($curl, CURLOPT_HEADEROPT, CURLHEADER_UNIFIED);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

    $result = curl_exec($curl);
    $http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

    echo '<br/>Response Status : ' . $http_status;
    echo '<br/>Response String : ' . $result;

    //To Convert json response to array
    $resJsonArray = json_decode($responseContent, true);
    ?>
    I recieve output :
    Response Status : 400
    Response String :

    how to reslove this error?


  • Thanks for fast reply .
    I apply this code after modify header eg
    $headers = array('Content-Type: application/json', 'Accept: application/json', 'X-UserType: USER', 'X-SourceID: WEB', 'X-ClientLocalIP: 208.91.198.55', 'X-ClientPublicIP: 43.225.3.40', 'X-MACAddress: 20-E6-17-07-19-3F', 'X-PrivateKey: MY_API_KEY');

    but I web page given this error :

    Response Status : 400
    Response String :
    Notice: Undefined variable: responseContent in C:\xampp\htdocs\test\login.php on line 28


  • @aksharmty Till any SDK is not release for PHP, you can login as below:

    <?php
    
    $headers = array('Content-Type: application/json', 'Accept: application/json', 'X-UserType: USER', 'X-SourceID: WEB', 'X-ClientLocalIP: Your_Local_IPAddress', 'X-ClientPublicIP: Your_Public_IPAddress', 'X-MACAddress: Your_MAC_Address', 'X-PrivateKey: Your_Private_Key');
    	    
    $data["clientcode"] = "Your_UserName";
    $data["password"] = "Your_Password";
    
    $url = 'https://apiconnect.angelbroking.com/rest/auth/angelbroking/user/v1/loginByPassword';
    
    $jsonData = json_encode($data);
    
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    curl_setopt($curl, CURLOPT_HEADEROPT, CURLHEADER_UNIFIED);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        
    $result = curl_exec($curl);
    $http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
    
    echo '<br/>Response Status : ' . $http_status;
    echo '<br/>Response String : ' . $result;
    
    //To Convert json response to array
    $resJsonArray = json_decode($responseContent, true);
    ?>
    

  • Dear @aksharmty we are working on PHP sdk we will update you on this.

  • Bugs

    Found a bug? Use this category to report us.

  • Java SDK

    Ask Java SDK related queries here.

  • R SDK

    Ask R SDK related queries here.

  • Go SDK

    Ask Go SDK related queries here.

How SmartAPI works