Now that you’ve learned about the Power BI REST APIs, you’re probably eager to try them out. But hold off writing code in Visual Studio. As it turns out, Microsoft created a very useful site, Power BI Developer Center, to get you started with Power BI
programming!
Getting started with Power BI Developer Center
You can access the Power BI Developer Center in three different ways:
1.Navigate to http://powerbi.com. Expand the Support menu and click Documentation.
Scroll to the bottom of the page, and click Developers in the Information section.
2.Log in to Power BI. Expand the “Help & Support” menu and then click “Power BI for Developers”.
3.Navigate directly to https://powerbi.microsoft.com/developers.
Figure 11.5 Power BI Developer Center is your one-stop resource for programming with Power BI.
The Power BI Developer Center (see Figure 11.5) is your one-stop resource for all your Power BI developer needs. It has links to useful resources, including developer
documentation and step-by-step guides of how to accomplish specific tasks.
4.Since I’m on the subject of REST APIs, click the “Try the API” link. This opens the Power BI REST API site, where you can read the API documentation.
Testing the APIs
A great feature of the Power BI REST API site is that it includes a testing console where you can try the APIs without writing a single line of code! Follow these steps to test the dataset APIs:
1.In the Power BI REST API site, click the Datasets link in the navigation page to expand the section.
2.Click the Datasets Collection item. This shows you the documentation of the dataset- related APIs.
3.Click the “List all Datasets” section. The right pane shows an example of the method call, including a sample request and a sample raw JSON response (see Figure 11.6).
Figure 11.6 The Power BI REST API site shows an example of the method invocation.
4.To get a code example written in your preferred programming language, expand the drop-down menu to the left of the Try button (that says “Raw”), and then select your targeted language, such as C#, Visual Basic, JavaScript, Node.js, and others. The default Raw option shows only the request and response payloads that your application needs to invoke the API and process the results. Another good use of the Raw option is that you copy the Request code, and then use it to make direct method invocations with network tools, such as Fiddler, when you want to test or troubleshoot the APIs.
5.To try the API, click the Try button. This switches you to an interactive console, as
shown in Figure 11.7.
Figure 11.7 The console lets you invoke APIs and shows the request and the response.
6.Click the Get Resource button. If you haven’t signed in to Power BI, this is when you’ll be asked to do so. That’s because all the API calls happen under the identity of the signed user.
7.After some delay, you’ll get the actual request/response pair as a result of the method invocation.
If you examine the request body, you’ll see an Authorization header. The obfuscated setting after “Bearer” is where the OAuth authorization token will go with an actual
method invocation. The Response pane shows the result of the call. As you know already, the “200” response code means a successful invocation. Next, the Response section
displays the response headers and the response body (not shown in Figure 11.7). The response body includes the JSON definition of the dataset collection, with all the datasets in My Workspace.
Figure 11.8 The console let’s you pass parameters to the method, such as the dataset identifier in this example.
Working with parameters
Now let’s use the console to get a list of tables in a given dataset:
1. Scroll down the response pane and copy the GUID of the id property of the Retail Analysis Sample dataset.
1.In the navigation pane, click the Tables Collection tab. On the Tables Collection page, click the “List all Tables” link.
2.In the Console pane (see Figure 11.8), click the URI Parameters button. This method takes an id parameter, which in this case is the dataset identifier.
3.Paste the dataset identifier next to the id parameter, and then click Call Resource.
4.If the method invocation succeeds, you should get a “200” response. Then the response body should show the JSON definition of a table collection with five tables.
5.(Optional) Experiment with calling other methods, such as to create a new dataset, create a new table, and add to rows to a table.