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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
karthipowerbi
Regular Visitor

PUSH DATA Using Python's Request package - API Error 404

All,

 

I have registered my application and got the client id. Note, I have used 'Native' option while registration.

 

My requirement is to push data from python script.

 

I have tried with ADOL, it seems fine, but i tried with 'request' package & called PowerBI's API

to push the data into my workspace.

 


from datetime import datetime
from random import randint
import time

import requests
import json
with open('sample.json') as json_file:
json_data = json.load(json_file)
print(json_data)
url = 'https://login.microsoftonline.com/common/oauth2/token'
data = {
'grant_type': 'password',
'scope': 'https://api.powerbi.com',
'resource': 'https://analysis.windows.net/powerbi/api',
'client_id': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'username': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'password': 'xxxxxxx'
}

r = requests.post(url, data=data)
access_token = r.json().get('access_token')
print(access_token)

header = {'Authorization': 'Bearer {}'.format(access_token), 'Content-Type': 'application/json', }

api = requests.put('https://api.powerbi.com/v1.0/myorg/datasets?defaultRetentionPolicy=basicFIFO', headers=header, json=json_data)

print("API Result: {}\n{}\n".format(api.status_code, api.text))


# r = requests.post('https://api.PowerBI.com/v1.0/myorg/datasets', json.dumps(data), verify = False)

 

Error Message:

 

API Result: 404
{
"error":{
"code":"","message":"No HTTP resource was found that matches the request URI 'http://api.powerbi.com/v1.0/myorg/datasets?defaultRetentionPolicy=basicFIFO'."
}
}

 

I just used the same json body file given in the powerbi reference site.

 

I created the dataset by using below the link successfully.

 

https://docs.microsoft.com/en-us/rest/api/power-bi/pushdatasets/datasets_postdataset#code-try-0

 

Note: I am able to view the list of Datasets by using the below API.

 

api = requests.get('https://api.powerbi.com/v1.0/myorg/datasets', headers=header)
print("API Result: {}\n{}\n".format(api.status_code, api.text))

 

this API is working, but the POST method to push the dataset is not working. How? what is the missing piece here?

 

any help would be really appreciable!

3 REPLIES 3
karthipowerbi
Regular Visitor

any inputs ?

Team,

 

Please let me know do i need to get in touch with some support team for this.

any thoughts?

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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