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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Anonymous
Not applicable

How to get data from rest API with authentication token which expires in 30 mins?

I have a rest API which when credentials are passed, a token is generated which expired in 30 mins. 
i have to pass this token to another link to get the required data.
How can i do all this inside power bi? is it possible? please help if any

1 ACCEPTED SOLUTION
Anonymous
Not applicable

i have the solution.

as every API might be different in context to headers passed, ill share what worked for me.

 

let
url = "https://api.abc.com/oauth2/token", //example for link
body = "{ ""client_id"": ""123abc123"", ""client_secret"": ""fgfgfdsefc""}", //123abc123 is client_id and fgfgfdsefc is client_secret
Parsed_JSON = Json.Document(body),
BuildQueryString = Uri.BuildQueryString(Parsed_JSON),
polichu = Json.Document(Web.Contents(url,[Headers = [#"Content-Type"="application/x-www-form-urlencoded"], Content = Text.ToBinary(BuildQueryString) ] )),
token = List.First( Record.FieldValues(polichu)), //this gave me a list of 3 records having token and other things so i had to take the first one which was token
bearer = "bearer ",
access_token = bearer & token, //combining it to text so the key is actually "bearer jsofsojdf" (something like this)

Source = Json.Document(Web.Contents("https://api.abc.com/devices/entities/devices/v1?ids=123123123", [Headers=[Authorization=access_token, Accept="application/json"]])),
resources = Source[resources],
resources1 = resources{0},
#"Converted to Table1" = Record.ToTable(resources1),
#"Transposed Table" = Table.Transpose(#"Converted to Table1"),
#"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars=true]),
#"Expanded meta" = Table.ExpandRecordColumn(#"Promoted Headers", "meta", {"version"}, {"meta.version"})
in
#"Expanded meta"

as i have attached my api working in Postman, this is a bearer token and using client id and secret - token was generated and using this token alone, i had to push it into another link to get the data. and this is how it works. 

 

hope this works out to everybody if requirement matches.

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

i have the solution.

as every API might be different in context to headers passed, ill share what worked for me.

 

let
url = "https://api.abc.com/oauth2/token", //example for link
body = "{ ""client_id"": ""123abc123"", ""client_secret"": ""fgfgfdsefc""}", //123abc123 is client_id and fgfgfdsefc is client_secret
Parsed_JSON = Json.Document(body),
BuildQueryString = Uri.BuildQueryString(Parsed_JSON),
polichu = Json.Document(Web.Contents(url,[Headers = [#"Content-Type"="application/x-www-form-urlencoded"], Content = Text.ToBinary(BuildQueryString) ] )),
token = List.First( Record.FieldValues(polichu)), //this gave me a list of 3 records having token and other things so i had to take the first one which was token
bearer = "bearer ",
access_token = bearer & token, //combining it to text so the key is actually "bearer jsofsojdf" (something like this)

Source = Json.Document(Web.Contents("https://api.abc.com/devices/entities/devices/v1?ids=123123123", [Headers=[Authorization=access_token, Accept="application/json"]])),
resources = Source[resources],
resources1 = resources{0},
#"Converted to Table1" = Record.ToTable(resources1),
#"Transposed Table" = Table.Transpose(#"Converted to Table1"),
#"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars=true]),
#"Expanded meta" = Table.ExpandRecordColumn(#"Promoted Headers", "meta", {"version"}, {"meta.version"})
in
#"Expanded meta"

as i have attached my api working in Postman, this is a bearer token and using client id and secret - token was generated and using this token alone, i had to push it into another link to get the data. and this is how it works. 

 

hope this works out to everybody if requirement matches.

Hi, 

The requirement exactly fits with mine. but i am getting the below error msg

Peter_Jeyaraj_I_0-1646654227367.png

 

See the complete text from Advance editor

Peter_Jeyaraj_I_1-1646654333153.png

Any idea?

V-lianl-msft
Community Support
Community Support

Hi @Anonymous ,

 

You can refer to this:https://community.powerbi.com/t5/Desktop/Issue-with-getting-data-via-API-with-bearer-token/td-p/126232 

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hi @V-lianl-msft ,

 

i tried everything in the solutions but somewhere its giving me eroors.

to give a more insight of my requirement,

my api contains - client_id and client_secret only.

using this i can get the bearer token. 

when i pass this bearer token in 'Header' as Authorization - it gives me data. there is no Auth 2.0 authorization working here.

ananthupresanth_0-1592916116057.png

Kindly Help

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

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.

March Power BI Update Carousel

Power BI Community Update - March 2026

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