Getting Started With Power BI API (Set Up, Configuration, Examples)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey howson guys in this video we're going to learn how to use microsoft power bi api in python so using power bi res api will be able to do quite many things and we can manage our power bi content performance operations and embedded power bi content and these are some of the information related to the power bi api and i'll post all the links that i'll be using in the description below on the left are some of the features that we can access via the api and for example if we go into data says category we can do things like delete a data set get a data set and i'll cover other features that i think are useful in future videos but for now i want to show you how to set up the api and how to connect to the endpoint i want to go to the register and azure ad application to sway power bis page on this page you can find the instruction below which is going to take you to each step but i feel like the instruction is a little bit too confusing and because there are a couple steps i feel like uh the documentation is missing all right so anyway uh let's go back to the top all right so i want to uh scroll to resident azure ad app section now click on one of these tabs then click on power bi app registration tool and that takes you to this setup your power bi embedding environment page depending on your use case if a developer or if you are developing a report for a customer then you will choose embedded for your customers by assistant admin that work for a company they will choose embedded for your organization and since i'm a developer i'm going to click on embedded for your customers all right so for step one you want to sign in to your account and i'll try they did then click on next now i want to create app now give your app a name and i'll name this app power bi u70 then i want to choose the permissions that i want to grant to this app and for demonstration purpose i'm going to select all then click on register all right so we have officially created the app now step two is optional do you want to create a new workspace to uh specifically to work with the api i'm going to say yes then i'm going to give this workspace a name now let's call this workspace power bi yosemite workspace and you have a typo step 4 is also optional do you have an existing power report that you want to upload to the workspace from step 3 and for this exercise i'm going to choose sample power bi report then click on import and the last step which is going to be step 5 is the most important step which is to grant permission to the app and make sure that you concern everything then click on accept now we have officially finished setting up the app from this app.powerbi.com instruction page and here we have the workspace id report id and application id you can also download a simple application which i've never done this before but i'm going to skip the downloading all right so i want to go into my address portal and you can go to portal.azure.com in the search field you want to search for app registrations and click on app registrations so by default it's going to show you the app that you own but want to choose all applications and they'll display all the applications that you have access to and here's the power bi 70 app that we just created now click into the app all right so a couple of things on the left-hand side want to go into authentication and scroll towards the bottom under the implicit grant and hybrid flows and make sure that you check the access tokens and also make sure that you set the allow public client flows to yes and save the settings all right so just in case if you want to modify the api permissions you can go into the app and go to api permissions and here you can add or remove different permission set all right so we have officially finished setting uh the application now we can write the script to connect to power bi api service alright so here i'm going to create a blank script i'll name the script power underscore bi demo one let me open my vs code from the import statement here let me increase the font size i'm going to import the requestes library and to generate the access token make sure that you install the msl or library and you can use the command pip install ms al and i forgot the name of the library but if you do a quick google search the msl library is the microsoft authentication library that you need to use to verify your account i'm going to import the oops i'm going to import the msl library now going back to my app i'm going to click on overview on the top are some of the ids assigned to the app and we need to grab the application id also known as client id and i'll copy the id to my script i'll name this as app id also copy the directory id also known as the tenant id and i'll name the variable tendon id so when we are connecting to power bi api we need to provide our username and password to verify our account and i save my username and my password you know python script and let me just copy paste over and i'm going to import my username and password now i want to go back to the app and if i click on endpoints i want to grab on the endpoint so it doesn't matter which endpoint that you copied basically we're going to do the everything beyond this login.microsoftonline.com so this is going to be the base url i'm going to name this as authority url concurrently with the tenant id they'll need to supply the scopes and for power bi api we can simply use this scope called https analysis windows.net slash power bi slash api default so we can simply provide the single scope to reference every single permission set that we assigned to the app and to connect to power bi api uh it's a two-step process the first step is we need to generate the token id and the second step is we're going to take the token id and use that to make a class code all right so it's going to be step one generate power bi access token from the msl library go on to reference the public client application class i will name the output client i'm going to assign the app id oops and the adore trl to the authority parameter and to generate the access token from the client object we want to insert the acquire token by username password method and we're going to supply our username password and scopes i'm going to run this code block by itself oh so you have a typeless thing let me delete this line here right so if i print the response option it's going to gives me invalid grant so to solve this issue i want to go back to microsoft address dashboard on the top you want to search for azure active directory go into the azure active directory then to scroll down to properties and the reason why we're getting the air is because a microsoft azure by default has multiple layers of security settings like enabled and i want to change the security setting by clicking on manage security defaults and i want to disable the security defaults and here we can implement or secure the protocol but for now i'm going to choose the first option and save all right so if i go back to my python script now if i recreate my response option and this time i'm able to generate the access token successfully all right so from the response output there are a couple things we have if i print the keys the access token key is going to contain the ssid and we can also print the scopes that this app has access to so i can print response providing the key and these are the scopes or permission sets that this application is using for this case i'm simply only interested in the access key so i'm going to create a variable called ssid in phone response option that gets onto reference access token key to create the tokens id all right so that's going to be step one and step two is to make a simple api code to the power api service now going back to the documentation so at this point we can basically make an api code to different power bi api services right so i'm going to show you one simple script to print my workspace i'm going to create the endpoint first and it's going to be https api.powerbi.com and right now we are still on version one so it's going to be v1.0 and the component name is going to be my org slash oops so here i'm going to create my headers we need to assign the access token or ssid to the authorization parameter and i'll make this as fstring they'll need to type bill space followed by the access token and to make the request code from questions.get i'm going to insert the endpoint plus the headers i'll name the output response request and i'll run this code block right so if i print the response option oh it should be a response request response and it's going to turn status code 200. here let me print status code all right so here i want to insert condition if the status code is equals to 200 then print the json response and found the response i can tell that based on this endpoint the api code is going to return all my workspaces for my power bi account if i look at my workspaces uh let's do this here um let's name this as a result for item in resell on supreme actually uh this should be values because the values key contain the actual content and it should be singular right so for item in result giving the value key i want to print double space name and looking at the output these are all my workspaces are currently available in my power bi account all right so this is going to be ifs i'm going to cover in this video and hopefully you guys found this video useful in the swiss see you guys watching i'll see you guys in the next video
Info
Channel: JJ Power BI
Views: 35,014
Rating: undefined out of 5
Keywords: Power BI, Power BI API, Power BI Rest API, Power BI Automation
Id: APj3MFt2w5I
Channel Id: undefined
Length: 17min 10sec (1030 seconds)
Published: Wed Apr 06 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.