Forum Discussion

StolzHerz's avatar
StolzHerz
Icon for Helper I rankHelper I
8 years ago
Solved

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 Tabula...
  • StolzHerz's avatar
    8 years ago

    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