Power BI - 使用nextLink调用Azure API(下一页)

时间:2018-02-13 16:19:00

标签: azure powerbi azure-api-management

道歉,我是Power BI的新手。我使用Power BI来调用Azure API,该API将列出我的订阅中的所有VM,但是它只会在显示nextLink之前显示前50个。

以下是我正在呼叫的API;

https://management.azure.com/subscriptions/< subscription >/providers/Microsoft.Compute/virtualMachines?api-version=2017-12-01

我已经看到其他网页和论坛遇到类似问题(例如Microsoft API),但没有看到Azure API。我搞砸了他们的修复,但无法弄清楚如何将它应用到我的。

他们的代码;

let
GetUserInfo = (Path)=>
let
     Source = Json.Document(Web.Contents(Path)),
     LL= @Source[value], 
     result = try @LL & @GetUserInfo(Source[#"@odata.nextLink"]) otherwise @LL

in
result,
    Fullset = GetUserInfo("https://graph.microsoft.com/beta/users?$select=manager&$expand=manager"),
    #"Converted to Table" = Table.FromList(Fullset, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"id", "displayName", "manager"}, {"Column1.id", "Column1.displayName", "Column1.manager"}),
    #"Expanded Column1.manager" = Table.ExpandRecordColumn(#"Expanded Column1", "Column1.manager", {"id", "displayName"}, {"id", "displayName"}),
    #"Renamed Columns" = Table.RenameColumns(#"Expanded Column1.manager",{{"Column1.displayName", "Employee Full Name"}, {"Column1.id", "Employee Id"}, {"id", "Manager Id"}, {"displayName", "Manager Full name"}})
in
    #"Renamed Columns"

与我的一开始相比,我通过简单的网络链接连接了源码;

let
    Source = Json.Document(Web.Contents("https://management.azure.com/subscriptions/< subscription >/providers/Microsoft.Compute/virtualMachines?api-version=2017-12-01")),
    #"Converted to Table" = Record.ToTable(Source)
in
    #"Converted to Table"

如果我要调整它,我怀疑它看起来像这样;

let
GetUserInfo = (Path)=>
let
     Source = Json.Document(Web.Contents(Path)),
     LL= @Source[value], 
     result = try @LL & @GetUserInfo(Source[#"@odata.nextLink"]) otherwise @LL

in
result,
    Fullset = GetUserInfo("https://management.azure.com/subscriptions/< subscription >/providers/Microsoft.Compute/virtualMachines?api-version=2017-12-01"),
    #"Converted to Table" = Record.ToTable(Source)
in
    #"Converted to Table"

但是,单击“确定”后会出现以下错误提示;

Expression.Error: The name 'Source' wasn't recognized.  Make sure it's spelled correctly.

对此的任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:2)

对于任何有兴趣的人,这都是我最后做的感谢这个链接:

{{3}}

let
    iterations = 10,
    url = 
     "https://management.azure.com/subscriptions/< subscription >/providers/Microsoft.Compute/virtualMachines?api-version=2017-12-01",

    FnGetOnePage =
     (url) as record =>
      let
       Source = Json.Document(Web.Contents(url)),
       data = try Source[value] otherwise null,
       next = try Source[nextLink] otherwise null,
       res = [Data=data, Next=next]
      in
       res,

    GeneratedList =
     List.Generate(
      ()=>[i=0, res = FnGetOnePage(url)],
      each [i]<iterations and [res][Data]<>null,
      each [i=[i]+1, res = FnGetOnePage([res][Next])],
      each [res][Data])
    in
     GeneratedList
一整天的谷歌搜索头痛:S