<?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 Custom Connector Issue in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Power-Query-Custom-Connector-Issue/m-p/3465937#M44839</link>
    <description>&lt;P&gt;The following code works. It might be worth comparing the two:&amp;nbsp;&lt;A href="https://community.fabric.microsoft.com/t5/Desktop/Custom-Zendesk-Connector-Power-Query-Code/td-p/2407620" target="_blank"&gt;https://community.fabric.microsoft.com/t5/Desktop/Custom-Zendesk-Connector-Power-Query-Code/td-p/2407620&lt;/A&gt;.&amp;nbsp; It's going to be difficult to find an answer to this without us being able to test it against the source.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 09 Oct 2023 00:46:17 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2023-10-09T00:46:17Z</dc:date>
    <item>
      <title>Power Query Custom Connector Issue</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-Query-Custom-Connector-Issue/m-p/2180889#M32824</link>
      <description>&lt;P&gt;Hi Experts,&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/10513"&gt;@mattmasson&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/148706"&gt;@colinpop&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/232700"&gt;@zhouguyin&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/91"&gt;@GuyInACube&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to build a custom connector for using the below code but I am facing the below difficulties ( I am assuming that after getting the auth code the process is not able to move forward) :&lt;/P&gt;&lt;P&gt;1. While testing the code successfully generates the authorization code but nothing happens after that.&lt;/P&gt;&lt;P&gt;2. Ideally the process should automatically get the access token after receiving the code and finish login which is not happening. Any pointers will be much appreciated. Below is the code :&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;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;// This file contains your Data Connector logic
section ProcoreConnector;

// Procore OAuth2 values
client_id = Text.FromBinary(Extension.Contents("client_id.txt"));
client_secret = Text.FromBinary(Extension.Contents("client_secret.txt"));
redirect_uri = "urn:ietf:wg:oauth:2.0:oob";
token_uri = "https://login.procore.com/oauth/token";
authorize_uri = "https://login.procore.com/oauth/authorize";

// Login modal window dimensions
windowWidth = 720;
windowHeight = 1024;

// OAuth2 scope
scope_prefix = "";
scopes = {
    ""
};


[DataSource.Kind="ProcoreConnector", Publish="ProcoreConnector.Publish"]
shared ProcoreConnector.Contents = (optional url as text) =&amp;gt;
    let
        source = Json.Document(Web.Contents(url))
    in
        source; 

// Data Source Kind description
ProcoreConnector= [
    TestConnection = (dataSourcePath) =&amp;gt; { "ProcoreConnector.Contents", dataSourcePath },
    Authentication = [
        OAuth = [
            StartLogin=StartLogin,
            FinishLogin=FinishLogin,
            Refresh=Refresh
        ]
    ],
    Label = Extension.LoadString("DataSourceLabel")
];

// Data Source UI publishing description
ProcoreConnector.Publish = [
    Beta = true,
    Category = "Other",
    ButtonText = { Extension.LoadString("ButtonTitle"), Extension.LoadString("ButtonHelp") },
    LearnMoreUrl = "https://developers.procore.com/",
    SourceImage = ProcoreConnector.Icons,
    SourceTypeImage = ProcoreConnector.Icons
];

// Helper functions for OAuth2: StartLogin, FinishLogin, Refresh, Logout
StartLogin = (resourceUrl, state, display) =&amp;gt;
    let
        authorizeUrl = authorize_uri &amp;amp; "?" &amp;amp; Uri.BuildQueryString([
            response_type = "code",
            scope = "",
            state = state,
            client_id = client_id,  
            redirect_uri = redirect_uri
        ])
    in
        [
            LoginUri = authorizeUrl,
            CallbackUri = redirect_uri,
            WindowHeight = 720,
            WindowWidth = 1024,
            Context = null
        ];

FinishLogin = (context, callbackUri, state) =&amp;gt;
    let
        Parts = Uri.Parts(callbackUri)[Query]
    in
        TokenMethod(Parts[code]);

