HP ALM REST API - Get ALM Releases

. 4 mins read

HP ALM REST API - Get ALM Releases

Tutorial on how to get releases under a project in HP ALM using REST API. Includes browser method, VB.NET and C# functions to get releases.

Web Browser Method

  • Open your favorite browser.
  • Enter HP ALM REST API URL: http://youralmserver:port/qcbin/api/authentication/sign-in
  • Enter your ALM User Name and Password in the prompt that you get on navigating to the above URL.
  • Once successful authentication has occurred you will get a blank page.
  • Now enter the URL to get releases in the same browser window: http://youralmserver:port/qcbin/rest/domains/domainName/projects/projectName/releases (Domain name and the Project name are case sensitive. Use the name as displayed in ALM.)
  • Once you enter this URL and press enter, you will get the list of releases under the project under the domain you specified in the URL in XML format.

Sample Output

<Entities TotalResults="1">
   <Entity Type="release">
      <ChildrenCount>
         <Value>0</Value>
      </ChildrenCount>
      <Fields>
         <Field Name="req-count">
            <Value>0</Value>
         </Field>
         <Field Name="ver-stamp">
            <Value>30</Value>
         </Field>
         <Field Name="description">
            <Value>Release Description</Value>
         </Field>
         <Field Name="scope-items-count">
            <Value>0</Value>
         </Field>
         <Field Name="start-date">
            <Value>2015-08-05</Value>
         </Field>
         <Field Name="has-attachments">
            <Value />
         </Field>
         <Field Name="end-date">
            <Value>2015-08-19</Value>
         </Field>
         <Field Name="last-modified">
            <Value>2016-10-06 00:06:25</Value>
         </Field>
         <Field Name="name">
            <Value>Release1</Value>
         </Field>
         <Field Name="milestones-count">
            <Value>2</Value>
         </Field>
         <Field Name="id">
            <Value>1003</Value>
         </Field>
         <Field Name="parent-id">
            <Value>104</Value>
         </Field>
      </Fields>
      <RelatedEntities />
   </Entity>
   <singleElementCollection>false</singleElementCollection>
</Entities>

Code Method

Required Inputs

ParameterExample / Comments
HP ALM Base URLhttp://youralmurl:port/qcbin
HP ALM Domain NameEnter the name of the domain from which you want the list of projects. Refer HP ALM REST API – Get ALM Domains for details on how to get domains from ALM.
HP ALM Project NameEnter the name of the project from which you want the list of releases. Refer HP ALM REST API – Get ALM Projects for details on how to get projects from ALM.
Authentication CookieContainerPass the authentication cookiecontainer obtained while you authenticated. Refer HP ALM REST API – Authentication for details.

In order to store Release information, create a class ProjectReleases Refer respective code sections for the class definition

VB.NET Code

VB.NET Code to define ProjectReleases class

Friend Class ProjectReleases
 Public Property ReleaseId() As Integer
 Public Property ReleaseName() As String
 Public Property ReleaseStartDate() As Date
 Public Property ReleaseEndDate() As Date

 Public Overrides Function ToString() As String
  Return $"Release ID: {ReleaseId}{vbLf}Release Name: {ReleaseName}{vbLf}Release Start Date: {ReleaseStartDate}{vbLf}Release End Date: {ReleaseEndDate}{vbLf}{vbLf}"
 End Function
End Class

VB Code to get Releases under Project

Private Function GetProjectReleases(almBaseUrl As String, domainName As String, projectName As String, authenticationCookieContainer As CookieContainer) As IEnumerable(Of ProjectReleases)
 Dim projectReleasesList = New List(Of ProjectReleases)()
 Dim releaseRestApiUrl = $"{almBaseUrl}/rest/domains/{domainName}/projects/{projectName}/releases"
 Dim projectReleasesRequest = CType(WebRequest.Create(releaseRestApiUrl), HttpWebRequest)
 projectReleasesRequest.CookieContainer = authenticationCookieContainer
 Dim projectReleasesResponse = projectReleasesRequest.GetResponse()
 Dim projectReleaseResponseStream = projectReleasesResponse.GetResponseStream()
 If projectReleaseResponseStream Is Nothing Then
  Return projectReleasesList
 End If
 Using responseReader = New StreamReader(projectReleaseResponseStream)
  Dim responseString = responseReader.ReadToEnd()
  Dim responseXml = XElement.Parse(responseString)
  Dim entitiesXml = responseXml.Descendants("Entity")
  Dim releaseQuery = (From e As XElement In entitiesXml
       Let relId = e....Single(Function(x) x.Attribute("Name").Value = "id").Value
       Let relName = e....Single(Function(x) x.Attribute("Name").Value = "name").Value
       Let relStartDate = e....Single(Function(x) x.Attribute("Name").Value = "start-date").Value
       Let relEndDate = e....Single(Function(x) x.Attribute("Name").Value = "end-date").Value
       Select New ProjectReleases With {.ReleaseId = relId, .ReleaseName = relName, .ReleaseStartDate = relStartDate, .ReleaseEndDate = relEndDate}
        ).ToList()
  projectReleasesList = releaseQuery
 End Using
 Return projectReleasesList
