HP ALM REST API – Get ALM Domains

    Tutorial on how to get domains from HP ALM using REST API. Includes the browser method, VB.NET and C# functions to get domains. Learn more with Aneejian.

    Post Contents

    Web Browser Method

    1. Open your favorite browser.
    2. Enter HP ALM REST API URL: http://youralmserver:port/qcbin/api/authentication/sign-in
    3. Enter your ALM User Name and Password in the prompt that you get on navigating to the above URL.
    4. Once successful authentication has occurred you will get a blank page.
    5. Now enter the URL to get domains in the same browser window: http://youralmserver:port/qcbin/api/domains
    6. Once you enter this URL and press enter you will get domain list you have access to in XML format.

    For ALM Versions prior to 12.53
    In URLs, replace api with rest
    e.g. http://youralmserver:port/qcbin/rest/domains

    Refer HP ALM REST API – Authentication for details on how to sign-in in older versions of ALM.

    Sample Output

    <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> 
     <Domain Name="Domain1" /> 
     <Domain Name="Domain2" /> 
     <Domain Name="Domain3" /> 
     <Domain Name="Domain4" /> 
     <Domain Name="Domain5" /> 

    Code Method

    For ALM Versions prior to 12.53
    In the code replace /api/domains with /rest/domains

    Parameters Required

    ParameterExample / Comments
    HP ALM Base URLhttp://youralmurl:port/qcbin
    Authentication CookieContainerPass the authentication cookie container obtained while you authenticated.
    Refer HP ALM REST API – Authentication for details.

    VB.Net Code to get ALM Domains

    Private Function GetDomains(almBaseUrl As String, authenticationCookieContainer As CookieContainer) As IEnumerable(Of String)
     Dim domainList = New List(Of String)()
     Dim domainRequest = CType(WebRequest.Create(almBaseUrl + "/api/domains"), HttpWebRequest)
     domainRequest.CookieContainer = authenticationCookieContainer
     Dim domainResponse = domainRequest.GetResponse()
     Dim domainResponseStream = domainResponse.GetResponseStream()
     If domainResponseStream Is Nothing Then
      Return domainList
     End If
     Using responseReader = New StreamReader(domainResponseStream)
      Dim responseString = responseReader.ReadToEnd()
      Dim responseXml = XElement.Parse(responseString)
      Dim domainQuery = From domain In responseXml.Elements() Select New With {.domainName = domain.Attribute("Name").Value}
      domainList.AddRange(domainQuery.[Select](Function(domain) domain.domainName))
     End Using
     Return domainList
    End Function


    Dim almDomains = GetDomains("http://youralmurl:port/qcbin", AuthenticationCookieContainer)
    Console.WriteLine(almDomains.Aggregate(Function(a, b) a + vbLf + b))

    C# Code to get ALM Domains

    private static IEnumerable GetDomains(string almBaseUrl, CookieContainer authenticationCookieContainer)
     var domainList = new List();
     var domainRequest = (HttpWebRequest)WebRequest.Create(almBaseUrl + "/api/domains");
     domainRequest.CookieContainer = authenticationCookieContainer;
     var domainResponse = domainRequest.GetResponse();
     var domainResponseStream = domainResponse.GetResponseStream();
     if (domainResponseStream == null) return domainList;
     using (var responseReader = new StreamReader(domainResponseStream))
      var responseString = responseReader.ReadToEnd();
      var responseXml = XElement.Parse(responseString);
      var domainQuery = from domain in responseXml.Elements()
            select new { domainName = domain.Attribute("Name").Value };
      domainList.AddRange(domainQuery.Select(domain => domain.domainName));
     return domainList;


    var almDomains = GetDomains("http://youralmurl:port/qcbin", authenticationCookieContainer);
    Console.WriteLine(almDomains.Aggregate((a, b) => a + "\n" + b));

    Sample Output


    Related Articles

    Recent Articles

    How to fix Date Time data type issue in Blue Prism?

    Know more about the date time issue while using the code stage in Blue Prism and understand how to fix it by dealing with the UTC offset.

    How to deserialize JSON in UiPath?

    Tutorial on how to properly deserialize JSON with UiPath Web Activities. Explains the concept of JSON Array and JSON Object.

    Dynamic or Variable Selectors in UiPath

    Tutorial on how to use dynamic selectors in UiPath. Explains how to use variables in UiPath selectors.

    Change Case Excel Add-In

    Change Case Excel Add-In is a powerful Excel Add-In that can change the case of selected cells. With easy to use Keyboard shortcuts, perform case conversion in style.

    Blue Prism Video Tutorial

    A well-structured video tutorial on Blue Prism, which is the right starting point for your RPA career. #rpa #blueprism

    Leave a Reply

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    Stay on top - Get latest articles in your inbox