Script to Pull Report into PowerBI
Hi All -
Wanted to share a script that I built to help with pulling in data directly into PowerBI. Note - you do not need Python or Postman. Just add to a blank query in PowerBI and update accordingly.
let
// Get the bearer token
auth_url = "https://api.app.wdesk.com/iam/v1/oauth2/token",
client_id = "insert client_id here between quotes",
client_secret = " insert client_secret here between quotes ",
body = "grant_type=client_credentials&client_id=" & client_id & "&client_secret=" & client_secret,
auth_headers = [#"Content-Type"= "application/x-www-form-urlencoded"],
auth_response = Web.Contents(auth_url, [Headers=auth_headers, Content=Text.ToBinary(body)]),
auth_json = Json.Document(auth_response),
access_token = auth_json[access_token],
// Set the parameters for the API request
wdesk_base_url = "https://api.app.wdesk.com/platform/v1/graph/",
report_id = "insert report_id here between quotes ",
report_format = "/csv",
url = wdesk_base_url & "reports/" & report_id & report_format,
// Make the API request using the bearer token
api_headers = [
Authorization = "Bearer " & access_token,
Accept = "text/csv"
],
response = Web.Contents(url, [Headers=api_headers]),
// Convert the response to a CSV table
csv = Csv.Document(response,[Delimiter=",", Encoding=65001, QuoteStyle=QuoteStyle.None]),
#"Promoted Headers" = Table.PromoteHeaders(csv, [PromoteAllScalars=true])
in
#"Promoted Headers"
Commenti
2 commenti