HP ALM REST API - Authentication

Tutorial on how to authenticate HP ALM Session using REST API. Includes VB and C# code for Sign-in and Sign-out resources.

Tutorial on how to authenticate HP ALM Session using REST API. Includes VB and C# code for Sign-in and Sign-out resources
Contents of this post
  • Introduction to ALM Authentication Resource 
  • Explanation on Sign-in resource 
  • Sign-in codes
    • VB Code for Sign-in
    • C# Code for Sign-in
  • Explanation on Sign-out resource
  • Sign-out codes
    • VB Code for Sign-out
    • C# Code for Sign-out

HP ALM provides two resources for Authentication.
  • Sign-in
  • Sign-out


The sign-in resource request authorization. To sucessfully authenticate we have to post user and password in BASE64 encoding in the Authorization header.

resource sets the authentication cookies required for future requests.
  • QCSession

URI

Uri for sign-in is /qcbin/api/authentication/sign-in
e.g. http://youralmserver:port/qcbin/api/authentication/sign-in

  • For ALM Versions prior to 12.53

    Uri for sign-in is /qcbin/authentication-point/authenticate?login-form-required=y
    e.g. http://youralmserver:port/qcbin/authentication-point/authenticate?login-form-required=y

    If this URI is provided directly to browser, you will get a prompt to enter your user name and password. Once you enter the correct credentials you will be taken to a blank screen.


    Doing it with code

    Inputs Required
    Prameter Example
    HP ALM Base URL http://youralmurl:port/qcbin
    HP ALM User Name aneejian
    HP ALM Password Password
    Sample Response

    ****  Request ***
    POST /qcbin/api/authentication/sign-in HTTP/1.1
    Authorization: Basic 123456789abcdef=
    Host: myserver:8081
    ****  Response ***
    HTTP/1.1 200 OK
    Set-Cookie: LWSSO_COOKIE_KEY=0123456789abcdef;Path=/;HTTPOnly
    Set-Cookie: QCSession=0123456789abcdef;Path=/;HttpOnly
    Expires: Thu, 01 Jan 1970 00:00:00 GMT
    Set-Cookie: ALM_USER=0123456789abcdef;Path=/
    Set-Cookie: XSRF-TOKEN=0123456789abcdef;Path=/
    Content-Length: 0

    Sign-in Code

    VB Code to get Authentication Cookies

    Private Function GetAuthenticationCookieContainer(almBaseUrl, almUserName, almPassword) As CookieContainer
     Dim authCookies = new CookieContainer()
     Dim auth As HttpWebRequest = WebRequest.Create(almBaseUrl + "/api/authentication/sign-in")
     Dim credentials As String = $"{almUserName}:{almPassword}"
     auth.CookieContainer = authCookies
     auth.Headers.Set(HttpRequestHeader.Authorization, "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(credentials)))
     Dim authResult As WebResponse = auth.GetResponse()
     Return authCookies
    End Function


    Dim AuthenticationCookieContainer = GetAuthenticationCookieContainer("http://youralmurl:port/qcbin", "aneejian", "Password")

    C# Code to get Authentication Cookies

    private static CookieContainer GetAuthenticationCookie(string almBaseUrl, string almUserName, string almPassword)
        var authCookies = new CookieContainer();
        var auth = (HttpWebRequest)WebRequest.Create(almBaseUrl + "/api/authentication/sign-in");
        var credentials = $"{almUserName}:{almPassword}";
        auth.CookieContainer = authCookies;
        auth.Headers.Set(HttpRequestHeader.Authorization, "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(credentials)));
        var authResult = auth.GetResponse();
        return authCookies;


    var authenticationCookieContainer = GetAuthenticationCookie("http://youralmurl:port/qcbin", "aneejian", "Password");
  • For ALM Versions prior to 12.53
    In the code replace /api/authentication/sign-in with /authentication-point/authenticate


    The sign-out resource logs the user off the system. It cancels the cookies returned by Sign-in.
    • QCSession 
    • ALM_USER 

    Sign-out URI

    Uri for sign-out is /qcbin/api/authentication/sign-out
    e.g. http://youralmserver:port/qcbin/api/authentication/sign-out

  • For ALM Versions prior to 12.53

    Uri for sign-out is /qcbin/authentication-point/logout
    e.g. http://youralmserver:port/qcbin/authentication-point/logout
    If you pass this to the browser where you signed in, it will sign you out from ALM.

    Sign-out Code

    VB Code to Sign-out

    Private Sub Signout(almBaseUrl As String, AuthenticationCookieContainer)
     Dim auth = CType(WebRequest.Create(almBaseUrl + "/api/authentication/sign-out"), HttpWebRequest)
     auth.CookieContainer = AuthenticationCookieContainer
     Dim authResult = auth.GetResponse()
    End Sub


    SignOut("http://youralmurl:port/qcbin", AuthenticationCookieContainer)

    C# Code to Sign-out

    private static void SignOut(string almBaseUrl, CookieContainer authenticationCookieContainer)
     var auth = (HttpWebRequest)WebRequest.Create(almBaseUrl + "/api/authentication/sign-out");
     auth.CookieContainer = authenticationCookieContainer; //authenticationCookieContainer is the CookieContainer you got from GetAuthenticationCookieContainer function.
     var authResult = auth.GetResponse();


    SignOut("http://youralmurl:port/qcbin", authenticationCookieContainer);
  • For ALM Versions prior to 12.53
    In the code replace /authentication/sign-out with /authentication-point/logout



    AngularJS,3,Automation Testing,8,Blue Prism,1,CSharp,5,Disqus,1,Excel,3,Excel Addin,1,HP ALM,5,HTML5,1,ISTQB,2,Java Script,2,Manual Testing,7,Photography,1,Quiz,2,REST API,5,Robotic Process Automation,2,RPA,2,Testing,15,UFT,8,UiPath,1,VB,5,VBScript,1,VSTO,1,Wordpress,1,
    Aneejian: HP ALM REST API - Authentication
    HP ALM REST API - Authentication
    Tutorial on how to authenticate HP ALM Session using REST API. Includes VB and C# code for Sign-in and Sign-out resources.
    Loaded All Posts No posts found VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU ARCHIVE SEARCH ALL POSTS No post found which matches with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content