<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Power Query REST API with Cookies in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Power-Query-REST-API-with-Cookies/m-p/1992592#M30868</link>
    <description>&lt;P&gt;Thanks for your suggestions, Rico.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately, it seems the API I'm trying to connect to doesn't support access tokens. It seems to require the cookies created during the authorization process for each API call.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, the cURL code for a part number search is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;# 1) Creating a new directory (if not exists) to save cookies.
mkdir /tmp/siliconexpert
 
# 2) Creating a new file (if not exists) to save cookies.
touch /tmp/siliconexpert/cookies
 
# 3) Authentication (if not authenticated or session expired).
#   -d (Send specified data in POST request).
#   -X (The request method to use).
#   login (Your API username).
#   apiKey (Your API password).
curl -c /tmp/siliconexpert/cookies -d "login=my_username&amp;amp;apiKey=my_password" -X POST https://app.siliconexpert.com/ProductAPI/search/authenticateUser
 
# 4) Calling the API.
curl -b /tmp/siliconexpert/cookies -d "partNumber=[{\"partNumber\":\"bav99wt\"},{\"partNumber\":\"bav99\"}]&amp;amp;mode=beginwith&amp;amp;pageNumber=1&amp;amp;fmt=xml" -X POST https://app.siliconexpert.com/ProductAPI/search/listPartSearch&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.siliconexpert.com/apidocs/#list-part-search" target="_blank"&gt;https://www.siliconexpert.com/apidocs/#list-part-search&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately, I'm not sure how to capture the cookies then pass them to the subsequent calls.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I attempted the R solution to this detailed at&amp;nbsp;&lt;A href="https://community.powerbi.com/t5/Desktop/How-to-extract-http-response-header/m-p/452992" target="_blank" rel="noopener"&gt;https://community.powerbi.com/t5/Desktop/How-to-extract-http-response-header/m-p/452992&lt;/A&gt;&amp;nbsp;but there's something still not quite right as it still says I'm not authenticated &amp;amp; the tokens seem to fail.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you have any other ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Mon, 02 Aug 2021 09:24:20 GMT</pubDate>
    <dc:creator>JeffRobson</dc:creator>
    <dc:date>2021-08-02T09:24:20Z</dc:date>
    <item>
      <title>Power Query REST API with Cookies</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-Query-REST-API-with-Cookies/m-p/1989323#M30831</link>
      <description>&lt;P&gt;I'm trying to extract some data from a REST API service that uses cookies to store the authentication credentials.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;let
    Source = Json.Document(Web.Contents("https://app.siliconexpert.com/ProductAPI/search/authenticateUser?login=username&amp;amp;apiKey=password")),
    Status = Source[Status],  
    Source1 = Json.Document(Web.Contents("https://app.siliconexpert.com/ProductAPI/search/listPartSearch?partNumber=%5b%7b%22partNumber%22:%22" &amp;amp; PartNumber &amp;amp; "wt%22%7d,%7b%22partNumber%22:%22" &amp;amp; PartNumber &amp;amp; "%22%7d%5d&amp;amp;mode=beginwith&amp;amp;pageNumber=1")),
    Status1 = Source1[Status]
in
    Status1&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first call works fine, says I'm authenticated &amp;amp; sets 3 cookies on my machine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, the second call then says I'm not authenticated &amp;amp; fails.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've had a look through many articles on this subject but can't figure out how to capture the cookies then pass them back to the API so it knows I'm authenticated in subsequent queries.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone assist please?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;API documentation at&amp;nbsp;&lt;A href="https://www.siliconexpert.com/apidocs/" target="_blank" rel="noopener"&gt;https://www.siliconexpert.com/apidocs/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jul 2021 09:17:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-Query-REST-API-with-Cookies/m-p/1989323#M30831</guid>
      <dc:creator>JeffRobson</dc:creator>
      <dc:date>2021-07-30T09:17:42Z</dc:date>
    </item>
    <item>
      <title>Re: Power Query REST API with Cookies</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-Query-REST-API-with-Cookies/m-p/1992473#M30866</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/288877"&gt;@JeffRobson&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Remove the credential in the Data Source Setting and connect to api again by this code.&lt;/P&gt;
