Connecting to an API is all very well but it’s very important that a custom connector delivers data in a format that is modelled appropriately for Power BI, and very few APIs do this on their own.Are you sure the published Open API definition file will get updated when the API changes, though? What if it doesn’t, or there is an error in it? This means that whenever the published Open API definition file is updated the custom connector also updates automatically. In this case I embedded the Open API definition file in the project but it’s also possible to download it dynamically using Web.Contents().As you’ll find if you try this, not everything ‘just works’ – there are a few functions that return errors. It looks super-easy to build a custom connector this way, but is it a actually good idea? I can see a few pros and cons: Once you build your custom connector, you see all of the endpoints (or at least those that support GET and POST requests) exposed as functions in the Navigation table: PBISwagger = Extension.Contents("PBISwagger.json"), OAuthCredential = Extension.CurrentCredential(), Here’s the M function definition from my demo project showing how to do this: The last problem to solve is that OpenApi.Document() only supports basic and anonymous authentication by default, so support for OAuth2 has to be handled using the ManualCredentials option. You can then use the Extension.Contents() M function to read the contents of the file in code and pass that to OpenApi.Document(). json file and add it to your Visual Studio custom connector project and set the Build Action property of the file to Compile: The Power BI REST API uses Azure Active Directory authentication and handling AAD authentication in custom connectors is well documented here Miguel’s sample shows how to adapt this code for Power BI.Īfter that, just download the Power BI REST API definition, save it as a. However the Power BI REST API has a lot of endpoints so writing code to support them all would be extremely time-consuming, and there is another option: using the new OpenApi.Document() M function – only available for custom connectors, and not in Power BI Desktop or Excel – to read the API definition from an Open API (aka Swagger) definition file.įull documentation and samples for using OpenApi.Document are available here, and an Open API definition file for the Power BI REST API is available here. The idea of creating a Power BI custom connector for the Power BI REST API is not a new one: Miguel Escobar wrote one earlier this year (see here for the source code and documentation).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |