How to access ALM data using REST API (19329 Views)
Reply
Occasional Advisor
umapendse
Posts: 17
Registered: ‎09-27-2010
Message 1 of 20 (19,329 Views)

How to access ALM data using REST API

Hi all,
can anyone tell me how to access ALM data using REST API? Is there any java code example available?
Thanks in advance.
Please use plain text.
Frequent Advisor
Elad Avraham
Posts: 40
Registered: ‎12-06-2010
Message 2 of 20 (19,329 Views)

Re: How to access ALM data using REST API

Hi,
You can find the ALM 11.0 REST API reference guide here:
http://support.openview.hp.com/selfsolve/manuals

http://support.openview.hp.com/selfsolve/document/KM997956/binary/ALM11.00_RE
ST_API.html?searchIdentifier=-765a98c0%3a12de84ca170%3a-27ac&resultType=document

In the documentation you will find examples how to use Rest resources.
The main entry point it the authentication after then you can login to project, create entities and more using the exposed resources.

To consume it from Java read here:
http://blogs.sun.com/enterprisetechtips/entry/consuming_restful_web_services_with

Thanks,
Elad
Please use plain text.
Occasional Contributor
Justin Zhang
Posts: 5
Registered: ‎06-14-2011
Message 3 of 20 (19,329 Views)

Re: How to access ALM data using REST API

From: http://support.openview.hp.com/selfsolve/document/KM997956/binary/ALM11.00_RE
ST_API.html?searchIdentifier=-765a98c0%3a12de84ca170%3a-27ac&resultType=document

I can't see any examples of using Rest resources, Could you please be more specific?
Please use plain text.
Occasional Contributor
Justin Zhang
Posts: 5
Registered: ‎06-14-2011
Message 4 of 20 (19,329 Views)

Re: How to access ALM data using REST API

[ Edited ]

I figured out. please see:

http://forums13.itrc.hp.com/service/forums/questionanswer.do?threadId=1484300

 

Edited by Bill Groot:

The above link is an old ITRC link and will not work. I have found the thread so to see it please click on this link:

 

http://h30499.www3.hp.com/t5/Quality-Center-Support-and-News/HP-ALM-rest-API-usage-issue-during-logi...

Please use plain text.
Visitor
hugelsb
Posts: 2
Registered: ‎12-01-2011
Message 5 of 20 (19,115 Views)

Re: How to access ALM data using REST API

Unfortunately the last link is not valid anymore. Did someone manage to login via the Java API to HP-ALM? If yes may I ask you to send me the source code. Thanks a lot for any help.

Please use plain text.
Occasional Visitor
petejim
Posts: 1
Registered: ‎02-07-2012
Message 6 of 20 (18,912 Views)

Re: How to access ALM data using REST API

Did you get the ALM REST API working?  I'm seeking the .jar file to import into java servlets.

Please use plain text.
Visitor
hugelsb
Posts: 2
Registered: ‎12-01-2011
Message 7 of 20 (18,889 Views)

Re: How to access ALM data using REST API

Yes I found a way that is working. You can find the necessary files in the attached ZIP files.

Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,957
Registered: ‎03-06-2006
Message 8 of 20 (18,863 Views)

Re: How to access ALM data using REST API

>Unfortunately the last link is not valid anymore.

 

Looking at Justin's other topic, it's probably:

http://h30499.www3.hp.com/t5/Quality-Center-Support-and-News/HP-ALM-rest-API-usage-issue-during-logi...

Please use plain text.
Established Member
MelodyG
Posts: 2
Registered: ‎04-24-2012
Message 9 of 20 (18,487 Views)

Re: How to access ALM data using REST API

When I download the manual i can see the TOC, but when I open the page I receive an error "Navigation to the webpage was canceled

What you can try:
Retype the address. "

Please use plain text.
Occasional Visitor
gonella
Posts: 1
Registered: ‎08-31-2012
Message 10 of 20 (17,427 Views)

Re: How to access ALM data using REST API

I have developed a framework able to connect in ALM via restful. Please check it:

 

Api fo JAVA

 

http://code.google.com/p/alm-java-api/

Please use plain text.
Occasional Visitor
AtlMike
Posts: 1
Registered: ‎10-30-2012
Message 11 of 20 (16,909 Views)

Re: How to access ALM data using REST API

I get a 403 error when I try to navigate to the Google Code link you posted with your java alm rest api example. Can you repost the link? 

Please use plain text.
Occasional Visitor
RameshBadam
Posts: 1
Registered: ‎01-29-2013
Message 12 of 20 (16,102 Views)

Re: How to access ALM data using REST API

I got 404 when i clicked teh google  code link. Could you please give the correct link ?