Refresh = (resourceUrl, refresh_token) =&amp;gt; TokenMethod("refresh_token", "refresh_token", refresh_token);

// see "Exchange code for access token: https://developers.procore.com/documentation/oauth-installed-apps for details
TokenMethod = (grantType, tokenField, code) =&amp;gt;
    let
        queryString = [
            grant_type = "authorization_code",
            redirect_uri = redirect_uri,
            client_id = client_id,
            client_secret = client_secret
        ],
        queryWithCode = Record.AddField(queryString, tokenField, code),

        tokenResponse = Web.Contents(token_uri, [
            Content = Text.ToBinary(Uri.BuildQueryString(queryWithCode)),
            Headers = [
                #"Content-type" = "application/x-www-form-urlencoded",
                #"Accept" = "application/json"
            ],
            ManualStatusHandling = {400} 
        ]),
        body = Json.Document(tokenResponse),
        result = if (Record.HasFields(body, {"error", "error_description"})) then 
                    error Error.Record(body[error], body[error_description], body)
                 else
                    body
    in
        result;
       

ProcoreConnector.Icons = [
    Icon16 = { Extension.Contents("ProcoreConnector16.png"), Extension.Contents("ProcoreConnector20.png"), Extension.Contents("ProcoreConnector24.png"), Extension.Contents("ProcoreConnector32.png") },
    Icon32 = { Extension.Contents("ProcoreConnector32.png"), Extension.Contents("ProcoreConnector40.png"), Extension.Contents("ProcoreConnector48.png"), Extension.Contents("ProcoreConnector64.png") }
];&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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Nov 2021 16:57:25 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-Query-Custom-Connector-Issue/m-p/2180889#M32824</guid>
      <dc:creator>SMax</dc:creator>
      <dc:date>2021-11-09T16:57:25Z</dc:date>
    </item>
    <item>
      <title>Re: Power Query Custom Connector Issue</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-Query-Custom-Connector-Issue/m-p/2186914#M32883</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/337776"&gt;@SMax&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What data source do you want to connect with in Power BI?&lt;/P&gt;
&lt;P&gt;I think your code is used to get access token from your data source. Will it return error or other?&lt;/P&gt;
&lt;P&gt;Here is a bolg with similar requirement like yours, I hope it could help you.&lt;/P&gt;
&lt;P&gt;For reference:&amp;nbsp;&lt;A href="https://community.powerbi.com/t5/Desktop/Power-Query-Open-ID-and-OAuth-2-0-Rest-API/m-p/693162" target="_self"&gt;&lt;SPAN&gt;Power Query Open ID and OAuth 2.0 Rest API&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.powerbi.com/t5/Developer/REST-API-Get-Access-Token/m-p/1895937" target="_self"&gt;REST API Get Access Token&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;BR /&gt;Rico Zhou&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Nov 2021 08:26:53 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-Query-Custom-Connector-Issue/m-p/2186914#M32883</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-11-12T08:26:53Z</dc:date>
    </item>
    <item>
      <title>Re: Power Query Custom Connector Issue</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-Query-Custom-Connector-Issue/m-p/3465937#M44839</link>
      <description>&lt;P&gt;The following code works. It might be worth comparing the two:&amp;nbsp;&lt;A href="https://community.fabric.microsoft.com/t5/Desktop/Custom-Zendesk-Connector-Power-Query-Code/td-p/2407620" target="_blank"&gt;https://community.fabric.microsoft.com/t5/Desktop/Custom-Zendesk-Connector-Power-Query-Code/td-p/2407620&lt;/A&gt;.&amp;nbsp; It's going to be difficult to find an answer to this without us being able to test it against the source.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2023 00:46:17 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-Query-Custom-Connector-Issue/m-p/3465937#M44839</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-10-09T00:46:17Z</dc:date>
    </item>
  </channel>
</rss>

