Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
StolzHerz
Helper I
Helper I

REST API on PBIRS on-prem Oct 2017: Update PowerBIReports DataSources

Hello

 

I used the REST API to update Power BI Reports with a C# Application, but I had no luck with updating the PowerBIReport DataSource. I have a connection to an on-prem Anaysis Services Tabular.

 

I tried it as it is described here: https://app.swaggerhub.com/apis/microsoft-rs/PBIRS/2.0#/

 

Sections:

GET /PowerBIReports({Id})/DataSources   --> Works fine

PATCH  /PowerBIReports({Id})/DataSources   --> NO LUCK, always (400) Bad Request.

PUT instead of PATCH gives (405) Method Not Allowed

 

Are there C# examples? For me, just the Swagger is not enough to understand what I have to do...

 

Greetings,

Roli

 

1 ACCEPTED SOLUTION
StolzHerz
Helper I
Helper I

OK, here my experiences with the Swagger on 2018-02-03 (can vary if you do it after that date because of updates)

 

Create IO.Swagger Assembly

  • Go to https://app.swaggerhub.com/apis/microsoft-rs/PBIRS/2.0
  • Ignore Error Message on Website: "Semantic error at parameters.LargeFileMultipartFile"
  • Download (green arrow on top right corner) the Client, csharp. Unzip it
  • Open Solution IO.Swagger.sln (I use VS 2015)
  • Note: There are missing references in both projects.
    • In VS 2015, got to menu "Tools", "NuGet Package Manager", "Package Manager Console"
    • There is a message "Some NuGet packages are missing from this solution". Click on "Restore". This donwloads the packages and adds the folder "packages" to your solution folder structure, containing "Newtonsoft.Json.10.0.3", "NUnit.2.6.4", "RestSharp.105.1.0"
    • In the two projects, go to the missing references (RestSharp, nunit.framework) and set property "Copy Local = true"
  • Build the solution with F6
    • you get a lot of errors. Fix that:
    • Error: "'xy.ToJson()': cannot override inherited member...". Declare methods as virtual so that they can be overridden:
      • CatalogItem.ToJson():
        • public virtual string ToJson()
      • ManifestItem.ToJson()

        • public virtual string ToJson()

    • Error: "The name 'BaseValidate' does not exists in the current context"
      • Outcomment all the mentioned methods in many classes:
        • //IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
          //{
          //    foreach(var x in BaseValidate(validationContext)) yield return x;
          //    yield break;
          //}
  • Build the solution with F6
    • successful
  • Now build the solution like it is described in the README.md 
    • That gives you a folder "bin" in your soltion folder with 4 files:
      • IO.Swagger.dll
      • IO.Swagger.xml
      • Newtonsoft.Json.dll
      • RestSharp.dll

Use IO.Swagger Assembly in your Application

  • Add referenced to this three dll files
  • In your  source code, do this (as example to get all Catalog Items):
  • Add usings

 

using IO.Swagger.Api;
using IO.Swagger.Client;
using IO.Swagger.Model;
using RestSharp;

 

  • Code
var clientCI = new CatalogItemsApi(apiString);
clientCI.Configuration.ApiClient.RestClient.Authenticator = new NtlmAuthenticator(CredentialCache.DefaultCredentials);
ODataCatalogItems cItems = clientCI.GetCatalogItems();

 

Updating PowerBIReports DataSources

//Get PowerBIReport
var clientPBIR = new PowerBIReportsApi(apiString);
clientPBIR.Configuration.ApiClient.RestClient.Authenticator = new NtlmAuthenticator(CredentialCache.DefaultCredentials);
PowerBIReport pbir = clientPBIR.GetPowerBIReport(id);

//Update ConnectionString
ODataDataSources odataDS = clientPBIR.GetPowerBIReportDataSources(id);
odataDS.Value[0].ConnectionString = "..." //To be replaced
clientPBIR.UpdatePowerBIReportDataSource(id, odataDS.Value);

 

Happy coding!

Roli

 

View solution in original post

2 REPLIES 2
StolzHerz
Helper I
Helper I

OK, here my experiences with the Swagger on 2018-02-03 (can vary if you do it after that date because of updates)

 

Create IO.Swagger Assembly

  • Go to https://app.swaggerhub.com/apis/microsoft-rs/PBIRS/2.0
  • Ignore Error Message on Website: "Semantic error at parameters.LargeFileMultipartFile"
  • Download (green arrow on top right corner) the Client, csharp. Unzip it
  • Open Solution IO.Swagger.sln (I use VS 2015)
  • Note: There are missing references in both projects.
    • In VS 2015, got to menu "Tools", "NuGet Package Manager", "Package Manager Console"
    • There is a message "Some NuGet packages are missing from this solution". Click on "Restore". This donwloads the packages and adds the folder "packages" to your solution folder structure, containing "Newtonsoft.Json.10.0.3", "NUnit.2.6.4", "RestSharp.105.1.0"
    • In the two projects, go to the missing references (RestSharp, nunit.framework) and set property "Copy Local = true"
  • Build the solution with F6
    • you get a lot of errors. Fix that:
    • Error: "'xy.ToJson()': cannot override inherited member...". Declare methods as virtual so that they can be overridden:
      • CatalogItem.ToJson():
        • public virtual string ToJson()
      • ManifestItem.ToJson()

        • public virtual string ToJson()

    • Error: "The name 'BaseValidate' does not exists in the current context"
      • Outcomment all the mentioned methods in many classes:
        • //IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
          //{
          //    foreach(var x in BaseValidate(validationContext)) yield return x;
          //    yield break;
          //}
  • Build the solution with F6
    • successful
  • Now build the solution like it is described in the README.md 
    • That gives you a folder "bin" in your soltion folder with 4 files:
      • IO.Swagger.dll
      • IO.Swagger.xml
      • Newtonsoft.Json.dll
      • RestSharp.dll

Use IO.Swagger Assembly in your Application

  • Add referenced to this three dll files
  • In your  source code, do this (as example to get all Catalog Items):
  • Add usings

 

using IO.Swagger.Api;
using IO.Swagger.Client;
using IO.Swagger.Model;
using RestSharp;

 

  • Code
var clientCI = new CatalogItemsApi(apiString);
clientCI.Configuration.ApiClient.RestClient.Authenticator = new NtlmAuthenticator(CredentialCache.DefaultCredentials);
ODataCatalogItems cItems = clientCI.GetCatalogItems();

 

Updating PowerBIReports DataSources

//Get PowerBIReport
var clientPBIR = new PowerBIReportsApi(apiString);
clientPBIR.Configuration.ApiClient.RestClient.Authenticator = new NtlmAuthenticator(CredentialCache.DefaultCredentials);
PowerBIReport pbir = clientPBIR.GetPowerBIReport(id);

//Update ConnectionString
ODataDataSources odataDS = clientPBIR.GetPowerBIReportDataSources(id);
odataDS.Value[0].ConnectionString = "..." //To be replaced
clientPBIR.UpdatePowerBIReportDataSource(id, odataDS.Value);

 

Happy coding!

Roli

 

Anonymous
Not applicable

could you help me some tips? how to upload a pdix file to the power BI server in the 

using IO.Swagger.Api;
using IO.Swagger.Client;
using IO.Swagger.Model
var clientCI = new CatalogItemsApi(apiString);
clientCI.Configuration.ApiClient.RestClient.Authenticator = new NtlmAuthenticator(CredentialCache.DefaultCredentials);
clientCI  .upload()//how to use the api? thanks very much

 

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.