Forum Discussion
Power Query REST API with Cookies
- 5 years ago
I ended up solving my own problem with a Python workaround.
The API documentation included some Python code which I then modified slightly to produce the results I needed.
I setup a new query using the Python Script connector with the code below as the source:
from pip._vendor import requests import pandas as pd headers = {'Content-Type': 'application/x-www-form-urlencoded'} s = requests.Session() # Put your username and password username = 'login' password = 'password' data = 'login=' + username + '&apiKey=' + password url = "https://app.siliconexpert.com/ProductAPI/search/authenticateUser" r = s.post(url, data=data, headers=headers) # default is fmt=json data = 'fmt=xml&partNumber=[{"partNumber":"bav99wt"}]' url = "https://app.siliconexpert.com/ProductAPI/search/listPartSearch" r = s.post(url, data=data, headers=headers) df = pd.DataFrame(r) print(df)This returned a series of rows which I then converted into a single text field using PQ, then parsed into XML & generated the data I needed.
I then edited the code to insert Power Query parameters for the username, password and part number, then converted this to a function and applied it against my data set of part numbers as an invoked function.
Thanks for your help. I hope this helps someone else in future!
Jeff
Hi JeffRobson
Remove the credential in the Data Source Setting and connect to api again by this code.
I think you can try to authenicate by access token.
For reference:
Using a REST API as a data source
Using a REST API as a data source - POST Method Only
Video: Get access token and then connect to Rest API in Power Query
https://www.youtube.com/watch?v=N8qYRSqRz84
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.