通过Power Query访问完整的Clockify保存的报告

时间:2019-07-02 13:51:32

标签: powerquery clockify

基于亚历克斯(Alex)的问题(以及对此的自己的回答),here与保存的时钟报告已建立联系,该报告工作了一段时间没有出现问题。但是,最近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”参数被完全忽略...

1 个答案:

答案 0 :(得分:0)

我在吠错树... 事实证明,无法避免已保存报告中的分页,并且count参数没有任何作用。该API正在开发中,因此可能会发生类似的变化。 相反,时钟支持建议改用POST /workspaces/{workspaceId}/reports/summary/,它需要request主体中的一些参数。示例:

{
  "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/