Forum Discussion
Rest Power BI API - Get information from users, data sources, tables and fields, and so on.
- 4 years ago
Hi Syndicate_Admin ,
I find the Power BI API (Beta) custom connector that you can use to call the Power BI Rest API without writing code.
a) Get the .mez file from this link: https://github.com/migueesc123/PowerBIRESTAPI/raw/master/Power%20BI%20API.mez
b) Place the connector. mez file in the [Documents]\Power BI Desktop\Custom Connectors folder. If this folder does not exist, create it.
In my example, the full path is “C:\Users\Administrator\Documents\Power BI Desktop\Custom Connectors folder”.
c) In Power BI Desktop, select File > Options and settings > Options > Security. Under Data Extensions, select (Not Recommended) Allow any extension to load without validation or warning. Click OK, and restart Power BI Desktop.
d) Launch Power BI Desktop and find the Power BI API (Beta) connector.
If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Syndicate_Admin ,
I wrote some code to get the metadata for the workspace. The logic is:
1. Obtain dynamic access token.
() =>
let
body = "grant_type=password&&resource=https://analysis.windows.net/powerbi/api&&response_type=code&&client_id=xxxxxxxxx&&client_secret=xxxxxxxxx&&username=xxxxxxxxx&&password=xxxxxxx",
Data=Json.Document(Web.Contents("https://login.microsoftonline.com/common/oauth2/token/",
[Headers=[#"Content-Type"="application/x-www-form-urlencoded"], Content=Text.ToBinary(body)])),
access_token = Data[access_token]
in
access_token
2. Call Groups GetGroupsAsAdmin api to return the list of workspaces and then merge those IDs.
3. Call WorkspaceInfo PostWorkspaceInfo api and reference the workspace IDs from the previous step and return the scan ID.
() =>
let
Source = Json.Document(Web.Contents("https://api.powerbi.com/v1.0/myorg/admin/groups?$top=3", [Headers=[Authorization="Bearer "& GetAccessToken() ]])),
value = Source[value],
#"Converted to Table" = Table.FromList(value, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"id", "isReadOnly", "isOnDedicatedCapacity", "capacityMigrationStatus", "description", "type", "state", "name"}, {"id", "isReadOnly", "isOnDedicatedCapacity", "capacityMigrationStatus", "description", "type", "state", "name"}),
GroupID = """" & Text.Combine(#"Expanded Column1"[id],""",""") & """",
body = "{ ""workspaces"": [ " & GroupID & " ]}",
Data=Json.Document(Web.Contents("https://api.powerbi.com/v1.0/myorg/admin/workspaces/getInfo?datasourceDetails=True&datasetSchema=True&datasetExpressions=True&getArtifactUsers=True",
[Headers=[Authorization="Bearer "& GetAccessToken(),#"Content-Type"="application/json"], Content=Text.ToBinary(body)])),
scanID = Data[id]
in
scanID
4. Call WorkspaceInfo GetScanStatus and reference the scan ID from the previous step. if the status value of the response is "Succeeded", proceed to the next step.
() =>
let
Data=Json.Document(Web.Contents("https://api.powerbi.com/v1.0/myorg/admin/workspaces/scanStatus/" & PostWorkspaceInfo(),
[Headers=[Authorization="Bearer "& GetAccessToken()]])),
Scan_ID = if Data[status] = "Succeeded" then Data[id] else "Scan failed"
in
Scan_ID
4. Call WorkspaceInfo GetScanResult to return the metadata of the workspaces.
let
Source = Json.Document(Web.Contents("https://api.powerbi.com/v1.0/myorg/admin/workspaces/scanResult/" & GetScanStatus(), [Headers=[Authorization="Bearer "& GetAccessToken() ]]))
in
Source
If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi,
I tried your code and it`s alright on Power Query, when I click on Close & Apply i get Error 400 - Bad Request on ScanStatus geting scan failed message. Could you help me??
v-kkf-msft can you help me???