Call to Rally API v2.0 not returning consistent re

2019-08-12 09:15发布

问题:

We're trying to use the Rally REST API v2.0 to extract data from Rally and bring it into a local database for further internal analysis. Initially, I make this call to get back the JSON with all the projects I want to enumerate through:

https://rally1.rallydev.com/slm/webservice/v2.0/workspace/17200849689

and in the JSON I get back

...
"Projects":{
         "_rallyAPIMajor":"2",
         "_rallyAPIMinor":"0",
         "_ref":"https://rally1.rallydev.com/slm/webservice/v2.0/Workspace/17200849689/Projects",
         "_type":"Project",
         "Count":36
      },
...

So my assumption is there should be 36 projects for me to go through, which I can access via the reference included above.

However, I then subsequently make a call using the URL above and appending an orderby clause, start index and pagesize based on the content. In effect .../17200849689/Projects?orderby=CreationDate&start=1&pagesize=20

Problem is, I don't get back 20 of the records. I get 16. It sort of seems like start should be zero based (which seems like it'd explain why I get back 16 records with a pagesize of 20), but if I call the above with start=0 (which isn't what the API reference indicates anyway), I still only get back 16 records.

In addition, the resulting JSON from the call disagrees with the record count. I get this back. Which indicates 56 records, not 36. I've gone and hand counted the number of projects via the website and arrived at 36 as well.

{
   "QueryResult":{
      "_rallyAPIMajor":"2",
      "_rallyAPIMinor":"0",
      "Errors":[

      ],
      "Warnings":[

      ],
      "TotalResultCount":56,
      "StartIndex":1,
      "PageSize":20,
...

Am I misunderstanding how start and pagesize work in my example call? Thanks in advance for any input/suggestions!

回答1:

The start index for queries begins at 1. The default is 1. Example: start=1

Max pagesize is 200. Default pagesize is 20. Try an endpoint with pagesize 200 without indicating start, e.g.

https://rally1.rallydev.com/slm/webservice/v2.0/workspace/12345/projects?pagesize=200

Other potential factors:

  • your permissions. What permission level does this user have, e.g. administrator, regular user?
  • closed projects are not returned by WS API. If you do not filter out closed projects in UI you will have more projects showing in UI than returned by WS API.

The issue with the closed projects is as follows: A project query (State = Closed) will return 0 results:

https://rally1.rallydev.com/slm/webservice/v2.0/project?workspace=https://rally1.rallydev.com/slm/webservice/v2.0/workspace/12345&query=(State%20%3D%20Closed)

but this endpoint:

https://rally1.rallydev.com/slm/webservice/v2.0/workspace/12345/projects

will return closed projects if a user has access to them. It depends on the timing: if the user was given access to a project while it was open, and it was closed afterwords, the workspace/12345/projects endpoint is expected to return open and closed projects data. If a project was closed before a user's access to various projects in a given workspace is being set, this project does not even appear in the UI to grant the user access to it. However, the workspace/12345/projects endpoint will demonstrate a discrepancy similar to the one you noticed. The totalresultcount will show total number of projects in the workspace, but the data (the number of project json objects returnted) will depend on the actual number of projects to which the user has access.



标签: json rest rally