Cross-project time-record filtering using Active Collab 5 API

两盒软妹~` 提交于 2019-11-28 09:25:08

问题


For Active Collab team watching this tag.

I am working on a project that uses new Active Collab 5 API, I am having performance issue trying to run reports.

Example I try to build reports on date-range, and currently to achieve that I need to first run a call to get all projects.

Followed by a loop with this call:

API::get('/projects/'.$id.'/time-records/filtered-by-date?' . http_build_query(['from' => $from, 'to' => $to]))

However we have a large number of projects, in addition to high number of active projects we also need to filter Archived projects as well to get correct reports for billing.

Now I work with around 1500 projects in AC.

So I need to make 1500 API calls which takes a huge performance hit. Is there a way that you can possibly build something that would work along these lines.

API::get(/timerecords/filter-by-date); 

with a possible passed parameter that will say (all, active, complited) project state.

Please let me know what you can do or if I have missed something in your documentation that already does this.

Thanks


回答1:


What you need here is not a request that goes through all projects one by one, but a request that it tailored for cross-project reporting. Active Collab 5 has just the right API endpoint for that - /reports/run.

As an example, you can use this command to query time records and expenses from all active projects that were tracked today:

curl -H "X-Angie-AuthApiToken: YOUR-API-TOKEN" "http://your.activecollab.com/api/v1/reports/run?type=TrackingFilter&project_filter=active&tracked_on_filter=today"

Notice the route (/reports/run) and query arguments:

  1. type - specify type of the report, in this case time and expense tracking report,
  2. project_filter - specify project filter. Apart from active, other useful values of this filter are completed (for completed projects), selected_1,2,3,4 (selected projects with a list of project ID-s), client_1,2,3,4 (projects for clients with the given ID-s), category_1,2,3,4 (projects in categories with the given ID-s),
  3. tracked_on_filter - filter by the date when records were tracked. To target a particular date use selected_date_YYYY-MM-DD and to target a date range use selected_range_YYYY-MM-DD:YYYY-MM-DD.
  4. tracked_by_filter - filter by who tracked the time. It can have various values, like anybody, logged_user, selected_1,2,3.

To list only time records, set type_filter to time (or to expenses if you want only expenses to be listed).



来源:https://stackoverflow.com/questions/33790093/cross-project-time-record-filtering-using-active-collab-5-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!