Forum Discussion

smpa01's avatar
smpa01
Community Champion
5 years ago
Solved

Running Rest API in Power query on each object

Ref - https://docs.microsoft.com/en-us/rest/api/power-bi/   GET https://api.powerbi.com/v1.0/myorg/groups/{groupId}/dataflows  If I use the above in web connector in a poewer query, gives me all t...
  • v-jingzhang's avatar
    5 years ago

    Hi smpa01 

     

    Based on my test, we don't need to run separate queries with generating separate Bearer tokens. Below are my codes:

     

    Custom function: GetDatasources

    (dataflowId as text) =>
    let
        Source = Json.Document(Web.Contents("https://api.powerbi.com/v1.0/myorg/groups/xxxxgroupidxxxx/dataflows/"&dataflowId&"/datasources", [Headers=[Authorization="Bearer xxxxxxtokenxxxxx"]])),
        #"Converted to Table" = Table.FromRecords({Source}),
        #"Expanded value" = Table.ExpandListColumn(#"Converted to Table", "value"),
        #"Changed Type" = Table.TransformColumnTypes(#"Expanded value",{{"@odata.context", type text}, {"value", type any}})
    in
        #"Changed Type"

     

    Result query

    let
        Source = Json.Document(Web.Contents("https://api.powerbi.com/v1.0/myorg/groups/xxxxxxgroupidxxxx/dataflows", [Headers=[Authorization="Bearer xxxxxxxxxtokenxxxxxxxxxxx"]])),
        #"Converted to Table" = Table.FromRecords({Source}),
        #"Expanded value" = Table.ExpandListColumn(#"Converted to Table", "value"),
        #"Expanded value1" = Table.ExpandRecordColumn(#"Expanded value", "value", {"objectId", "name", "description", "configuredBy", "users"}, {"value.objectId", "value.name", "value.description", "value.configuredBy", "value.users"}),
        #"Changed Type" = Table.TransformColumnTypes(#"Expanded value1",{{"@odata.context", type text}, {"value.objectId", type text}, {"value.name", type text}, {"value.description", type any}, {"value.configuredBy", type text}, {"value.users", type any}}),
        #"Removed Other Columns" = Table.SelectColumns(#"Changed Type",{"value.objectId", "value.name"}),
        #"Invoked Custom Function" = Table.AddColumn(#"Removed Other Columns", "datasources", each GetDatasources([value.objectId]))
    in
        #"Invoked Custom Function"

     

    Result

     

    Regards,
    Community Support Team _ Jing
    If this post helps, please Accept it as the solution to help other members find it.