How to get all the defects in Quality Center 11 by Restful API

2.5k views Asked by At

I use https://qcxxx.xxx.com:443/qcbin/rest/domains/{domain}/projects/{project}/defects but I can only get 100 defects. Actually there are many more than 100 defects. Why is this?

3

There are 3 answers

0
vitorueda On BEST ANSWER

You can pass some paramethers to "fix" it.

/defects?page-size=X&start-index=Y

X is the number of how many defects you can see at same page. Y is the number of how many defects you will "skip".

There are some limits that are setted in QC configuration.

0
jumps4fun On

You can also use:

/defects?page-size=max

This also has a limited amount of returns, but is a simple way of getting all of the results, as long as it doesn't exceed the set max page size. I don't remember the default max page size right now, but it is a few thousands. I also know it can be changed according to your needs, in settings. I've set mine to 5000.

UPDATE: from the API:

If the specified page-size is greater than the maximum page size, an exception is thrown. The maximum page size can be specified by the site parameter REST_API_MAX_PAGE_SIZE. If the site parameter is not defined, the maximum page size is 2000. The requested page size can be set equal to the maximum by specifying page-size=max.

0
Halim Saad-Rached On

Below is a c# function we used that returns the ids of all our hp alm/qc defects having attachments and using pagination in the rest api url.

public List<string> GetDefectIds()
{
    XmlNodeList nodeIds = null;
    int iteration = 0;
    List<string> returnIds = new List<string>();
    do
    {
        string queryString = "?fields=id&query={attachment['Y']}&page-size=" + Constant.ALM_DEFECTS_PAGE_SIZE.ToString() + "&start-index=" + (iteration++ * Constant.ALM_DEFECTS_PAGE_SIZE + 1).ToString();
        string url = _urlBase + "/rest/domains/" + _domain + "/projects/" + _project + "/defects" + queryString;
        WebRequest wrq = WebRequest.Create(url);
        wrq.Headers.Set(HttpRequestHeader.Cookie, _sessionCookie);
        WebResponse wrp = wrq.GetResponse();
        StreamReader reader = new StreamReader(wrp.GetResponseStream());
        string xmlString = reader.ReadToEnd();
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.LoadXml(xmlString);
        nodeIds = xmlDoc.SelectNodes("/Entities/Entity/Fields/Field/Value");
        foreach (XmlNode node in nodeIds)
        {
            returnIds.Add(node.InnerXml);
        }
        wrp.Close();
    }
    while (nodeIds?.Count > 0);
    return returnIds;
}

Variables starting with underscore are private class members and the alm page size constant is equal to 250.