Fetch Token - Login

JWT TOKEN - Rest API Login

  • Login using an HTTP POST request by providing username and password
  • Receives a JWT authentication Token for later requests to identify the authorized user
  • Send the Authentication Token with subsequent requests typically HTTP Headers like Authorization: Bearer AUTH_JWT_TOKEN

Login API Specs

Login - http://uat.tickermarket.com/TPILWebAPI/Api/V1/Users/Login

Http Method must be a POST Request
Http Scheme http
Hostname Server IP ( e.g http://uat.tickermarket.com)
Port -
Path TPILWebAPI/Api/V1/Users/Login (Login Endpoint path)
POST Parameters BODY

{ "username":"ABC", "password": "1111" }

Response JSON Format

{ "token": "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJERkRFTU8wMDAxICAgICAiLCJERkRFTU8wMDAxICAgICAiOiIxNzIuMjAuMTAyLjQyIiwiQXBpS2V5IjoiRlgwMDEtMTAwMCIsImV4cCI6MTYzMDQ5MzcxNSwiaWF0IjoxNjMwNDgxNzE1fQ.5fDEI8lb7Xlc9F3Qogod6HrNg5fRD51T05F--mOC1VIgxPJ2i9h3J1M69m3mT6DEANglPXF0zioQHS46WV5U6Q" }

  • Extracting JWT AUTH TOKEN-Token Based Authentication is a simple mechanism where a token uniquely identifies a user session.
  • Once JSON Extractor is working then we can use the subsequent requests to perform authenticated requests.
Error Response

Code: 401 UNAUTHORIZED
Content: {error : "You are unauthorized to make this request." }

OR

Code: 404 NOT FOUND
Content: {error: "User doesn't exist" }

                                                      
                            {
                                                "username":"xxxxx",
                                                "password":"xxxxxx"
                                                                               }
                                                                              
                                                      
                        [
    {
                                        "token": "eyJhbGciOiJIUzUxMiJ9.eyJERkRFTU8wMDU4ICAgICAiOiIyMDMuMTE0LjI0MC4xNjgiLCJzdWIiOiJERkRFTU8wMDU4ICAgICAiLCJBcGlLZXkiOiJDWDAwMS01MCIsImV4cCI6MTY1ODI5NzU3NCwiaWF0IjoxNjU4MjM3NTc0fQ.oV-pRQALRkew035JW_0aTZ0pwDfspAjZpiCtcMdPvlLqFSWp9AiExWQeSlKjirYri5PRxUud44JhWiL4iq6l7Q"
                                                                    }
    ]

                      
                                                      
                            {
                                "username":"xxxxx",
                                "password":"xxxxxx"
                                                                               }
                                                                              
                                                      
                                        <BSEList>
                                        <item>
                                        <Segment>BSE</Segment>
                                        <Instrument>Equity</Instrument>
                                        <TPILCode>658</TPILCode>
                                        <IndexName>SENSEX</IndexName>
                                        <DateTime>16-September-2021 16:5:0</DateTime>
                                        <CurrentIndexValue>59141.16</CurrentIndexValue>
                                        <OpenIndexValue>58881.04</OpenIndexValue>
                                        <HighIndexValue>59204.29</HighIndexValue>
                                        <LowIndexValue>58700.50</LowIndexValue>
                                        <CloseIndexValue>58723.20</CloseIndexValue>
                                        <NetChange>417.96</NetChange>
                                        <PercentChange>0.71</PercentChange>
                                        <52WeekHighIndexValue>59204.29</52WeekHighIndexValue>
                                        <52WeekLowIndexValue>36495.98</52WeekLowIndexValue>
                                        </item>
                                        </BSEList>
                        
                                    
                                        // Java Data Services - Login
                                        URL url = new
                                        URL("http://uat.tickermarket.com/TPILWebAPI /Api/V1/Users/Login");

                                        //Open URL connection
                                        HttpURLConnection http = (HttpURLConnection)url.openConnection();

                                        //POST Request
                                        http.setRequestMethod("POST");
                                        http.setDoOutput(true);
                                        http.setRequestProperty("Accept", "application/json");
                                        http.setRequestProperty("Content-Type", "application/json");
                                        

                                        //Create the Request Body
                                        String data = "{\n  \"username\": 1111,\n  \"password\": "abc",\n  \"rType\": 1,\n  }";
                                        byte[] out = data.getBytes(StandardCharsets.UTF_8);

                                        // Response Data
                                        OutputStream stream = http.getOutputStream();
                                        stream.write(out);
                                        System.out.println(http.getResponseCode() + " " + http.getResponseMessage());
                                        BufferedReader br=new BufferedReader(new InputStreamReader((http.getInputStream())));
                                        StringBuilder sb= new StringBuilder();
                                        String output;
                                        While((output=br.readLine())!=null)
                                        {
                                        sb.append(output);
                                        }catch(Exception e) { System.out.println(“Exception e”+ e);
                                        http.disconnect();


                                    
                                    
                                        // C# Data Services - Login
                                        var  url = "http://uat.tickermarket.com/TPILWebAPI /Api/V1/Users/Login");
                                        var httpRequest= (HttpWebRequest) WebRequest.Create(url);

                                        

                                        //POST Request
                                        http.setRequestMethod("POST");

                                        httpRequest.Accept("application/json");

                                        httpRequest.ContentType("application/json");

                                        //Create the Request Body
                                        var logindata = @" {
                                        ""username"" : 1111,
                                        ""password"" : abc}";



                                        // Response Data

                                        var httpResponse = (HttpWebResponse) httpRequest.GetResponse();
                                        Using ( var streamReader = new
                                        StreamReader(httpResponse.GetResponseStream()))
                                        {
                                        Var result= streamReader.ReadToEnd();
                                        }
                                        Console.WriteLine(httpResponse.StatusCode);


                                    
                                    
                                        //Python Data Services - LOGIN
                                        Import requests
                                        From requests.structure import CaseInsensitiveDict

                                        url = ("www.tickermarket.com/TPILWebAPI/Api/V1/Users/Login");
                                        headers = CaseInsensitiveDict()



                                        

                                        //POST Request


                                        headers [ "Accept"] = "application/json"
                                        headers["Content-Type"] = "application/json"


                                        //Create the Request Body
                                        data=  "username=Abc&password=123"




                                        // Response Data

                                        resp= requests.post(url,headers=headers, data=data)
                                        print(resp.status_code)



                                    
                                    
                                        //Javascript Data Services - LOGIN


                                        Var url=("www.tickermarket.com/TPILWebAPI/Api/V1/Users/Login" )
                                        Var xhr = new XMLHttpRequest();

                                        //POST Request


                                        xhr.open("POST", url);
                                        xhr.setRequestHeader("Accept","application/json" );
                                        xhr.setRequestHeader(Content-Type, "application/json" );

                                        xhr.onreadystatechange= function() {
                                        if(xhr.readyState === 4)
                                        {
                                        Console.log(xhr.status);
                                        Console.log(xhr.responseText);
                                        }};



                                        //Create the Request Body
                                        var data = '{
                                        "username": 1111,
                                        "password": "abc"
                                        }
                                        ';





                                        // Response Data

                                        Xhr.send(data);
                                        Console.log(xhr.status);