Unable to get list of datasets in power bi using RestApi?












0














enter image description hereAfter getting Access token, by sending GET request to



https://app.powerbi.com/groups/me/datasets/


by adding access token in header



content-type: application/json
authorization: access token



instead of getting datasets i am getting html content below:



> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" >
> <head>
> <title>Power BI</title>
> <meta http-equiv="X-UA-Compatible" content="IE=edge;" />
>
> <meta charset="utf-8">
> <meta name="description" content="">
> <meta name="format-detection" content="telephone=no" />
> <link rel="shortcut icon" href="/images/PowerBI_Favicon.ico" />
>
> <meta name="apple-itunes-app" content="app-id=929738808">
> <meta name="apple-itunes-app-tab" content="app-id=929738808">
> <meta name="google-play-app" content="app-id=com.microsoft.powerbim">
> <meta name="google-play-app-tab" content="app-id=com.microsoft.powerbim">
> <meta http-equiv="x-dns-prefetch-control" content="on"> .............


how to get list of datasets in json format?



code(java sdk):



    String workspacename = "rightws";
String username = "xxxxxxxxxxx.onmicrosoft.com";
String workspaceId = "xxxxxxxxxxx1-9812b695603a";
String reportId="6xxxxxxxxxx4098-a55b-96f8c103edab";
String accessKey = "xxxxx34d7f7xxxxxxxxxxxx;
PowerBIToken token = PowerBIToken.CreateReportEmbedToken(
workspacename,
workspaceId,
reportId,
username,
null);
String jwt = token.Generate(accessKey);


System.out.println(jwt);










