The Suffrage

The thing I hate about Brian is that he has his days and if he is having a “ day “ then it is bad day for me . You never know if your’e going to even wake up and then you never know if you are going…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




PowerBI API call using Native app in Python

This is an article that talks about a very simple procedure to fetch information off PowerBI APIs. There are some very interesting material out there in community.powerbi.com and the rest of the internet. But I found that it would be good if I write about a scenario that I came across and didn't know what to do as I was new to solving a specific requirement.

The PowerBI Rest API documentation on Microsoft is the correct place to be when you want to know which APIs will you need for your specific requirement. In this article we will look at a very tiny requirement and how to solve it easily using a python script.

The requirement is to update an SQL table with the last run time of a specific report in a specific workspace in powerbi. Pretty simple I guess!

All we need to do is register a Native app on dev.powerbi.com. Link given below. You can describe what your app is for by giving it a name.

The below link was shared by a good friend on github when I was asking for help online. It has a very good documentation of exactly what information you need to build your script if you are either trying to embed a PowerBI report or if you want to just get some information using PowerBI API calls like me. Hence I will not repeat what they have already given in the link.

Before you start with python scripting, you need to ensure you have the python dependencies like adal, pyodbc and requests. The below code is in python 3.

Below you define the function that helps to generate the authorization

You can have multiple URLs if you need. You can put them in a list and loop through the list if you prefer.

Once you have appended the empty lists with the values you need like in this case if the refresh of the report completed and the time of completion.

Now you have created the connection instance to the database.

If you need to copy paste the code. You will need to take care of the indentation. Also ensure you give the right parameters.

Other wise, that is all. You have successfully called the PowerBI API and got the information you need and stored it in a database. Please post questions and corrections if any.

Add a comment

Related posts:

The story of a non working API Secret!

So I decided to join Medium and connect it to my WordPress blog with the “SNAP plugin from NEXT Scripts. All seemed great, I got my API client ID and my secret (neither of which you can copy and…

The Problem With Exchanges

Within the digital currency universe there exists two forms of medium of exchange: cryptocurrencies, which are either derived from (in the case of tokens) or a part of themselves (in the case of…

Land Of Migrants

Your deserved praises they sing from the yards Their eloquence swiftly raising the bright flag On you, chest up, into classrooms they march But it’s only a matter of time Before they feel wise, and…