Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Boricuanet
Frequent Visitor

Connect API JWT

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.

2 REPLIES 2
Anonymous
Not applicable

did you manage to find a solution?

 

lbendlin
Super User
Super User

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.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.