Forum Discussion

rcyber's avatar
rcyber
Resolver I
7 years ago
Solved

Underlying error message:Value cannot be null. Parameter name: uriString

Hello all!

 

I've developed a custom connector. It is very simple and just shows the 'Hello world!' message.

Also I added an OAuth authentification method. And it works fine too in Power BI desktop but not on Power BI Service.

When I'm trying to add a datasource on Power BI service I get the following error: "Google:There was an error in the data gateway. Underlying error message:Value cannot be null. Parameter name: uriString".

What does it mean? What do I wrong?

 

 

Thanks in advance,

Alexander.

  • I've found out MS has issued the new version of Gateway.

    I've installed that and my issue is disappeared then.

    So, my connector works fine now and we can close the topic.

     

    Thanks.

5 Replies

    • rcyber's avatar
      rcyber
      Resolver I

      Thanks for reply.

       

      I've checked everything ten times. Still not working.

      In order to understanding what is wrong I created a new PQConnector project and added the code from GitHub sample that is placed here. I added the functions for implementation of OAuth process.

       

      It works fine under Visual Studio and Power BI Desktop both.

      But if I add this connector onto Power BI Service I have got the same error.

      I guess I've missed some URL I need in to complete OAuth but what have I missed? And why does it work in Power BI desktop but not on Power BI service then?

       

      Will be appreciate for any help.

      Below is the code of the test connector.

       

      Thanks,

      Alexander

      Spoiler
      // This file contains your Data Connector logic
      section GitHub;
      
      redirect_uri = "https://oauth.powerbi.com/views/oauthredirect.html";
      client_id = "";
      client_secret = "";
      windowWidth = 1000;
      windowHeight = 800;
      
      
      [DataSource.Kind="GitHub", Publish="GitHub.Publish"]
      shared GitHub.Contents = (optional message as text) =>
          let
              _message = if (message <> null) then message else "(no message)",
              a = "Hello from GitHub: " & _message
          in
              a;
      
      // Data Source Kind description
      GitHub = [
          Authentication = [
              OAuth = [
                  StartLogin = StartLogin,
                  FinishLogin = FinishLogin
              ]
          ],
          Label = Extension.LoadString("DataSourceLabel")
      ];
      
      StartLogin = (resourceUrl, state, display) =>
              let
                  TestConnection = (url) => {"GitHub.Contents"},
                  AuthorizeUrl = "https://Github.com/login/oauth/authorize?" & Uri.BuildQueryString([
                      client_id = client_id,
                      scope = "user, repo",
                      state = state,
                      redirect_uri = redirect_uri])
              in
                  [
                      LoginUri = AuthorizeUrl,
                      CallbackUri = redirect_uri,
                      WindowHeight = windowHeight,
                      WindowWidth = windowWidth,
                      Context = null
                  ];
      
      FinishLogin = (context, callbackUri, state) =>
          let
              Parts = Uri.Parts(callbackUri)[Query]
          in
              TokenMethod(Parts[code]);
      
       TokenMethod = (code) =>
          let
              Response = Web.Contents("https://Github.com/login/oauth/access_token", [
                  Content = Text.ToBinary(Uri.BuildQueryString([
                      client_id = client_id,
                      client_secret = client_secret,
                      code = code,
                      redirect_uri = redirect_uri])),
                  Headers=[#"Content-type" = "application/x-www-form-urlencoded",#"Accept" = "application/json"]]),
              Parts = Json.Document(Response)
          in
              Parts;
      
      // Data Source UI publishing description
      GitHub.Publish = [
          Beta = true,
          Category = "Other",
          ButtonText = { Extension.LoadString("ButtonTitle"), Extension.LoadString("ButtonHelp") },
          LearnMoreUrl = "https://powerbi.microsoft.com/",
          SourceImage = GitHub.Icons,
          SourceTypeImage = GitHub.Icons
      ];
      
      GitHub.Icons = [
          Icon16 = { Extension.Contents("GitHub16.png"), Extension.Contents("GitHub20.png"), Extension.Contents("GitHub24.png"), Extension.Contents("GitHub32.png") },
          Icon32 = { Extension.Contents("GitHub32.png"), Extension.Contents("GitHub40.png"), Extension.Contents("GitHub48.png"), Extension.Contents("GitHub64.png") }
      ];

       

      • rcyber's avatar
        rcyber
        Resolver I

        Also I've tried the following.

         

        I put whole code from sample into Github.pq and it does not work.

        Something is wrong but I can't understand what.

         

        Help!

  • Kyle-MSFT's avatar
    Kyle-MSFT
    Microsoft Employee

    Another thing to check if you are getting the "Value cannot be null. Parameter name: uriString" error while creating a gateway connection to a custom data connector. Verify you are using the correct redirect endpoint/URL in your gateway's OAuth flow. It needs to be https://oauth.powerbi.com/views/oauthredirect.html. You can read more information about the redirect URL here in the "OAuth and Power BI" section: https://docs.microsoft.com/en-us/power-query/samples/github/readme