HP ALM REST API - Get ALM Releases

Aneejian · Mar 30, 2017 · 9 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">
         <Field Name="req-count">
         <Field Name="ver-stamp">
         <Field Name="description">
            <Value>Release Description</Value>
         <Field Name="scope-items-count">
         <Field Name="start-date">
         <Field Name="has-attachments">
            <Value />
         <Field Name="end-date">
         <Field Name="last-modified">
            <Value>2016-10-06 00:06:25</Value>
         <Field Name="name">
         <Field Name="milestones-count">
         <Field Name="id">
         <Field Name="parent-id">
      <RelatedEntities />

Code Method

Required Inputs

Parameter Example / Comments
HP ALM Base URL http://youralmurl:port/qcbin
HP ALM Domain Name Enter 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 Name Enter 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 CookieContainer Pass 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 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}
  projectReleasesList = releaseQuery
 End Using
 Return projectReleasesList
End Function
Dim projectReleases = GetProjectReleases(almBaseUrl, "domainName", "projectName", authenticationCookieContainer)
For Each pr As ProjectReleases In projectReleases

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)})
  projectReleasesList = releaseQuery;
 return projectReleasesList;
var projectReleases = GetProjectReleases(almBaseUrl, "domainName", "projectName", authenticationCookieContainer);
foreach (var pr in projectReleases)

Sample Output

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.