Get Tables

 

Updated: July 21, 2017



Request | Response | Example | Try on Apiary | Client and web app samples

The Get Tables operation returns a JSON list of Tables for the specified Dataset. Get Tables also returns a JSON list from a Group.

Required scope: Dataset.ReadWrite.All or Dataset.Read.All

GET https://api.powerbi.com/v1.0/myorg/datasets/{dataset_id}/tables

Groups

Groups are a collection of unified Azure Active Directory groups that the user is a member of and is available in the Power BI service. These are referred to as app workspaces within the Power BI service. To learn how to create a group, see Create an app workspace.

GET https://api.powerbi.com/v1.0/myorg/groups/{group_id}/datasets/{dataset_id}/tables

Uri parameter

NameDescriptionData Type
group_idGuid of the Group to use. You can get the group id from the Get Groups operation. Groups are referred to as app workspaces within the Power BI service.String
dataset_idGuid of the Dataset to use. You can get the dataset id from the Get Datasets operation.String

Header

Authorization: Bearer eyJ0eX ... FWSXfwtQ

Status code

CodeDescription
200OK. Indicates success. The dataset is returned in the response body.

Content-Type

application/json

Body schema

A Table has a name.

{
  "odata.context": "string",
  "value": [
    {
      "name": "string",
      "columns": [
        {
          "name": "string",
          "dataType": "string"
        }
      ],
      "rows": [
        {
          "id": "string"
        }
      ]
    }
  ]
}


[Top of article]

The following C# example calls the Get Tables operation. The example assumes you have a Dataset named SalesMarketing. To create a dataset, see Create Dataset operation. The example also shows how to:

  • Get a Dataset id using a LINQ query. To get a dataset id, see Get Datasets.
  • Deserialize the JSON response using the JavaScriptSerializer class.

Note The Client app sample also shows you how to Serialize and Deserialize a JSON request and response as well as call Group operations.

###To run this code snippet, you need to:

s1 - Have an Azure Active Directory tenant.

s2 - Sign up for Power BI.

s3 - Register your app to get a client id.

s4 - You will need a Dataset id. To get a dataset id, see Get Datasets operation.

    using System;  
    using System.Net;  
    using Microsoft.IdentityModel.Clients.ActiveDirectory;  
    using System.IO;  
    using System.Web.Script.Serialization;  
    using System.Linq;  

    public table[] GetTables()  
    {  
        //This is sample code to illustrate a Power BI operation.   
        //In a production application, refactor code into specific methods and use appropriate exception handling.  

        //The client id that Azure AD creates when you register your client app.  
        //  To learn how to register a client app, see https://msdn.microsoft.com/en-US/library/dn877542(Azure.100).aspx    
        string clientID = "{client id from Azure AD app registration}";  

        //Assuming you have a dataset named SalesMarketing  
        // To get a dataset id, see Get Datasets operation.             
        dataset[] datasets = GetDatasets();  
        string datasetId = (from d in datasets where d.Name == "SalesMarketing" select d).FirstOrDefault().Id;  

        //RedirectUri you used when you register your app.  
        //For a client app, a redirect uri gives Azure AD more details on the application that it will authenticate.  
        // You can use this redirect uri for your client app  
        string redirectUri = "https://login.live.com/oauth20_desktop.srf";  

        //Resource Uri for Power BI API  
        string resourceUri = "https://analysis.windows.net/powerbi/api";  

        //OAuth2 authority Uri  
        string authorityUri = "https://login.windows.net/common/oauth2/authorize";  

        string powerBIApiUrl = String.Format("https://api.powerbi.com/v1.0/myorg/datasets/{0}/tables", datasetId);  
         
        //Get access token:   
        // To call a Power BI REST operation, create an instance of AuthenticationContext and call AcquireToken  
        // AuthenticationContext is part of the Active Directory Authentication Library NuGet package  
        // To install the Active Directory Authentication Library NuGet package in Visual Studio,   
        //  run "Install-Package Microsoft.IdentityModel.Clients.ActiveDirectory" from the nuget Package Manager Console.  

        // AcquireToken will acquire an Azure access token  
        // Call AcquireToken to get an Azure token from Azure Active Directory token issuance endpoint  
        AuthenticationContext authContext = new AuthenticationContext(authorityUri);  
        string token = authContext.AcquireToken(resourceUri, clientId, new Uri(redirectUri), PromptBehavior.RefreshSession).AccessToken;  

        //GET web request to list all tables.  
        //To get tables in a group, use the Groups uri: https://api.powerbi.com/v1.0/myorg/groups/{group_id}/datasets/{dataset_id}/tables  
        HttpWebRequest request = System.Net.WebRequest.Create(powerBIApiUrl) as System.Net.HttpWebRequest;  
        request.KeepAlive = true;  
        request.Method = "GET";  
        request.ContentLength = 0;  
        request.ContentType = "application/json";  
        request.Headers.Add("Authorization", String.Format("Bearer {0}", token));  

        //Get HttpWebResponse from GET request  
        using (HttpWebResponse httpResponse = request.GetResponse() as System.Net.HttpWebResponse)  
        {  
            //Get StreamReader that holds the response stream  
            using (StreamReader reader = new System.IO.StreamReader(httpResponse.GetResponseStream()))  
            {  
                string responseContent = reader.ReadToEnd();  

                JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();  
                Tables tables = (Tables)jsonSerializer.Deserialize(responseContent, typeof(Tables));  

                return tables.value;  
            }  
        }  
    }  
      
    public class Datasets  
    {  
        public dataset[] value { get; set; }  
    }  

    public class dataset  
    {  
        public string Id { get; set; }  
        public string Name { get; set; }  
    }  

    public class Tables  
    {  
        public table[] value { get; set; }  
    }  

    public class table  
    {  
        public string Name { get; set; }  
    }  

    public class Groups  
    {  
        public group[] value { get; set; }  
    }  

    public class group  
    {  
        public string Id { get; set; }  
        public string Name { get; set; }  
    }       

Show: