$show=home$hide=mobile-page

HP ALM REST API - Get ALM Domains and Projects Together

Tutorial on how to get domains and projects from HP ALM using REST API together. Includes browser method, VB and C# functions to get them together.

HP ALM REST API - Get ALM Domains and Projects Together
Tutorial on how to get domains and projects from HP ALM using REST API together. Includes browser method, VB and C# functions to get them together

Contents of this post.

[post_ads]

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 you 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?include-projects-info=y
  6. Once you enter this url and press enter you will get the list of domains and projects under them. Resulting XML includes all domainss and projects you have access to in HP ALM.
  •  
  • For ALM Versions prior to 12.53
    In urls, replace api with rest
    e.g. http://youralmserver:port/qcbin/rest/domains?include-projects-info=y

    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" ?> 
    <Domains>
     <Domain Name="Domain1">
      <Projects>
       <Project UID="172a-321-543-1" Name="Project1" /> 
       <Project UID="172a-321-543-2" Name="Project2" /> 
       <Project UID="172a-321-543-3" Name="Project3" /> 
      </Projects>
     </Domain>
     <Domain Name="Domain2">
      <Projects>
       <Project UID="172a-321-543-11" Name="ProjectA" /> 
       <Project UID="172a-321-543-21" Name="ProjectB" /> 
       <Project UID="172a-321-543-43" Name="ProjectC" /> 
       <Project UID="172a-321-543-44" Name="ProjectD" /> 
       <Project UID="172a-321-543-56" Name="ProjectE" /> 
      </Projects>
     </Domain>
     <Domain Name="Domain3">
      <Projects>
       <Project UID="172a-321-543-31" Name="ProjectX" /> 
       <Project UID="172a-321-543-25" Name="ProjectY" /> 
      </Projects>
     </Domain>
    </Domains>

    Code Method

    Inputs Required
    Prameter Example / Comments
    HP ALM Base URL http://youralmurl:port/qcbin
    Authentication CookieContainer

    Pass the authentication cookiecontainer obtained while you authenticated.

    Refer HP ALM REST API - Authentication for details.

    [post_ads_2]

    In order to store Domain and Project information, create a class DomainProject
    Refer respective code sections for class definition

    VB Code to define DomainProject class

    Friend Class DomainProject
     Public Property Domain() As String
      Get
       Return m_Domain
      End Get
      Set
       m_Domain = Value
      End Set
     End Property
     Private m_Domain As String
     Public Property ProjectList As List(Of String) = New List(Of String)
     Public Overrides Function ToString() As String
            Return $"Domain: {Domain}{vbLf}Project Count: {ProjectList.Count}{vbLf}{vbTab}{ProjectList.Aggregate(Function(a,b) a + vbLf + vbTab + b)}{vbLf}"
     End Function
    End Class

    VB Code to get ALM Domains and Projects Together

    Private Function GetDomainProject(almBaseUrl As String, authenticationCookieContainer As CookieContainer) As List(Of DomainProject)
     Dim domainProjectList = New List(Of DomainProject)()
     Dim domainProjectRequest = CType(WebRequest.Create(almBaseUrl + "/api/domains?include-projects-info=y"), HttpWebRequest)
     domainProjectRequest.CookieContainer = authenticationCookieContainer
     Dim domainProjectRequestResponse = domainProjectRequest.GetResponse()
     Dim domainProjectRequestResponseStream = domainProjectRequestResponse.GetResponseStream()
     If domainProjectRequestResponseStream Is Nothing Then
      Return domainProjectList
     End If
     Using responseReader = New StreamReader(domainProjectRequestResponseStream)
      Dim responseString = responseReader.ReadToEnd()
      Dim responseXml = XElement.Parse(responseString)
      Dim projectListXml = responseXml.Descendants("Projects")
      Dim projectQuery = From project In projectListXml.Elements()
             Let domainName = project.Parent.Parent.FirstAttribute.Value
             Let projectName = project.Attribute("Name").Value
             Order By domainName, projectName
             Select New With {domainName, projectName}
    
      domainProjectList = projectQuery.GroupBy(Function(d) d.domainName).[Select](Function(p) New DomainProject With {.Domain = p.Key, .ProjectList = p.[Select](Function(q) q.projectName).ToList()}).ToList()
     End Using
     Return domainProjectList
    End Function

    Usage

    Dim almDomainProjects = GetDomainProject(almBaseUrl, authenticationCookieContainer);
    For Each dp As DomainProject in almDomainProjects
     Console.WriteLine(dp.ToString());
    Next

    C# Code to define DomainProject class

    internal class DomainProject
    {
     public string Domain { get; set; }
     public List ProjectList { get; set; }
     public override string ToString()
     {
      return $"Domain: {Domain} \nProject Count: {ProjectList.Count} \n\t{ProjectList.Aggregate((a, b) => a + "\n\t" + b)}\n";
     }
    }

    C# Code to get ALM Domains and Projects Together

    private static IEnumerable GetDomainProject(string almBaseUrl, CookieContainer authenticationCookieContainer)
    {
     var domainProjectList = new List();
     var domainProjectRequest = (HttpWebRequest)WebRequest.Create(almBaseUrl + "/api/domains?include-projects-info=y");
     domainProjectRequest.CookieContainer = authenticationCookieContainer;
     var domainProjectRequestResponse = domainProjectRequest.GetResponse();
     var domainProjectRequestResponseStream = domainProjectRequestResponse.GetResponseStream();
     if (domainProjectRequestResponseStream == null) return domainProjectList;
     using (var responseReader = new StreamReader(domainProjectRequestResponseStream))
     {
      var responseString = responseReader.ReadToEnd();
      var responseXml = XElement.Parse(responseString);
      var projectListXml = responseXml.Descendants("Projects");
      var projectQuery = from project in projectListXml.Elements()
             let domainName = project.Parent.Parent.FirstAttribute.Value
             let projectName = project.Attribute("Name").Value
             orderby domainName, projectName
             select new { domainName, projectName };
      domainProjectList = (from d in projectQuery group d.projectName by d.domainName into dp select new DomainProject { Domain = dp.Key, ProjectList = dp.ToList() }).ToList();
     }
     return domainProjectList;
    }

    Usage

    var almDomainProjects = GetDomainProject(almBaseUrl, authenticationCookieContainer);
    foreach (var dp in almDomainProjects)
    {
     Console.WriteLine(dp.ToString());
    }

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

    Sample Output

    Domain: Domain1
    Project Count: 3
     Project1
     Project2
     Project3
     
    Domain: Domain2
    Project Count: 5
     ProjectA
     ProjectB
     ProjectC
     ProjectD
     ProjectE
     
    Domain: Domain3
    Project Count: 2
     ProjectX
     ProjectY
    
  •  
  • Tip

    You can use this code to get information from all domains and projects without hard coding domain names and project names. Use the DomainProject class to get data from various Domain-Project combinations.

    COMMENTS





    Name

    AngularJS,3,Automation Testing,8,CSharp,5,Disqus,1,Excel,2,HP ALM,5,HTML5,1,ISTQB,2,Java Script,2,Manual Testing,7,Photography,1,Quiz,2,REST API,5,Testing,15,UFT,8,VB,5,VBScript,1,Wordpress,1,
    ltr
    item
    Aneejian: HP ALM REST API - Get ALM Domains and Projects Together
    HP ALM REST API - Get ALM Domains and Projects Together
    Tutorial on how to get domains and projects from HP ALM using REST API together. Includes browser method, VB and C# functions to get them together.
    https://2.bp.blogspot.com/-zy4l7f61wgw/WNPdgSHdpfI/AAAAAAAAAMk/QFin-OlJRmAmXOuxWP67vwvKitOdwZSQgCLcB/s320/domainProject.jpg
    https://2.bp.blogspot.com/-zy4l7f61wgw/WNPdgSHdpfI/AAAAAAAAAMk/QFin-OlJRmAmXOuxWP67vwvKitOdwZSQgCLcB/s72-c/domainProject.jpg
    Aneejian
    http://www.aneejian.com/2017/03/hp-alm-rest-api-get-alm-domains-projects-together.html
    http://www.aneejian.com/
    http://www.aneejian.com/
    http://www.aneejian.com/2017/03/hp-alm-rest-api-get-alm-domains-projects-together.html
    true
    5798203121010168414
    UTF-8
    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 CONTENT IS PREMIUM Please share to unlock 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