End Function
Usage of VB.NET code
Dim projectReleases = GetProjectReleases(almBaseUrl, "domainName", "projectName", authenticationCookieContainer)
For Each pr As ProjectReleases In projectReleases
 Console.WriteLine(pr.ToString())
Next

C# Code

C# Code to define ProjectReleases class

internal class ProjectReleases
{
 public int ReleaseId { get; set; }
 public string ReleaseName { get; set; }
 public DateTime ReleaseStartDate { get; set; }
 public DateTime ReleaseEndDate { get; set; }

 public override string ToString()
 {
  return $"Release ID: {ReleaseId}\nRelease Name: {ReleaseName}\nRelease Start Date: {ReleaseStartDate}\nRelease End Date: {ReleaseEndDate}\n\n";
 }
}

C# Code to get Releases under Project

private static IEnumerable GetProjectReleases(string almBaseUrl, string domainName,
 string projectName, CookieContainer authenticationCookieContainer)
{
 var projectReleasesList = new List();
 var releaseRestApiUrl = $"{almBaseUrl}/rest/domains/{domainName}/projects/{projectName}/releases";
 var projectReleasesRequest = (HttpWebRequest)WebRequest.Create(releaseRestApiUrl);
 projectReleasesRequest.CookieContainer = authenticationCookieContainer;
 var projectReleasesResponse = projectReleasesRequest.GetResponse();
 var projectReleaseResponseStream = projectReleasesResponse.GetResponseStream();
 if (projectReleaseResponseStream == null) return projectReleasesList;
 using (var responseReader = new StreamReader(projectReleaseResponseStream))
 {
  var responseString = responseReader.ReadToEnd();
  var responseXml = XElement.Parse(responseString);
  var entitiesXml = responseXml.Descendants("Entity");
  var releaseQuery = (from entity in entitiesXml
       select entity.Descendants("Field")
    into releaseFields
       select releaseFields as IList ?? releaseFields.ToList()
    into relElements
       let relId = relElements.Single(x => x.Attribute("Name").Value == "id").Value
       let relName = relElements.Single(x => x.Attribute("Name").Value == "name").Value
       let relStartDate = relElements.Single(x => x.Attribute("Name").Value == "start-date").Value
       let relEndDate = relElements.Single(x => x.Attribute("Name").Value == "start-date").Value
       select new ProjectReleases { ReleaseId = int.Parse(relId), ReleaseName = relName, ReleaseStartDate = DateTime.Parse(relStartDate), ReleaseEndDate = DateTime.Parse(relEndDate)})
   .ToList();
  projectReleasesList = releaseQuery;
 }
 return projectReleasesList;
}
Usage of C# code
var projectReleases = GetProjectReleases(almBaseUrl, "domainName", "projectName", authenticationCookieContainer);
foreach (var pr in projectReleases)
{
 Console.WriteLine(pr.ToString());
}

Output Sample

Release ID: 1003
Release Name: Release1
Release Start Date: 05-12-2015
Release End Date: 05-01-2016

Release ID: 1004
Release Name: Release2
Release Start Date: 05-12-2015
Release End Date: 05-01-2016

Release ID: 1005
Release Name: Release3
Release Start Date: 05-12-2015
Release End Date: 05-01-2016

You can get additional release details from other fields available in ALM. Add fields to the class and release query in code.

ProgrammingSoftware Testing
HP ALM REST API - Get ALM Domains and Projects Together
23 Mar 2017

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

ProgrammingSoftware Testing
HP ALM REST API - Get ALM Projects
22 Mar 2017

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

ProgrammingSoftware Testing
HP ALM REST API - Get ALM Domains
21 Mar 2017

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 @aneejian.