将Clockify数据加载到Power BI

时间:2019-12-19 05:07:31

标签: api powerbi clockify

我有一个Power BI报告,该报告基于Clockify的数据。到目前为止,我不得不从clockify下载详细的报告,以便能够在Power BI中查看最新数据。我想摆脱此手动步骤,并使用API​​直接连接到Clockify中存储的数据。

我当前正在加载以下M代码:

let
    Query1 = let
Source = Json.Document(Web.Contents("https://api.clockify.me/api/workspaces/",
[Headers=[#"x-api-key"="xxxxxxxxxxx"]])),
messages = Source[messages]
in
Source

This leads to a Record in Power Query which I can then turn into a table

但是,当我展开表格时,我只会获得有关Clockify工作区的信息,而不会获得记录的时间。我希望直接在Power BI中获得详细报告中的所有信息。希望有人能帮忙。干杯!

1 个答案:

答案 0 :(得分:0)

我复制了您的查询,但我认为您所命中的端点没有所需的信息。您必须在API文档中进行搜索。

无论如何,这是用于扩展该端点中所有内容的M代码,请查看其是否有用:

let
    Query1 = 
    let
        Source = Json.Document(Web.Contents("https://api.clockify.me/api/workspaces/",
            [Headers=[#"x-api-key"="YOUR-API-KEY"]])),
        #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
        #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"id", "name", "hourlyRate", "memberships", "workspaceSettings"}, {"id", "name", "hourlyRate", "memberships", "workspaceSettings"}),
        #"Expanded workspaceSettings" = Table.ExpandRecordColumn(#"Expanded Column1", "workspaceSettings", {"timeRoundingInReports", "onlyAdminsSeeBillableRates", "onlyAdminsCreateProject", "onlyAdminsSeeDashboard", "defaultBillableProjects", "isProjectPublicByDefault", "lockTimeEntries", "round", "projectFavorites", "canSeeTimeSheet", "projectPickerSpecialFilter", "forceProjects", "forceTasks", "forceTags", "forceDescription", "onlyAdminsSeeAllTimeEntries", "onlyAdminsSeePublicProjectsEntries", "trackTimeDownToSecond", "projectGroupingLabel", "adminOnlyPages", "automaticLock", "onlyAdminsCreateTag"}, {"timeRoundingInReports", "onlyAdminsSeeBillableRates", "onlyAdminsCreateProject", "onlyAdminsSeeDashboard", "defaultBillableProjects", "isProjectPublicByDefault", "lockTimeEntries", "round", "projectFavorites", "canSeeTimeSheet", "projectPickerSpecialFilter", "forceProjects", "forceTasks", "forceTags", "forceDescription", "onlyAdminsSeeAllTimeEntries", "onlyAdminsSeePublicProjectsEntries", "trackTimeDownToSecond", "projectGroupingLabel", "adminOnlyPages", "automaticLock", "onlyAdminsCreateTag"}),
        #"Expanded memberships" = Table.ExpandListColumn(#"Expanded workspaceSettings", "memberships"),
        #"Expanded memberships1" = Table.ExpandRecordColumn(#"Expanded memberships", "memberships", {"userId", "hourlyRate", "targetId", "membershipType", "membershipStatus"}, {"userId", "hourlyRate.1", "targetId", "membershipType", "membershipStatus"}),
        #"Expanded hourlyRate" = Table.ExpandRecordColumn(#"Expanded memberships1", "hourlyRate", {"amount", "currency"}, {"amount", "currency"}),
        #"Expanded round" = Table.ExpandRecordColumn(#"Expanded hourlyRate", "round", {"round", "minutes"}, {"round.1", "minutes"}),
        #"Expanded adminOnlyPages" = Table.ExpandListColumn(#"Expanded round", "adminOnlyPages")
    in
        #"Expanded adminOnlyPages"
in 
    Query1

如果您不使用Postman和Fiddler,我建议您使用它来测试端点并检查响应。