Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago
Solved

Swagger URL for PBI Report Server

I am trying to generate a client in C# from the Swagger resful API on Power BI Report Server. In Visual Studio 2017 there is a feature where you can generate a client proxy from the Solution explorer by right-clicking the project, Add and REST API Client. In the dialog it asks for Swagger url or an existing metadata file. I have tried using http://my-server/reports/api/v2.0/, http://my-server/reports/api/v2.0/swagger.json, https://app.swaggerhub.com/apis/microsoft-rs/PBIRS/2.0/ and https://app.swaggerhub.com/apis/microsoft-rs/PBIRS/2.0/swagger.json which all generates the total useless error message "Failed to download metadata file for Microsoft Azure API App : ConsoleApp1Client".

 

API documentation: https://app.swaggerhub.com/apis/microsoft-rs/PBIRS/2.0/

Hopefully a good guide to the rest of the work: https://www.red-gate.com/simple-talk/dotnet/net-development/visual-studio-2017-swagger-building-documenting-web-apis/

 

Has anyone successfylly generated a C# client for PBIRS? If so please share!

  • mgmeyer's avatar
    mgmeyer
    8 years ago

    If you just want the JSON file you can get it from SwaggerHub here:

     

    https://app.swaggerhub.com/apis/microsoft-rs/PBIRS/2.0

     

    In the top right you'll see an arrow pointing down, click that and you should see and option to download the JSON. I just noticed that there were some codegen customisations that we missed for PBIRS but added for SSRS which may be why your getting compilation errors, I just added them in I'll try it on my end to make sure it works. However if you still want to try the editor let me know if you see any issues.

     

    Matt M.

12 Replies

  • mgmeyer's avatar
    mgmeyer
    Power BI Team

    Visual Studio uses something called AutoRest to generate there REST stubs, you can see the GitHub link here:

     

    https://github.com/Azure/AutoRest

     

    Unfortuntely the version that ships in Visual Studio has some issues and GitHub is updated more frequently than VS. If your looking to generate client proxies there are some other options you can try, for most of our testing we used either the opensource Swagger editor or the best option is to use the swagger codegen CLI. 

     

    1. Swagger Codegen - https://github.com/swagger-api/swagger-codegen It's a little more work to get setup but has the most support and can be cusotmized quite a bit.

    2. Swagger Editor - Got to http://editor.swagger.io of you copy and past the Swagger json into the editor you can export to many differant languages in the UI C# being one of them

    3. Swagger Hub - this is where we have the docs hosted and like the editor above it has export options as well but they're code gen is a few steps behind the open source one

     

    Let me know how it goes or is you have any other questions! 

     

    Thanks!

     

    Matt M.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks Matt!

       

      I found the little arrow (download client) button just by chance! It would help, and save countless hours of searching, if you could mention in some documentation how to actually use the REST API. All I have come across is just mentioning that there is an API and a bit what you can do with it. Sorry for the rant, but I have spent all day on this getting nowhere.

       

      As I said, I downloaded the generated client then opened it in VS 2017. It did not compile. Read the readme and tried running the build.bat, same thing, did not compile. I choose csharpe, and I allso tried CsharpDotNet2 but that did not compile either. The compile errors I got from csharp is lots of these:

       

      src\IO.Swagger\Model\ReportParameterDefinition.cs(65,325): error CS1750: A value of type '<null>' cannot be used as a default parameter because there are no standard conversions to type 'IO.Swagger.Model.ReportParameterState'

       

      A quick look at Swagger Codegen tells me Im going to spent one more day just getting the environment ready to output a client!?

       

      The Swagger Editor needs the json which I asked for in my original question. Where is it? How do I get that file?

       

      Sorry again and thank you for your help!

      • mgmeyer's avatar
        mgmeyer
        Power BI Team

        If you just want the JSON file you can get it from SwaggerHub here:

         

        https://app.swaggerhub.com/apis/microsoft-rs/PBIRS/2.0

         

        In the top right you'll see an arrow pointing down, click that and you should see and option to download the JSON. I just noticed that there were some codegen customisations that we missed for PBIRS but added for SSRS which may be why your getting compilation errors, I just added them in I'll try it on my end to make sure it works. However if you still want to try the editor let me know if you see any issues.

         

        Matt M.