&lt;P&gt;I think you can try to authenicate by access token.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For reference:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.powerbi.com/t5/Power-Query/Using-a-REST-API-as-a-data-source/td-p/50400" target="_self"&gt;&lt;SPAN&gt;Using a REST API as a data source&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.powerbi.com/t5/Desktop/Using-a-REST-API-as-a-data-source-POST-Method-Only/m-p/244166" target="_self"&gt;&lt;SPAN&gt;Using a REST API as a data source - POST Method Only&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Video: Get access token and then connect to Rest API in Power Query&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 12.0pt;" lang="en-US"&gt;&lt;A href="https://www.youtube.com/watch?v=N8qYRSqRz84" target="_blank"&gt;https://www.youtube.com/watch?v=N8qYRSqRz84&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Best Regards,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Rico Zhou&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;If this post &lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider &lt;EM&gt;&lt;STRONG&gt;Accept it as the solution&lt;/STRONG&gt;&lt;/EM&gt; to help the other members find it more quickly.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Aug 2021 08:25:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-Query-REST-API-with-Cookies/m-p/1992473#M30866</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-08-02T08:25:13Z</dc:date>
    </item>
    <item>
      <title>Re: Power Query REST API with Cookies</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-Query-REST-API-with-Cookies/m-p/1992592#M30868</link>
      <description>&lt;P&gt;Thanks for your suggestions, Rico.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately, it seems the API I'm trying to connect to doesn't support access tokens. It seems to require the cookies created during the authorization process for each API call.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, the cURL code for a part number search is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;# 1) Creating a new directory (if not exists) to save cookies.
mkdir /tmp/siliconexpert
 
# 2) Creating a new file (if not exists) to save cookies.
touch /tmp/siliconexpert/cookies
 
# 3) Authentication (if not authenticated or session expired).
#   -d (Send specified data in POST request).
#   -X (The request method to use).
#   login (Your API username).
#   apiKey (Your API password).
curl -c /tmp/siliconexpert/cookies -d "login=my_username&amp;amp;apiKey=my_password" -X POST https://app.siliconexpert.com/ProductAPI/search/authenticateUser
 
# 4) Calling the API.
curl -b /tmp/siliconexpert/cookies -d "partNumber=[{\"partNumber\":\"bav99wt\"},{\"partNumber\":\"bav99\"}]&amp;amp;mode=beginwith&amp;amp;pageNumber=1&amp;amp;fmt=xml" -X POST https://app.siliconexpert.com/ProductAPI/search/listPartSearch&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.siliconexpert.com/apidocs/#list-part-search" target="_blank"&gt;https://www.siliconexpert.com/apidocs/#list-part-search&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately, I'm not sure how to capture the cookies then pass them to the subsequent calls.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I attempted the R solution to this detailed at&amp;nbsp;&lt;A href="https://community.powerbi.com/t5/Desktop/How-to-extract-http-response-header/m-p/452992" target="_blank" rel="noopener"&gt;https://community.powerbi.com/t5/Desktop/How-to-extract-http-response-header/m-p/452992&lt;/A&gt;&amp;nbsp;but there's something still not quite right as it still says I'm not authenticated &amp;amp; the tokens seem to fail.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you have any other ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 02 Aug 2021 09:24:20 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-Query-REST-API-with-Cookies/m-p/1992592#M30868</guid>
      <dc:creator>JeffRobson</dc:creator>
      <dc:date>2021-08-02T09:24:20Z</dc:date>
    </item>
    <item>
      <title>Re: Power Query REST API with Cookies</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-Query-REST-API-with-Cookies/m-p/1994806#M30886</link>
      <description>&lt;P&gt;I ended up solving my own problem with a Python workaround.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The API documentation included some Python code which I then modified slightly to produce the results I needed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I setup a new query using the Python Script connector with the code below as the source:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;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 + '&amp;amp;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&amp;amp;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)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This returned a series of rows which I then converted into a single text field using PQ, then parsed into XML &amp;amp; generated the data I needed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help. I hope this helps someone else in future!&lt;/P&gt;&lt;P&gt;Jeff&lt;/P&gt;</description>
      <pubDate>Tue, 03 Aug 2021 08:10:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-Query-REST-API-with-Cookies/m-p/1994806#M30886</guid>
      <dc:creator>JeffRobson</dc:creator>
      <dc:date>2021-08-03T08:10:06Z</dc:date>
    </item>
    <item>
      <title>Re: Power Query REST API with Cookies</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-Query-REST-API-with-Cookies/m-p/3205627#M42371</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this is giving SSL certficate verfiy fail issue, any ideas to resolve&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2023 17:58:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-Query-REST-API-with-Cookies/m-p/3205627#M42371</guid>
      <dc:creator>Dev_powerBi</dc:creator>
      <dc:date>2023-04-25T17:58:14Z</dc:date>
    </item>
  </channel>
</rss>

