Python Script to Power Query

Hi, I have managed to export a Postman API to Python and managed to run this in Python to obtain data. I now need to convert this python script into M Language to avoid having to use gateways when publishing to PBI Service as otherwise the dataset will not refresh but I can’t find any useful info on how to do this, so any help would be appreciated, thanks.

Python script - sensitive data replaced with x:

import pandas as pd
import requests
import json

url = “https://xxxxxxxxxx.execute-api.eu-west-2.amazonaws.com/Live/getcontracts

payload={}
headers = {
‘authorizationToken’: ‘xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx’,
‘user_group_type_id’: ‘8’
}

response = requests.request(“GET”, url, headers=headers, data=payload)

my_string = response.content.decode(‘utf-8’)
data = json.loads (my_string)
df = pd.DataFrame (data)
print(df)

bumping this post

@BCS - sorry for delay - I hoped you get much better answer.
I try to search for it - I found only this:

So I used another approach.

Maybe someone has other practical information/ ideas …

…or something changed in meantime

Good luck.

P.s. You need to be careful when you use Python within PBI since not all packages are supported

1 Like

Thanks @mspanic for your reply.

I knew about the personal gateway and i’d also need python on the computer ruinning the API call or use a virtual python environment these are the reasons i wanted to move away from Python and use M code for the API call but i couldn’t work out how to convery the python code to M code.

Thanks for your post