Please use plain text.
Occasional Visitor
Splendiferous
Posts: 1
Registered: ‎10-25-2012
Message 13 of 20 (15,791 Views)

Re: How to access ALM data using REST API

I get proxy errors and missing page messages. I thought this was HP's SUOPPORT site? Not very impressive work, gentlemen!

Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,957
Registered: ‎03-06-2006
Message 14 of 20 (15,708 Views)

Re: How to access ALM data using REST API

>I thought this was HP's SUPPORT site?

 

No, this is a peer to peer forum, not an official HP support site.

Please use plain text.
Trusted Contributor
alexanderk
Posts: 122
Registered: ‎04-03-2012
Message 15 of 20 (15,685 Views)

Re: How to access ALM data using REST API

[ Edited ]

I've created a C# app that can authenticate, get and post to ALM REST API.

 

Should be very similar on Java.

 

Additionaly there are examples on JAVA in ALM REST API reference in ALM documant library.

 

Auth method:

 public void auth(string url, string xml)
        {          
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
                byte[] requestBytes = System.Text.Encoding.UTF8.GetBytes(xml.ToString());
                req.Method = "POST";
                req.ContentType = "application/xml";
                req.Accept = "application/xml";
                req.KeepAlive = true;
                req.AllowAutoRedirect = true;

                req.ContentLength = requestBytes.Length;
                Stream requestStream = req.GetRequestStream();
                requestStream.Write(requestBytes, 0, requestBytes.Length);
                requestStream.Close();
                HttpWebResponse res = (HttpWebResponse)req.GetResponse();
                StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.Default);
                backstr = sr.ReadToEnd();       
                myheader = res.Headers.Get("Set-Cookie"); 
                sr.Close();
                res.Close();

        }

 The tricky thing here that when you athenticate yourself you recieva a cookie that you SHOULD use further, when you do posts or gets.

But ALM returns you cookies NOT in http.cookie, but in HTTP response HEADER itself with name "Set-cookie".

So my header would be here: 

myheader = res.Headers.Get("Set-Cookie"); 

So now we call out auth method:

try
            {
// my creds, server domain etc are taken form apps UI.
                server_ = textBox2.Text;
                user_ = textBox5.Text;
                password_ = textBox6.Text;
                domain_ = textBox3.Text;
                project = textBox4.Text;
 
                REST.auth(server_ + "/authentication-point/alm-authenticate", "<?xml version='1.0' encoding='utf-8'?><alm-authentication><user>" + user_ + "</user><password>" + password_ + "</password></alm-authentication>");

                MessageBox.Show("Connected to REST");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

 Here is get method:

 public void get(string url)
        {                             
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
                req.Method = "GET";
                req.Accept = "application/xml";
                req.KeepAlive = true;
                req.AllowAutoRedirect = true;
                req.Headers.Add("Cookie", myheader);

                HttpWebResponse res = (HttpWebResponse)req.GetResponse();
                StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.Default);
                backstr = sr.ReadToEnd();               
                sr.Close();
                res.Close();
                        
        }

 So we add our header that we recieved after auth like : req.Headers.Add("Cookie", myheader);

cookie is stroed in myheader variable as we remember, right?

 

So here example of getting defects from ALM:

try
            {
               
// again creds, server, domain,etc. are taken from my apps variables.

                REST.get(server_ + "/rest/domains/" + domain_ +"/projects/" + project + "/defects/?page-size=1000");

                XPARSER.readXml(REST.backstr); // here I parse the response as I recieve xml - ignore that and everuthing that is below - it's relevant for my app.

               for (int i = 0; i < XPARSER.ids.Count; i++)
                {
                    listBox1.Items.Add(String.Format("{0} {1}", XPARSER.ids[i], XPARSER.names[i]));
                }
                XPARSER.ids.Clear();
                XPARSER.names.Clear();
                
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

 Here is post method:

public void post(string url, string xml)
        {
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);

            byte[] requestBytes = System.Text.Encoding.UTF8.GetBytes(xml.ToString());
            req.Method = "POST";
            req.ContentType = "application/xml";
            req.Accept = "application/xml";
            req.KeepAlive = true;
            req.AllowAutoRedirect = true;
            req.Headers.Add("Cookie", myheader);

            req.ContentLength = requestBytes.Length;
            Stream requestStream = req.GetRequestStream();
            requestStream.Write(requestBytes, 0, requestBytes.Length);
            requestStream.Close();

            HttpWebResponse res = (HttpWebResponse)req.GetResponse();
            StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.Default);
            backstr = sr.ReadToEnd();
            sr.Close();
            res.Close();
        }

When you want to create something you should send post http request.

Along with url you should provide an XML of an entity you are tying to post.

