OpenApi.Document is a Power Query M function that returns a table of operations described by an Open API definition, with optional extended properties.
Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365
Syntax
OpenApi.Document(
definition as binary,
optional options as nullable record,
) as any
Description
Returns a table of operations from an Open API definition. An optional record parameter, options, may be provided to specify additional properties. The record can contain the following fields:
IncludeExtensions
: A logical (true/false). Default is true. When true, vendor extensions are included as meta record fields on the appropriate value.-
SecurityDefinition
: A text value. Defaults to the first definition which matches the accepted credential type (basic, apiKey). When specified this value overrides the security definition to use for the service. -
ManualStatusHandling
: Specifying this value as a list will prevent any builtin handling for HTTP requests whose response has one of these status codes. -
IncludeDeprecated
: A logical (true/false). Defaults to false. When true, operations that are marked as deprecated are included in the navigation table. -
IncludeMoreColumns
: A logical (true/false). Defaults to false. When true, the ‘MoreColumns’ column is enabled.
Examples
Here’s an example from Chris Webb:
shared OAuth2.OpenAPIDemo = () =>
let
OAuthCredential = Extension.CurrentCredential(),
OAuthToken = OAuthCredential[access_token],
SecurityHeaders = [Authorization = "Bearer " & OAuthToken],
PBISwagger = Extension.Contents("PBISwagger.json"),
CallWebService = OpenApi.Document(
PBISwagger,
[Headers = SecurityHeaders, ManualCredentials = true]
)
in
CallWebService
In this example, the OpenApi.Document function plays a role in integrating the Power BI REST API into the custom connector. It uses the OpenAPI (Swagger) definition file, provided as PBISwagger.json
, to automatically interpret and expose the API’s endpoints as navigable functions in Power BI.
The function takes two key inputs:
- API Definition File: The
PBISwagger
variable holds the content of thePBISwagger.json
file, which defines the structure and available endpoints of the Power BI REST API. - Options for Authentication: The
[Headers = SecurityHeaders, ManualCredentials = true]
parameter passes the security headers, including an OAuth2 token (Bearer " & OAuthToken
), to authenticate API requests securely.
Related articles
Learn more about OpenApi.Document in the following articles:
- Using OpenApi.Document() To Create A Power BI Custom Connector For The Power BI REST API
Chris Webb explains how to use the OpenApi.Document() function to create a Power BI custom connector for the REST API, making integration easier but highlighting challenges like authentication and data formatting. » Read more
2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy