I found it quite straightforward by registering the app with Azure AD and getting the Client ID string from that.
Then you just use the client ID to get an authorisation token, and use the token in any Power BI API requests.
So if I wanted to create a dataset I first get a token using my client ID, see the GetToken() example here.
When I have the token I can create a dataset like this (I use the RestSharp package to make REST API calls easier)
public string CreateDataset(string token, string json) { string Resource = "v1.0/myorg/datasets"; IRestResponse Response = RestRequest(token, Resource, json, Method.POST); return Response.Content; }
The RestRequest method:
public IRestResponse RestRequest(string token, string resource, string Json, RestSharp.Method HttpMethod) { //string PowerBIApiAddRowsUrl = String.Format("https://api.powerbi.com/v1.0/myorg/datasets/{0}/tables/{1}/rows", datasetId, tableName); var client = new RestClient("https://api.powerbi.com"); var request = new RestRequest(resource, HttpMethod); request.AddParameter("Authorization", String.Format("Bearer {0}", token), ParameterType.HttpHeader); request.AddParameter("application/json; charset=utf-8", Json, ParameterType.RequestBody); request.RequestFormat = DataFormat.Json; IRestResponse response = client.Execute(request); return response; }
The json passed in should be of the form that the API is expecting to define a dataset, as described here. Basically it's just:
{\"name\": \"SalesMarketing\"}
That returns an ID string that you could further use to add tables to the dataset.