share|improve this question





























    0














    enter image description hereAfter getting Access token, by sending GET request to



    https://app.powerbi.com/groups/me/datasets/


    by adding access token in header



    content-type: application/json
    authorization: access token



    instead of getting datasets i am getting html content below:



    > <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" >
    > <head>
    > <title>Power BI</title>
    > <meta http-equiv="X-UA-Compatible" content="IE=edge;" />
    >
    > <meta charset="utf-8">
    > <meta name="description" content="">
    > <meta name="format-detection" content="telephone=no" />
    > <link rel="shortcut icon" href="/images/PowerBI_Favicon.ico" />
    >
    > <meta name="apple-itunes-app" content="app-id=929738808">
    > <meta name="apple-itunes-app-tab" content="app-id=929738808">
    > <meta name="google-play-app" content="app-id=com.microsoft.powerbim">
    > <meta name="google-play-app-tab" content="app-id=com.microsoft.powerbim">
    > <meta http-equiv="x-dns-prefetch-control" content="on"> .............


    how to get list of datasets in json format?



    code(java sdk):



        String workspacename = "rightws";
    String username = "xxxxxxxxxxx.onmicrosoft.com";
    String workspaceId = "xxxxxxxxxxx1-9812b695603a";
    String reportId="6xxxxxxxxxx4098-a55b-96f8c103edab";
    String accessKey = "xxxxx34d7f7xxxxxxxxxxxx;
    PowerBIToken token = PowerBIToken.CreateReportEmbedToken(
    workspacename,
    workspaceId,
    reportId,
    username,
    null);
    String jwt = token.Generate(accessKey);


    System.out.println(jwt);










    share|improve this question



























      0












      0








      0







      enter image description hereAfter getting Access token, by sending GET request to



      https://app.powerbi.com/groups/me/datasets/


      by adding access token in header



      content-type: application/json
      authorization: access token



      instead of getting datasets i am getting html content below:



      > <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" >
      > <head>
      > <title>Power BI</title>
      > <meta http-equiv="X-UA-Compatible" content="IE=edge;" />
      >
      > <meta charset="utf-8">
      > <meta name="description" content="">
      > <meta name="format-detection" content="telephone=no" />
      > <link rel="shortcut icon" href="/images/PowerBI_Favicon.ico" />
      >
      > <meta name="apple-itunes-app" content="app-id=929738808">
      > <meta name="apple-itunes-app-tab" content="app-id=929738808">
      > <meta name="google-play-app" content="app-id=com.microsoft.powerbim">
      > <meta name="google-play-app-tab" content="app-id=com.microsoft.powerbim">
      > <meta http-equiv="x-dns-prefetch-control" content="on"> .............


      how to get list of datasets in json format?



      code(java sdk):



          String workspacename = "rightws";
      String username = "xxxxxxxxxxx.onmicrosoft.com";
      String workspaceId = "xxxxxxxxxxx1-9812b695603a";
      String reportId="6xxxxxxxxxx4098-a55b-96f8c103edab";
      String accessKey = "xxxxx34d7f7xxxxxxxxxxxx;
      PowerBIToken token = PowerBIToken.CreateReportEmbedToken(
      workspacename,
      workspaceId,
      reportId,
      username,
      null);
      String jwt = token.Generate(accessKey);


      System.out.println(jwt);










      share|improve this question















      enter image description hereAfter getting Access token, by sending GET request to



      https://app.powerbi.com/groups/me/datasets/


      by adding access token in header



      content-type: application/json
      authorization: access token



      instead of getting datasets i am getting html content below:



      > <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" >
      > <head>
      > <title>Power BI</title>
      > <meta http-equiv="X-UA-Compatible" content="IE=edge;" />
      >
      > <meta charset="utf-8">
      > <meta name="description" content="">
      > <meta name="format-detection" content="telephone=no" />
      > <link rel="shortcut icon" href="/images/PowerBI_Favicon.ico" />
      >
      > <meta name="apple-itunes-app" content="app-id=929738808">
      > <meta name="apple-itunes-app-tab" content="app-id=929738808">
      > <meta name="google-play-app" content="app-id=com.microsoft.powerbim">
      > <meta name="google-play-app-tab" content="app-id=com.microsoft.powerbim">
      > <meta http-equiv="x-dns-prefetch-control" content="on"> .............


      how to get list of datasets in json format?



      code(java sdk):



          String workspacename = "rightws";
      String username = "xxxxxxxxxxx.onmicrosoft.com";
      String workspaceId = "xxxxxxxxxxx1-9812b695603a";
      String reportId="6xxxxxxxxxx4098-a55b-96f8c103edab";
      String accessKey = "xxxxx34d7f7xxxxxxxxxxxx;
      PowerBIToken token = PowerBIToken.CreateReportEmbedToken(
      workspacename,
      workspaceId,
      reportId,
      username,
      null);
      String jwt = token.Generate(accessKey);


      System.out.println(jwt);







      powerbi






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 12 '18 at 11:28

























      asked Oct 20 '18 at 18:32









      user10512791

      94




      94
























          2 Answers
          2






          active

          oldest

          votes


















          0














          It appears you may be using the wrong endpoint. The documentation for the Rest API is here: https://docs.microsoft.com/en-us/rest/api/power-bi/datasets



          To get a list of data sets you either need to use this endpoint (note there is no "group" designation in URL)



          GET https://api.powerbi.com/v1.0/myorg/datasets


          Or this one (which is data sets for a specific group -- group ID is required)



          GET https://api.powerbi.com/v1.0/myorg/groups/{groupId}/datasets


          You appear to be using the endpoint that returns groups. I think "/me/datasets" must be getting ignored



          GET https://api.powerbi.com/v1.0/myorg/groups


          Hope this helps






          share|improve this answer





















          • i am getting 403 error when sending get request to api.powerbi.com/v1.0/myorg/datasets with header as authorization: Bearer xxxxxxxxxxx , content-type:appl/json @HeavyDNickell
            – user10512791
            Oct 30 '18 at 7:29



















          0














          Try using this code:



                  var request = WebRequest.Create("https://api.powerbi.com/v1.0/myorg/datasets") as HttpWebRequest;
          request.KeepAlive = true;
          request.Method = "GET";
          request.ContentLength = 0;
          request.ContentType = "application/json";
          request.Headers.Add("Authorization", $"Bearer {accessToken}");
          using (HttpWebResponse httpResponse = request.GetResponse() as System.Net.HttpWebResponse)
          {
          using (StreamReader reader = new System.IO.StreamReader(httpResponse.GetResponseStream()))
          {
          string responseContent = reader.ReadToEnd();
          MessageBox.Show(responseContent, "Get Datasets");
          }
          }


          If you keep getting 403 error, then make sure you granted rights to read datasets when you register your application. Try to decode the access token at https://jwt.io and see does it contains Dataset.Read.All in scp:



          enter image description here



          UPDATE: It looks like your token doesn't give you rights to get the list of datasets. Try to register a new native application and make sure you select "Read All Datasets" checkbox from Dataset APIs. Then try to obtain the access token with code like this:



          string redirectUri = "https://login.live.com/oauth20_desktop.srf";
          string resourceUri = "https://analysis.windows.net/powerbi/api";
          string authorityUri = "https://login.windows.net/common/oauth2/authorize";
          string clientId = "xxxxxx";
          AuthenticationContext authContext = new AuthenticationContext(authorityUri, new TokenCache());
          var authenticationResult = await authContext.AcquireTokenAsync(resourceUri, clientId, new Uri(redirectUri), new PlatformParameters(PromptBehavior.Auto));
          if (authenticationResult != null)
          GetListOfDatasets(authenticationResult.AccessToken);


          UPDATE: To list datasets using the Power BI Client library, you need code like this. First you need to authenticate using AcquireTokenAsync (either providing user name and password, or be prompted interactively), then pass this access token to your client and call GetDatasetsInGroupWithHttpMessageAsync method.



          private static string resourceUri = "https://analysis.windows.net/powerbi/api";
          private static string apiUrl = "https://api.powerbi.com";
          private static string clientId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
          private static string groupId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";

          UserPasswordCredential uc = new UserPasswordCredential("someuser@example.com", "some strong password");
          AuthenticationResult authenticationResult = authContext.AcquireTokenAsync(resourceUri, clientId, uc).Result;
          TokenCredentials credentials = new TokenCredentials($"{authenticationResult.AccessToken}", "Bearer");
          using (var client = new Microsoft.PowerBI.Api.V2.PowerBIClient(new Uri(apiUrl), credentials))
          {
          var resultDatasets = await client.Datasets.GetDatasetsInGroupWithHttpMessagesAsync(groupId);
          foreach (var item in resultDatasets.Body.Value)
          MessageBox.Show($"{item.Name} ({item.Id})");
          }





          share|improve this answer























          • I dont find scp in the decoded token @Andrey Nikolov
            – user10512791
            Oct 31 '18 at 8:45










          • How do you obtained this token? Could you provide the decoded payload here for reviewing it (deleting the sensitive parts, of course)?
            – Andrey Nikolov
            Oct 31 '18 at 12:03










          • { "aud": "analysis.windows.net/powerbi/api", "iss": "sts.windows.net/xxxxxxxxxxxx", "iat": 1540992342, "nbf": 1540992342, "exp": 1540996242, "aio": "42RgYEg+YDnZ4Man88dERJepCbToAQA=", "appid": "xxxxxxxxxxxxxxx", "appidacr": "1", "idp": "sts.windows.net/xxxxxxxxxxx", "tid": "xxxxxxxxxxxx", "uti": "xxxxxxxxxxxx", "ver": "1.0" } @Andrey Nikolov
            – user10512791
            Oct 31 '18 at 13:36










          • Is this token generated using ADAL? Check App registrations in Azure AD does your app has access to Power BI Service API and which are the delegated permissions? Eventually, try to grant permissions for it.But essentially, you are getting 403 because this token doesn't give you rights to read the list of datasets.
            – Andrey Nikolov
            Oct 31 '18 at 14:03












          • please check the image attached, i got the token by sending post request tohttps://login.windows.net/common/oauth2/token @Andrey Nikolov
            – user10512791
            Oct 31 '18 at 14:09













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52908864%2funable-to-get-list-of-datasets-in-power-bi-using-restapi%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          It appears you may be using the wrong endpoint. The documentation for the Rest API is here: https://docs.microsoft.com/en-us/rest/api/power-bi/datasets



          To get a list of data sets you either need to use this endpoint (note there is no "group" designation in URL)



          GET https://api.powerbi.com/v1.0/myorg/datasets


          Or this one (which is data sets for a specific group -- group ID is required)



          GET https://api.powerbi.com/v1.0/myorg/groups/{groupId}/datasets


          You appear to be using the endpoint that returns groups. I think "/me/datasets" must be getting ignored



          GET https://api.powerbi.com/v1.0/myorg/groups


          Hope this helps






          share|improve this answer





















          • i am getting 403 error when sending get request to api.powerbi.com/v1.0/myorg/datasets with header as authorization: Bearer xxxxxxxxxxx , content-type:appl/json @HeavyDNickell
            – user10512791
            Oct 30 '18 at 7:29
















          0














          It appears you may be using the wrong endpoint. The documentation for the Rest API is here: https://docs.microsoft.com/en-us/rest/api/power-bi/datasets



          To get a list of data sets you either need to use this endpoint (note there is no "group" designation in URL)



          GET https://api.powerbi.com/v1.0/myorg/datasets


          Or this one (which is data sets for a specific group -- group ID is required)



          GET https://api.powerbi.com/v1.0/myorg/groups/{groupId}/datasets


          You appear to be using the endpoint that returns groups. I think "/me/datasets" must be getting ignored



          GET https://api.powerbi.com/v1.0/myorg/groups


          Hope this helps






          share|improve this answer





















          • i am getting 403 error when sending get request to api.powerbi.com/v1.0/myorg/datasets with header as authorization: Bearer xxxxxxxxxxx , content-type:appl/json @HeavyDNickell
            – user10512791
            Oct 30 '18 at 7:29














          0












          0








          0






          It appears you may be using the wrong endpoint. The documentation for the Rest API is here: https://docs.microsoft.com/en-us/rest/api/power-bi/datasets



          To get a list of data sets you either need to use this endpoint (note there is no "group" designation in URL)



          GET https://api.powerbi.com/v1.0/myorg/datasets


          Or this one (which is data sets for a specific group -- group ID is required)



          GET https://api.powerbi.com/v1.0/myorg/groups/{groupId}/datasets


          You appear to be using the endpoint that returns groups. I think "/me/datasets" must be getting ignored



          GET https://api.powerbi.com/v1.0/myorg/groups


          Hope this helps






          share|improve this answer












          It appears you may be using the wrong endpoint. The documentation for the Rest API is here: https://docs.microsoft.com/en-us/rest/api/power-bi/datasets



          To get a list of data sets you either need to use this endpoint (note there is no "group" designation in URL)



          GET https://api.powerbi.com/v1.0/myorg/datasets


          Or this one (which is data sets for a specific group -- group ID is required)



          GET https://api.powerbi.com/v1.0/myorg/groups/{groupId}/datasets


          You appear to be using the endpoint that returns groups. I think "/me/datasets" must be getting ignored



          GET https://api.powerbi.com/v1.0/myorg/groups


          Hope this helps







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Oct 22 '18 at 11:03









          HeavyDNickell

          364




          364












          • i am getting 403 error when sending get request to api.powerbi.com/v1.0/myorg/datasets with header as authorization: Bearer xxxxxxxxxxx , content-type:appl/json @HeavyDNickell
            – user10512791
            Oct 30 '18 at 7:29


















          • i am getting 403 error when sending get request to api.powerbi.com/v1.0/myorg/datasets with header as authorization: Bearer xxxxxxxxxxx , content-type:appl/json @HeavyDNickell
            – user10512791
            Oct 30 '18 at 7:29
















          i am getting 403 error when sending get request to api.powerbi.com/v1.0/myorg/datasets with header as authorization: Bearer xxxxxxxxxxx , content-type:appl/json @HeavyDNickell
          – user10512791
          Oct 30 '18 at 7:29




          i am getting 403 error when sending get request to api.powerbi.com/v1.0/myorg/datasets with header as authorization: Bearer xxxxxxxxxxx , content-type:appl/json @HeavyDNickell
          – user10512791
          Oct 30 '18 at 7:29













          0














          Try using this code:



                  var request = WebRequest.Create("https://api.powerbi.com/v1.0/myorg/datasets") as HttpWebRequest;
          request.KeepAlive = true;
          request.Method = "GET";
          request.ContentLength = 0;
          request.ContentType = "application/json";
          request.Headers.Add("Authorization", $"Bearer {accessToken}");
          using (HttpWebResponse httpResponse = request.GetResponse() as System.Net.HttpWebResponse)
          {
          using (StreamReader reader = new System.IO.StreamReader(httpResponse.GetResponseStream()))
          {
          string responseContent = reader.ReadToEnd();
          MessageBox.Show(responseContent, "Get Datasets");
          }
          }


          If you keep getting 403 error, then make sure you granted rights to read datasets when you register your application. Try to decode the access token at https://jwt.io and see does it contains Dataset.Read.All in scp:



          enter image description here



          UPDATE: It looks like your token doesn't give you rights to get the list of datasets. Try to register a new native application and make sure you select "Read All Datasets" checkbox from Dataset APIs. Then try to obtain the access token with code like this:



          string redirectUri = "https://login.live.com/oauth20_desktop.srf";
          string resourceUri = "https://analysis.windows.net/powerbi/api";
          string authorityUri = "https://login.windows.net/common/oauth2/authorize";
          string clientId = "xxxxxx";
          AuthenticationContext authContext = new AuthenticationContext(authorityUri, new TokenCache());
          var authenticationResult = await authContext.AcquireTokenAsync(resourceUri, clientId, new Uri(redirectUri), new PlatformParameters(PromptBehavior.Auto));
          if (authenticationResult != null)
          GetListOfDatasets(authenticationResult.AccessToken);


          UPDATE: To list datasets using the Power BI Client library, you need code like this. First you need to authenticate using AcquireTokenAsync (either providing user name and password, or be prompted interactively), then pass this access token to your client and call GetDatasetsInGroupWithHttpMessageAsync method.



          private static string resourceUri = "https://analysis.windows.net/powerbi/api";
          private static string apiUrl = "https://api.powerbi.com";
          private static string clientId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
          private static string groupId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";

          UserPasswordCredential uc = new UserPasswordCredential("someuser@example.com", "some strong password");
          AuthenticationResult authenticationResult = authContext.AcquireTokenAsync(resourceUri, clientId, uc).Result;
          TokenCredentials credentials = new TokenCredentials($"{authenticationResult.AccessToken}", "Bearer");
          using (var client = new Microsoft.PowerBI.Api.V2.PowerBIClient(new Uri(apiUrl), credentials))
          {
          var resultDatasets = await client.Datasets.GetDatasetsInGroupWithHttpMessagesAsync(groupId);
          foreach (var item in resultDatasets.Body.Value)
          MessageBox.Show($"{item.Name} ({item.Id})");
          }





          share|improve this answer























          • I dont find scp in the decoded token @Andrey Nikolov
            – user10512791
            Oct 31 '18 at 8:45










          • How do you obtained this token? Could you provide the decoded payload here for reviewing it (deleting the sensitive parts, of course)?
            – Andrey Nikolov
            Oct 31 '18 at 12:03










          • { "aud": "analysis.windows.net/powerbi/api", "iss": "sts.windows.net/xxxxxxxxxxxx", "iat": 1540992342, "nbf": 1540992342, "exp": 1540996242, "aio": "42RgYEg+YDnZ4Man88dERJepCbToAQA=", "appid": "xxxxxxxxxxxxxxx", "appidacr": "1", "idp": "sts.windows.net/xxxxxxxxxxx", "tid": "xxxxxxxxxxxx", "uti": "xxxxxxxxxxxx", "ver": "1.0" } @Andrey Nikolov
            – user10512791
            Oct 31 '18 at 13:36










          • Is this token generated using ADAL? Check App registrations in Azure AD does your app has access to Power BI Service API and which are the delegated permissions? Eventually, try to grant permissions for it.But essentially, you are getting 403 because this token doesn't give you rights to read the list of datasets.
            – Andrey Nikolov
            Oct 31 '18 at 14:03












          • please check the image attached, i got the token by sending post request tohttps://login.windows.net/common/oauth2/token @Andrey Nikolov
            – user10512791
            Oct 31 '18 at 14:09


















          0














          Try using this code:



                  var request = WebRequest.Create("https://api.powerbi.com/v1.0/myorg/datasets") as HttpWebRequest;
          request.KeepAlive = true;
          request.Method = "GET";
          request.ContentLength = 0;
          request.ContentType = "application/json";
          request.Headers.Add("Authorization", $"Bearer {accessToken}");
          using (HttpWebResponse httpResponse = request.GetResponse() as System.Net.HttpWebResponse)
          {
          using (StreamReader reader = new System.IO.StreamReader(httpResponse.GetResponseStream()))
          {
          string responseContent = reader.ReadToEnd();
          MessageBox.Show(responseContent, "Get Datasets");
          }
          }


          If you keep getting 403 error, then make sure you granted rights to read datasets when you register your application. Try to decode the access token at https://jwt.io and see does it contains Dataset.Read.All in scp:



          enter image description here



          UPDATE: It looks like your token doesn't give you rights to get the list of datasets. Try to register a new native application and make sure you select "Read All Datasets" checkbox from Dataset APIs. Then try to obtain the access token with code like this:



          string redirectUri = "https://login.live.com/oauth20_desktop.srf";
          string resourceUri = "https://analysis.windows.net/powerbi/api";
          string authorityUri = "https://login.windows.net/common/oauth2/authorize";
          string clientId = "xxxxxx";
          AuthenticationContext authContext = new AuthenticationContext(authorityUri, new TokenCache());
          var authenticationResult = await authContext.AcquireTokenAsync(resourceUri, clientId, new Uri(redirectUri), new PlatformParameters(PromptBehavior.Auto));
          if (authenticationResult != null)
          GetListOfDatasets(authenticationResult.AccessToken);


          UPDATE: To list datasets using the Power BI Client library, you need code like this. First you need to authenticate using AcquireTokenAsync (either providing user name and password, or be prompted interactively), then pass this access token to your client and call GetDatasetsInGroupWithHttpMessageAsync method.



          private static string resourceUri = "https://analysis.windows.net/powerbi/api";
          private static string apiUrl = "https://api.powerbi.com";
          private static string clientId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
          private static string groupId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";

          UserPasswordCredential uc = new UserPasswordCredential("someuser@example.com", "some strong password");
          AuthenticationResult authenticationResult = authContext.AcquireTokenAsync(resourceUri, clientId, uc).Result;
          TokenCredentials credentials = new TokenCredentials($"{authenticationResult.AccessToken}", "Bearer");
          using (var client = new Microsoft.PowerBI.Api.V2.PowerBIClient(new Uri(apiUrl), credentials))
          {
          var resultDatasets = await client.Datasets.GetDatasetsInGroupWithHttpMessagesAsync(groupId);
          foreach (var item in resultDatasets.Body.Value)
          MessageBox.Show($"{item.Name} ({item.Id})");
          }





          share|improve this answer























          • I dont find scp in the decoded token @Andrey Nikolov
            – user10512791
            Oct 31 '18 at 8:45










          • How do you obtained this token? Could you provide the decoded payload here for reviewing it (deleting the sensitive parts, of course)?
            – Andrey Nikolov
            Oct 31 '18 at 12:03










          • { "aud": "analysis.windows.net/powerbi/api", "iss": "sts.windows.net/xxxxxxxxxxxx", "iat": 1540992342, "nbf": 1540992342, "exp": 1540996242, "aio": "42RgYEg+YDnZ4Man88dERJepCbToAQA=", "appid": "xxxxxxxxxxxxxxx", "appidacr": "1", "idp": "sts.windows.net/xxxxxxxxxxx", "tid": "xxxxxxxxxxxx", "uti": "xxxxxxxxxxxx", "ver": "1.0" } @Andrey Nikolov
            – user10512791
            Oct 31 '18 at 13:36










          • Is this token generated using ADAL? Check App registrations in Azure AD does your app has access to Power BI Service API and which are the delegated permissions? Eventually, try to grant permissions for it.But essentially, you are getting 403 because this token doesn't give you rights to read the list of datasets.
            – Andrey Nikolov
            Oct 31 '18 at 14:03












          • please check the image attached, i got the token by sending post request tohttps://login.windows.net/common/oauth2/token @Andrey Nikolov
            – user10512791
            Oct 31 '18 at 14:09
















          0












          0








          0






          Try using this code:



                  var request = WebRequest.Create("https://api.powerbi.com/v1.0/myorg/datasets") as HttpWebRequest;
          request.KeepAlive = true;
          request.Method = "GET";
          request.ContentLength = 0;
          request.ContentType = "application/json";
          request.Headers.Add("Authorization", $"Bearer {accessToken}");
          using (HttpWebResponse httpResponse = request.GetResponse() as System.Net.HttpWebResponse)
          {
          using (StreamReader reader = new System.IO.StreamReader(httpResponse.GetResponseStream()))
          {
          string responseContent = reader.ReadToEnd();
          MessageBox.Show(responseContent, "Get Datasets");
          }
          }


          If you keep getting 403 error, then make sure you granted rights to read datasets when you register your application. Try to decode the access token at https://jwt.io and see does it contains Dataset.Read.All in scp:



          enter image description here



          UPDATE: It looks like your token doesn't give you rights to get the list of datasets. Try to register a new native application and make sure you select "Read All Datasets" checkbox from Dataset APIs. Then try to obtain the access token with code like this:



          string redirectUri = "https://login.live.com/oauth20_desktop.srf";
          string resourceUri = "https://analysis.windows.net/powerbi/api";
          string authorityUri = "https://login.windows.net/common/oauth2/authorize";
          string clientId = "xxxxxx";
          AuthenticationContext authContext = new AuthenticationContext(authorityUri, new TokenCache());
          var authenticationResult = await authContext.AcquireTokenAsync(resourceUri, clientId, new Uri(redirectUri), new PlatformParameters(PromptBehavior.Auto));
          if (authenticationResult != null)
          GetListOfDatasets(authenticationResult.AccessToken);


          UPDATE: To list datasets using the Power BI Client library, you need code like this. First you need to authenticate using AcquireTokenAsync (either providing user name and password, or be prompted interactively), then pass this access token to your client and call GetDatasetsInGroupWithHttpMessageAsync method.



          private static string resourceUri = "https://analysis.windows.net/powerbi/api";
          private static string apiUrl = "https://api.powerbi.com";
          private static string clientId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
          private static string groupId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";

          UserPasswordCredential uc = new UserPasswordCredential("someuser@example.com", "some strong password");
          AuthenticationResult authenticationResult = authContext.AcquireTokenAsync(resourceUri, clientId, uc).Result;
          TokenCredentials credentials = new TokenCredentials($"{authenticationResult.AccessToken}", "Bearer");
          using (var client = new Microsoft.PowerBI.Api.V2.PowerBIClient(new Uri(apiUrl), credentials))
          {
          var resultDatasets = await client.Datasets.GetDatasetsInGroupWithHttpMessagesAsync(groupId);
          foreach (var item in resultDatasets.Body.Value)
          MessageBox.Show($"{item.Name} ({item.Id})");
          }





          share|improve this answer














          Try using this code:



                  var request = WebRequest.Create("https://api.powerbi.com/v1.0/myorg/datasets") as HttpWebRequest;
          request.KeepAlive = true;
          request.Method = "GET";
          request.ContentLength = 0;
          request.ContentType = "application/json";
          request.Headers.Add("Authorization", $"Bearer {accessToken}");
          using (HttpWebResponse httpResponse = request.GetResponse() as System.Net.HttpWebResponse)
          {
          using (StreamReader reader = new System.IO.StreamReader(httpResponse.GetResponseStream()))
          {
          string responseContent = reader.ReadToEnd();
          MessageBox.Show(responseContent, "Get Datasets");
          }
          }


          If you keep getting 403 error, then make sure you granted rights to read datasets when you register your application. Try to decode the access token at https://jwt.io and see does it contains Dataset.Read.All in scp:



          enter image description here



          UPDATE: It looks like your token doesn't give you rights to get the list of datasets. Try to register a new native application and make sure you select "Read All Datasets" checkbox from Dataset APIs. Then try to obtain the access token with code like this:



          string redirectUri = "https://login.live.com/oauth20_desktop.srf";
          string resourceUri = "https://analysis.windows.net/powerbi/api";
          string authorityUri = "https://login.windows.net/common/oauth2/authorize";
          string clientId = "xxxxxx";
          AuthenticationContext authContext = new AuthenticationContext(authorityUri, new TokenCache());
          var authenticationResult = await authContext.AcquireTokenAsync(resourceUri, clientId, new Uri(redirectUri), new PlatformParameters(PromptBehavior.Auto));
          if (authenticationResult != null)
          GetListOfDatasets(authenticationResult.AccessToken);


          UPDATE: To list datasets using the Power BI Client library, you need code like this. First you need to authenticate using AcquireTokenAsync (either providing user name and password, or be prompted interactively), then pass this access token to your client and call GetDatasetsInGroupWithHttpMessageAsync method.



          private static string resourceUri = "https://analysis.windows.net/powerbi/api";
          private static string apiUrl = "https://api.powerbi.com";
          private static string clientId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
          private static string groupId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";

          UserPasswordCredential uc = new UserPasswordCredential("someuser@example.com", "some strong password");
          AuthenticationResult authenticationResult = authContext.AcquireTokenAsync(resourceUri, clientId, uc).Result;
          TokenCredentials credentials = new TokenCredentials($"{authenticationResult.AccessToken}", "Bearer");
          using (var client = new Microsoft.PowerBI.Api.V2.PowerBIClient(new Uri(apiUrl), credentials))
          {
          var resultDatasets = await client.Datasets.GetDatasetsInGroupWithHttpMessagesAsync(groupId);
          foreach (var item in resultDatasets.Body.Value)
          MessageBox.Show($"{item.Name} ({item.Id})");
          }






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 12 '18 at 12:02

























          answered Oct 31 '18 at 7:21









          Andrey Nikolov

          3,2781620




          3,2781620












          • I dont find scp in the decoded token @Andrey Nikolov
            – user10512791
            Oct 31 '18 at 8:45










          • How do you obtained this token? Could you provide the decoded payload here for reviewing it (deleting the sensitive parts, of course)?
            – Andrey Nikolov
            Oct 31 '18 at 12:03










          • { "aud": "analysis.windows.net/powerbi/api", "iss": "sts.windows.net/xxxxxxxxxxxx", "iat": 1540992342, "nbf": 1540992342, "exp": 1540996242, "aio": "42RgYEg+YDnZ4Man88dERJepCbToAQA=", "appid": "xxxxxxxxxxxxxxx", "appidacr": "1", "idp": "sts.windows.net/xxxxxxxxxxx", "tid": "xxxxxxxxxxxx", "uti": "xxxxxxxxxxxx", "ver": "1.0" } @Andrey Nikolov
            – user10512791
            Oct 31 '18 at 13:36










          • Is this token generated using ADAL? Check App registrations in Azure AD does your app has access to Power BI Service API and which are the delegated permissions? Eventually, try to grant permissions for it.But essentially, you are getting 403 because this token doesn't give you rights to read the list of datasets.
            – Andrey Nikolov
            Oct 31 '18 at 14:03












          • please check the image attached, i got the token by sending post request tohttps://login.windows.net/common/oauth2/token @Andrey Nikolov
            – user10512791
            Oct 31 '18 at 14:09




















          • I dont find scp in the decoded token @Andrey Nikolov
            – user10512791
            Oct 31 '18 at 8:45










          • How do you obtained this token? Could you provide the decoded payload here for reviewing it (deleting the sensitive parts, of course)?
            – Andrey Nikolov
            Oct 31 '18 at 12:03










          • { "aud": "analysis.windows.net/powerbi/api", "iss": "sts.windows.net/xxxxxxxxxxxx", "iat": 1540992342, "nbf": 1540992342, "exp": 1540996242, "aio": "42RgYEg+YDnZ4Man88dERJepCbToAQA=", "appid": "xxxxxxxxxxxxxxx", "appidacr": "1", "idp": "sts.windows.net/xxxxxxxxxxx", "tid": "xxxxxxxxxxxx", "uti": "xxxxxxxxxxxx", "ver": "1.0" } @Andrey Nikolov
            – user10512791
            Oct 31 '18 at 13:36










          • Is this token generated using ADAL? Check App registrations in Azure AD does your app has access to Power BI Service API and which are the delegated permissions? Eventually, try to grant permissions for it.But essentially, you are getting 403 because this token doesn't give you rights to read the list of datasets.
            – Andrey Nikolov
            Oct 31 '18 at 14:03












          • please check the image attached, i got the token by sending post request tohttps://login.windows.net/common/oauth2/token @Andrey Nikolov
            – user10512791
            Oct 31 '18 at 14:09


















          I dont find scp in the decoded token @Andrey Nikolov
          – user10512791
          Oct 31 '18 at 8:45




          I dont find scp in the decoded token @Andrey Nikolov
          – user10512791
          Oct 31 '18 at 8:45












          How do you obtained this token? Could you provide the decoded payload here for reviewing it (deleting the sensitive parts, of course)?
          – Andrey Nikolov
          Oct 31 '18 at 12:03




          How do you obtained this token? Could you provide the decoded payload here for reviewing it (deleting the sensitive parts, of course)?
          – Andrey Nikolov
          Oct 31 '18 at 12:03












          { "aud": "analysis.windows.net/powerbi/api", "iss": "sts.windows.net/xxxxxxxxxxxx", "iat": 1540992342, "nbf": 1540992342, "exp": 1540996242, "aio": "42RgYEg+YDnZ4Man88dERJepCbToAQA=", "appid": "xxxxxxxxxxxxxxx", "appidacr": "1", "idp": "sts.windows.net/xxxxxxxxxxx", "tid": "xxxxxxxxxxxx", "uti": "xxxxxxxxxxxx", "ver": "1.0" } @Andrey Nikolov
          – user10512791
          Oct 31 '18 at 13:36




          { "aud": "analysis.windows.net/powerbi/api", "iss": "sts.windows.net/xxxxxxxxxxxx", "iat": 1540992342, "nbf": 1540992342, "exp": 1540996242, "aio": "42RgYEg+YDnZ4Man88dERJepCbToAQA=", "appid": "xxxxxxxxxxxxxxx", "appidacr": "1", "idp": "sts.windows.net/xxxxxxxxxxx", "tid": "xxxxxxxxxxxx", "uti": "xxxxxxxxxxxx", "ver": "1.0" } @Andrey Nikolov
          – user10512791
          Oct 31 '18 at 13:36












          Is this token generated using ADAL? Check App registrations in Azure AD does your app has access to Power BI Service API and which are the delegated permissions? Eventually, try to grant permissions for it.But essentially, you are getting 403 because this token doesn't give you rights to read the list of datasets.
          – Andrey Nikolov
          Oct 31 '18 at 14:03






          Is this token generated using ADAL? Check App registrations in Azure AD does your app has access to Power BI Service API and which are the delegated permissions? Eventually, try to grant permissions for it.But essentially, you are getting 403 because this token doesn't give you rights to read the list of datasets.
          – Andrey Nikolov
          Oct 31 '18 at 14:03














          please check the image attached, i got the token by sending post request tohttps://login.windows.net/common/oauth2/token @Andrey Nikolov
          – user10512791
          Oct 31 '18 at 14:09






          please check the image attached, i got the token by sending post request tohttps://login.windows.net/common/oauth2/token @Andrey Nikolov
          – user10512791
          Oct 31 '18 at 14:09




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52908864%2funable-to-get-list-of-datasets-in-power-bi-using-restapi%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Xamarin.form Move up view when keyboard appear

          Post-Redirect-Get with Spring WebFlux and Thymeleaf

          Anylogic : not able to use stopDelay()