<?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: Connect to API with token that changes in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Connect-to-API-with-token-that-changes/m-p/2500501#M35959</link>
    <description>&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;HI&amp;nbsp;@Anonymous&lt;/a&gt;,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;In fact, you can also use post requests in the power query web connector. You need to add the request contents to the header or body(this is based on your API settings) and attached them to the data connector.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;let
    rootURL = "app.xxx.com",
    secretId = xxxxx,
    GetJson =
        Web.Contents(
            rootURL,
            [
                Headers = [
                    #"Authorization" = "Basic " &amp;amp; secretId,
                    #"Content-Type" = "application/json"
                ],
                Content = Text.ToBinary("grant_type=client_credentials")
            ]
        ),
    body = "xxxxx",
    Result =
        Web.Contents(
            rootURL,
            [
                Headers = [
                    Authorization = "Bearer " + token,
                    apikey = "xxxxxxx",
                    RelativePath = "/api/departments/list/",
                    Content = Text.ToBinary(body),
                    ContentType = "application/json"
                ],
                Query = [
                    page = "1",
                    sortDirection = "asc"
                ]
            ]
        )
in
    Result&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;&lt;A href="https://blog.crossjoin.co.uk/2016/08/16/using-the-relativepath-and-query-options-with-web-contents-in-power-query-and-power-bi-m-code/" target="_blank" rel="noopener"&gt;Chris Webb's BI Blog: Using The RelativePath And Query Options With Web.Contents() In Power Query And Power BI M Code Chris Webb's BI Blog (crossjoin.co.uk)&lt;/A&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;Regards,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;Xiaoxin Sheng&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 09 May 2022 00:55:00 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2022-05-09T00:55:00Z</dc:date>
    <item>
      <title>Connect to API with token that changes</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Connect-to-API-with-token-that-changes/m-p/2486043#M35804</link>
      <description>&lt;P&gt;Hello, I am trying to connect to an API that requires re creation of a token every 8 hours. I can get it to create a token and pull the json into postman, but not into Power Bi. When I use that postman token. I also don't know how to code it in bi to make a new token, as this one expires every 8 hours.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am entering information into Power Bi and getting the 400 error, and referring to swagger endpoints for the API&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="20220429_095032.jpg" style="width: 3024px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/707281iF15583AB11EA99AE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="20220429_095032.jpg" alt="20220429_095032.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="20220429_095038.jpg" style="width: 4032px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/707283i45035EA65B3F5945/image-size/medium?v=v2&amp;amp;px=400" role="button" title="20220429_095038.jpg" alt="20220429_095038.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="20220429_095054.jpg" style="width: 4032px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/707284iB5B8C02F31318037/image-size/medium?v=v2&amp;amp;px=400" role="button" title="20220429_095054.jpg" alt="20220429_095054.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="20220429_095103.jpg" style="width: 4032px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/707285i51C2F2CB66F96974/image-size/medium?v=v2&amp;amp;px=400" role="button" title="20220429_095103.jpg" alt="20220429_095103.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="20220429_095109.jpg" style="width: 4020px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/707286i2522988E916BCE6E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="20220429_095109.jpg" alt="20220429_095109.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="20220429_100912.jpg" style="width: 4032px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/707288i91750BFC64DEDFED/image-size/medium?v=v2&amp;amp;px=400" role="button" title="20220429_100912.jpg" alt="20220429_100912.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="20220429_100946.jpg" style="width: 4032px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/707289i608D220E35E7270A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="20220429_100946.jpg" alt="20220429_100946.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Fri, 29 Apr 2022 15:10:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Connect-to-API-with-token-that-changes/m-p/2486043#M35804</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-04-29T15:10:47Z</dc:date>
    </item>
    <item>
      <title>Re: Connect to API with token that changes</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Connect-to-API-with-token-that-changes/m-p/2488647#M35855</link>
      <description>&lt;P&gt;There are many examples for handling refresh tokens. Here is one :&amp;nbsp;&lt;A href="https://community.powerbi.com/t5/Power-Query/Refresh-token-api-call/td-p/937553" target="_blank"&gt;Solved: Refresh token api call - Microsoft Power BI Community&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 02 May 2022 12:32:31 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Connect-to-API-with-token-that-changes/m-p/2488647#M35855</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2022-05-02T12:32:31Z</dc:date>
    </item>
    <item>
      <title>Re: Connect to API with token that changes</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Connect-to-API-with-token-that-changes/m-p/2488671#M35856</link>
      <description>&lt;P&gt;I'm now finding the issue is it is a POST request instead of GET, is there any way to connect to data of they have it set up as a POST?&lt;/P&gt;</description>
      <pubDate>Mon, 02 May 2022 12:43:09 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Connect-to-API-with-token-that-changes/m-p/2488671#M35856</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-05-02T12:43:09Z</dc:date>
    </item>
    <item>
      <title>Re: Connect to API with token that changes</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Connect-to-API-with-token-that-changes/m-p/2488684#M35857</link>
      <description>&lt;P&gt;Providing a Content payload to Web.Contents() converts the API call from GET to POST.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://docs.microsoft.com/en-us/powerquery-m/web-contents" target="_blank"&gt;Web.Contents - PowerQuery M | Microsoft Docs&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 02 May 2022 12:46:18 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Connect-to-API-with-token-that-changes/m-p/2488684#M35857</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2022-05-02T12:46:18Z</dc:date>
    </item>
    <item>
      <title>Re: Connect to API with token that changes</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Connect-to-API-with-token-that-changes/m-p/2500501#M35959</link>
      <description>&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;HI&amp;nbsp;@Anonymous&lt;/a&gt;,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;In fact, you can also use post requests in the power query web connector. You need to add the request contents to the header or body(this is based on your API settings) and attached them to the data connector.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;let
    rootURL = "app.xxx.com",
    secretId = xxxxx,
    GetJson =
        Web.Contents(
            rootURL,
            [
                Headers = [
                    #"Authorization" = "Basic " &amp;amp; secretId,
                    #"Content-Type" = "application/json"
                ],
                Content = Text.ToBinary("grant_type=client_credentials")
            ]
        ),
    body = "xxxxx",
    Result =
        Web.Contents(
            rootURL,
            [
                Headers = [
                    Authorization = "Bearer " + token,
                    apikey = "xxxxxxx",
                    RelativePath = "/api/departments/list/",
                    Content = Text.ToBinary(body),
                    ContentType = "application/json"
                ],
                Query = [
                    page = "1",
                    sortDirection = "asc"
                ]
            ]
        )
in
    Result&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;&lt;A href="https://blog.crossjoin.co.uk/2016/08/16/using-the-relativepath-and-query-options-with-web-contents-in-power-query-and-power-bi-m-code/" target="_blank" rel="noopener"&gt;Chris Webb's BI Blog: Using The RelativePath And Query Options With Web.Contents() In Power Query And Power BI M Code Chris Webb's BI Blog (crossjoin.co.uk)&lt;/A&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;Regards,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;Xiaoxin Sheng&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 09 May 2022 00:55:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Connect-to-API-with-token-that-changes/m-p/2500501#M35959</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-05-09T00:55:00Z</dc:date>
    </item>
  </channel>
</rss>

