Skip to main content
Showing results for 
Search instead for 
Did you mean: 

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Frequent Visitor

power BI rest API with python

I am new to power BI rest APIs need some help on power BI APIs with python.

I have a requirement to use power BI rest API with python script.

As part of the requirement I have to create a new dataset using API calls from python and then post data from a json/csv file into the newly created dataset using API calls from python. 

Can someone please share some documentation/threads around these topics


I can create a dataset with help of python and rest API calls but can't insert data from a json/csv file into newly created dataset is 

Below is the code for creating a dataset


import adal
import pandas as pd
import requests
import json
from pypowerbi.dataset import Column, Table, Dataset
from pypowerbi.client import PowerBIClient

# you might need to change these, but i doubt it 

# change these to your credentials

# Authenticate using adal
context = adal.AuthenticationContext(authority=authority_url,

# get your authentication token
token = context.acquire_token_with_username_password(resource=resource_url,

# create your powerbi api client
client = PowerBIClient.get_client_with_username_password(client_id=client_id, username=username, password=password)

# create your columns
columns = []
columns.append(Column(name='CHNG', data_type='Int64'))
columns.append(Column(name='CUMULATIVE', data_type='Int64'))
columns.append(Column(name='S', data_type='Int64'))
columns.append(Column(name='VALUE', data_type='Int64'))
columns.append(Column(name='COUNTY', data_type='string'))
columns.append(Column(name='METRIC', data_type='string'))
columns.append(Column(name='SESSIONID', data_type='datetime'))

# create your tables
tables = []
tables.append(Table(name='contacts_daily_chng', columns=columns))

# create your dataset
dataset = Dataset(name='apidemo2', tables=tables)

# post your dataset!


Hi @lok ,


Try to use Power BI REST API to push data from Json file into a Power BI dataset,check the reference below:



Best Regards,

Did I answer your question? Mark my post as a solution!

View solution in original post

New Member

Given information is very informative.


Could you please also suggest if the same approach can be used to GET data from PowerBI REST API and in this steps i need to load GET response into JSON or db table.


Appreciate your response in advance

Super User
Super User

@lok , I am not fully clear.

If you need call power bi API to python?


You need to power bi rest APIS


Do you need to call Python in power bi?

How to make Python work with Power BI:


These is limit what you can use for visual

Thanks for your reply!


This is my actual requirement

1. Creating an empty dataset using PBI API calls with python

2. Inseting some data from any file type like (json, csv, text etc..) into the newly created dataset with help of PBI API calls and python

3. Append the existing data with help of PBI API calls and python


I did all above steps with help of postman, and now we are trying to implement the same with help of python.


I did see the video you shared, I can create a table using python script from power BI desktop. But my requirement is using API calls need to create datasets and Insert data. 

Hi @lok ,


Try to use Power BI REST API to push data from Json file into a Power BI dataset,check the reference below:



Best Regards,

Did I answer your question? Mark my post as a solution!

Helpful resources

Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors