首页 > 解决方案 > 通过 Power Query 访问完整的 Clockify 保存报告

问题描述

基于 Alex 的问题(以及对此的自己的回答)我已经与保存的 clockify 报告建立了联系,该报告在一段时间内没有问题。然而,最近clockify 在保存的报告中引入了分页,结果只有(最多)前50 个条目从报告中返回。

Clockify 支持已将我指向“计数”或“页面”作为可能的解决方案(“计数”(默认为 50)应指示返回条目的数量,“页面”应指示返回报告的页面)。不幸的是,我无法改变返回的内容。

= Json.Document(
        Web.Contents("api.clockify.me/api/reports/{my report}",
                     [Headers=    [ContentType="application/json",
                                   #"X-Api-Key"="{my API Key}",
                                   count="9999"                                  
                                   ]
                      ]                    
                    )
                )

上面的例子,我相信应该最多返回 9999 个条目,但实际上最多只返回 50 个。“count”参数完全被忽略了......

标签: powerqueryclockify

解决方案


我叫错了树...事实证明,无法避免保存的报告中的分页,并且 count 参数什么也不做。此 API 正在开发中,因此可能会发生此类更改。相反,clockify 支持建议使用instead,这需要在requestPOST /workspaces/{workspaceId}/reports/summary/的正文中使用一些参数。例子:

{
  "startDate": "2018-01-01T00:00:00.000Z",
  "endDate": "2018-12-31T23:59:59.999Z",
  "me": "false", (Options: "false", "true", "TEAM", "ME", "null")
  "userGroupIds": [],
  "userIds": [],
  "projectIds": [],
  "clientIds": [],
  "taskIds": [],
  "tagIds": [],
  "billable": "BOTH", (Options: "BOTH", "BILLABLE", "NOT_BILLABLE")
  "includeTimeEntries": "true",
  "zoomLevel": "week", (Options: "week", "month", "year")
  "description": "",
  "archived": "Active", (Options: "Active", "All", "Archived")
  "roundingOn": "false"
}

(我从clockify支持中获得了更多参数,但据我所知,目前它们没有任何区别。我在下面评论了它们。)

我让它在 Power Query 中工作:

let
 url="https://api.clockify.me/api/workspaces/{workspaceId}/reports/summary/",
    content ="{
      ""startDate"": ""2017-01-01T00:00:00.000Z"",
      ""endDate"": ""2025-12-31T23:59:59.999Z"",
      ""me"": ""false"", 
      ""userGroupIds"": [],
      ""userIds"": [],
      ""projectIds"": [],
      ""clientIds"": [],
      ""taskIds"": [],
      ""tagIds"": [],
      ""billable"": ""BOTH"", 
      ""includeTimeEntries"": ""true"",
      ""zoomLevel"": ""week"", 
      ""description"": """",
      ""archived"": ""Active"", 
      ""roundingOn"": ""false"",
      ""groupingOn"": ""false"" 
"/* ,
      ""groupedByDate"": ""false"",
      ""page"":0,
      ""count"":9999,
      ""sortDetailedBy"": ""timeAsc"" (Options: "description", "descriptionAsc", "userName", "userNameAsc", "duration", "durationAsc", "time", "timeAsc")
 */
       &" }",      
    Source = Json.Document(
                    Web.Contents(url,    [Headers=    [ #"X-Api-Key"="{yourAPIkey}"
                                                        ,ContentType="application/json"
                                                        ,#"Content-Type"="application/json"
                                                       ]
                                         ,Content=Text.ToBinary(content)
                                         ] 
                                 )
                             )
    in
        Source

(来源: https ://community.powerbi.com/t5/Desktop/How-to-add-body-into-Web-Contents/td-p/128996

https://eriksvensen.wordpress.com/2014/09/15/specifying-json-query-in-power-query-example-statistics-sweden/

进一步的发展:

https://www.thebiccountant.com/2018/06/05/easy-post-requests-with-power-bi-and-power-query-using-json-fromvalue/


推荐阅读