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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Anonymous
Not applicable

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
client_id = 'XXXXXXXXXXXXXXXXXXXXX' 
username = 'XXXXXXXXXXXXXXXXXXXXXXXXX'
password = 'XXXXXXXXXXXXXXX'

# Authenticate using adal
context = adal.AuthenticationContext(authority=authority_url,
                                     validate_authority=True,
                                     api_version=None)

# get your authentication token
token = context.acquire_token_with_username_password(resource=resource_url,
                                                     client_id=client_id,
                                                     username=username,
                                                     password=password)

# 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!
client.datasets.post_dataset(dataset)

print(dataset.name)
1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

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

https://docs.microsoft.com/en-us/power-bi/developer/automation/walkthrough-push-data

 

 

Best Regards,
Kelly

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

View solution in original post

4 REPLIES 4
sauami
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

amitchandak
Super User
Super User

@Anonymous , I am not fully clear.

If you need call power bi API to python?

 

You need to power bi rest APIS

https://docs.microsoft.com/en-us/rest/api/power-bi/

 

Do you need to call Python in power bi?

How to make Python work with Power BI: https://youtu.be/5D0BkNsu5CM

 

These is limit what you can use for visual

https://powerbi.microsoft.com/en-us/blog/python-visualizations-in-power-bi-service/

Anonymous
Not applicable

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 @Anonymous ,

 

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

https://docs.microsoft.com/en-us/power-bi/developer/automation/walkthrough-push-data

 

 

Best Regards,
Kelly

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

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

July Newsletter

Fabric Community Update - July 2024

Find out what's new and trending in the Fabric Community.