If you don't know how xml should look like - do a get request first

- recieve an xml and see how it looks like.

Here is example of posting a defect:

 try 
            {
                
                for (int i = 0; i < rest_bCount; ++i)
                   {

                      
                    REST.post(server_ + "/rest/domains/" + domain_ + "/projects/" + project + "/defects/",
                        @"<?xml version='1.0' encoding='utf-8'?>
                        <Entity Type='defect'>
                        <Fields>
                        <Field Name='description'>
                        <Value>desc</Value>
                        </Field>
                        <Field Name='name'>
                        <Value>defect created from rest" + i + Convert.ToString(rand.Next()) + "</Value></Field><Field Name='status'><Value>" + arr[i % arr.Length] + "</Value></Field><Field Name='severity'><Value>" + arr2[i % arr2.Length] + "</Value></Field><Field Name='detected-by'><Value>" + user_ + "</Value></Field><Field Name='creation-time'><Value>" + date.ToString(format) + "</Value></Field></Fields></Entity>"
                        );
                    XPARSER.readXml(REST.backstr);
}
 catch (Exception ex)
                {
                   
                    MessageBox.Show(ex.Message);
                }

 Hope that will help you a bit.

Please use plain text.
Advisor
Chuck Hunt
Posts: 19
Registered: ‎10-13-2008
Message 16 of 20 (8,322 Views)

Re: How to access ALM data using REST API

Great post on adding the defect.  My problem is how do I add a new test run and have it update all the necessary locations?

 

I've actually been able to add a run under the Test Instance Details but it doesn't update the Test on the Execution Grid.  I'd like for it to update that Status, Exec Date, Exec Time, etc.  Does anyone know what is actually needed to update this?

 

Please use plain text.
Occasional Visitor
damodarr
Posts: 1
Registered: ‎03-01-2014
Message 17 of 20 (8,297 Views)

Re: How to access ALM data using REST API

Hi  ,

 

   Thanks for the sample .Net code I have used the same but always I am getting "The remote server returned an error: (401) Unauthorized" exception (the test user iD /PWD will work perfect when logging in to QC manually). Can you please suggest is there anything need to setup in QC or any suggestions will be greatly appreciated.

 

Thanks in Advance

 

Please use plain text.
Valued Contributor
Pradeep0905
Posts: 92
Registered: ‎07-08-2013
Message 18 of 20 (7,728 Views)

Re: How to access ALM data using REST API

There are different ways (3 i guess) to authenticate into QC using REST. I'm using basic authentication and never tried web authentication as above. The basic concept is that when you authorize, a token cookie will be returned. Use this token cookie to perform an operation, which will return a session cookie and you need to use this session cookie on subsequent operations. On each operation a new session cookie will be returned. This is how session is managed in QC while using REST.

See if cookies are properly set.
Please use plain text.
Occasional Visitor
keerthi_maroju
Posts: 1
Registered: ‎04-07-2014
Message 19 of 20 (6,913 Views)

Re: How to access ALM data using REST API

 HI,

 

Is there a way where we can create a test set using the HP ALM Rest API.

 

Also executing the Rest APi using rest client in firefox. Im getting the following error msg

 

  1. Status Code: 401 Authentication failed. Browser based integrations - to login append '?login-form-required=y to the url you tried to access.
  2. Cache-Control: must-revalidate,no-cache,no-store
  3. Content-Length: 1662
  4. Content-Type: text/html;charset=ISO-8859-1
  5. Date: Mon, 07 Apr 2014 19:10:34 GMT
  6. Server: Jetty(7.5.4.v20111024)
  7. WWW-Authenticate: LWSSO realm=http://XXXXXXXXXX/qcbin/authentication-point

 

please suggest!!

 

Thanks

Keerthi.


Pradeep0905 wrote:
There are different ways (3 i guess) to authenticate into QC using REST. I'm using basic authentication and never tried web authentication as above. The basic concept is that when you authorize, a token cookie will be returned. Use this token cookie to perform an operation, which will return a session cookie and you need to use this session cookie on subsequent operations. On each operation a new session cookie will be returned. This is how session is managed in QC while using REST.

See if cookies are properly set.

 

Please use plain text.
Occasional Visitor
Jeyaps
Posts: 1
Registered: ‎05-06-2014
Message 20 of 20 (5,863 Views)

Re: How to access ALM data using REST API

Hi All,

 

Does the given ALM REST API works with LAB Management as well? I am trying to generate a report on hourly basis to get the list of timelots and active test runs from lab management portal. Can i achive this via ALM REST API? or Is there any other way to generate such a report? Any help/pointers will be really helpful.

 

Thanks.

 

 

Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation