Skip to content

Commit

Permalink
Add connection test to enable running on PowerBI Gateway (#21)
Browse files Browse the repository at this point in the history
* FetchPage: return error on non ok HTTP Status

* implement connection test using sites query

* Update ApiClient.pqm

Co-authored-by: Daniel Krebs <[email protected]>

---------

Co-authored-by: Daniel Krebs <[email protected]>
  • Loading branch information
denizs and daniel-k authored Dec 2, 2024
1 parent 9b580fd commit 4cbb87b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
10 changes: 9 additions & 1 deletion ApiClient.pqm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ let
queryParamsNonNull = Record.RemoveFields(combinedQueryParams, nullValueFields),
queryString = Uri.BuildQueryString(queryParamsNonNull),
apiUrlWithQueryParams = if Text.Length(queryString) > 0 then apiUrl & "?" & queryString else apiUrl,
parsedResponse = Json.Document(Web.Contents(apiUrlWithQueryParams, [Headers = headers]))
response = Web.Contents(
apiUrlWithQueryParams, [Headers = headers, ManualStatusHandling = {400, 401, 403, 404, 422, 500, 503}]
),
statusCode = Value.Metadata(response)[Response.Status],
parsedResponse =
if statusCode = 200 then
Json.Document(response)
else
error "HTTP Error: " & Text.From(statusCode) & ". Response body: " & Text.FromBinary(response)
in
parsedResponse,
FetchPaginated = (apiPath as text, cursor as nullable text, optional queryParams as nullable record) as list =>
Expand Down
5 changes: 4 additions & 1 deletion enlyze.pq
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,17 @@ shared enlyze.Contents = () =>
in
NavTable;

shared enlyze.ConnectionTest = () => enlyze.Contents(){[Key = "sites"]}[Data];

enlyze = [
Authentication = [
Key = [
Label = "ENLYZE API Key",
KeyLabel = "ENLYZE API Key"
]
],
Label = "ENLYZE"
Label = "ENLYZE",
TestConnection = (dataSourcePath) => {"enlyze.ConnectionTest"}
];

enlyze.Publish = [
Expand Down

0 comments on commit 4cbb87b

Please sign in to comment.