Why is this foreach loop stopping early?

2019-09-16 11:32发布

问题:

I am trying to pull project information from the AtTask/WorkFront site. The foreach loop that I am using stops looping at 100 projects every time.

JToken projects = client.Search(ObjCode.PROJECT, new { groupID = userGroupID });
foreach (var j in projects["data"].Children())
{
    Console.WriteLine("# " + counter + " Name: {0}", j.Value<string>("name")); 
    counter++;
}

This produces names just as I need it to, except that the loop always stops short. The code for this loop came directly from the WorkFront developer site (https://developers.workfront.com/api-docs/code-samples/).

Is this caused by the WorkFront API having a call limit or is there a mistake in the code? What can I do to fix this issue?

回答1:

From the documentation:

Default Number of Results 100 If no limit is specified in the query filter (ie, $$LIMIT), the result will contain no more than 100 primary objects. See the example below for instructions on how to use the $$LIMIT in your query filter.



回答2:

Via the WorkFront docs...

If no limit is specified in the query filter (ie, $$LIMIT), the result will contain no more than 100 primary objects. See the example below for instructions on how to use the $$LIMIT in your query filter.

https://developers.workfront.com/api-docs/#Guidelines