More

    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

    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 releases in the same browser window: http://youralmserver:port/qcbin/rest/domains/domainName/projects/projectName/releases (Domain name and the Project name is case sensitive. Use the name as displayed in ALM.)
    6. 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

    <?xml version="1.0" encoding="UTF-8"?>
    <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

    PrameterExample / 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

    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

    var projectReleases = GetProjectReleases(almBaseUrl, "domainName", "projectName", authenticationCookieContainer);
    foreach (var pr in projectReleases)
    {
     Console.WriteLine(pr.ToString());
    }

    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.

    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