The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
Dear PowerBi community
I have the following problem. My experience in API's is quite devil.
My current problem is how can I connect JWT API's through PowerBi.
I have the following data;
(The documentation of API usage--> https://automation.trendmicro.com/apex-central/api )
Application name: | |
Application ID: | XXXXXX-XXXX-4F8A-XXXXX-XXXXXD5BE6 |
API key: | XXXXXX-4A7B-XXXXX-81C9-XXXXXE58623D |
API type: | Isolate/Restore endpoint connections |
Communication time-out: | 120 S. |
I have tried the following scripts and have not achieved positive results.
let
GetJson = Web.Contents("https://mydomain.co.uk/api/token",
[
Headers = [#"Content-Type"="application/x-www-form-urlencoded"],
Content = Text.ToBinary("grant_type=password&username=" &Username&"&password="&Password&"&clienttype=User")
]
),
FormatAsJson = Json.Document(GetJson),
#"Converted to Table" = Record.ToTable(FormatAsJson),
access_token = #"Converted to Table"{0}[Value]
in
access_token
let
//URLs
api_url = "", //Insert your API endpoint
token_url ="", //Insert your token URL
//Client credentials
client_credentials = "grant_type=" &grant_type& "&username=" &username& "&password="&password&"&clienttype=User",
//Get JSON Web Token via API
EncodedCredentials = "Basic "& Binary.ToText(Text.ToBinary(client_id & ":" & client_secret), BinaryEncoding.Base64),
Token_Response = Web.Contents(token_url, [Headers=
[Authorization=EncodedCredentials, #"Content-Type"="application/x-www-form-urlencoded;charset=UTF-8"],
Content=Text.ToBinary(client_credentials)]),
//Get Access Token and Token Type
FormatAsJson = Json.Document(Token_Response),
TypeToken = FormatAsJson[token_type],
AccessToken = FormatAsJson[access_token],
//Format Token
AccessTokenHeader = TypeToken & " " & AccessToken,
//Get Data
GetJsonQueryAPI = Csv.Document(Web.Contents(api_url, [Headers=[Authorization=AccessTokenHeader]]),[Delimiter=";",
Encoding=1252, QuoteStyle=QuoteStyle.None])
in
GetJsonQueryAPI
I am grateful for any help.
did you manage to find a solution?
Troubleshoot it step by step. First make sure that you can reliably get a bearer token. Then check the token at jwt.io to make sure it has the right scope. Only then continue with your attempt to retrieve data.