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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
YasirKazi77
Frequent Visitor

Use api token from text file in connection query

Hi,

I am getting data from an API that requires an authorization token to be passed in the connection string. Since the token needs to be renewed every 7 days, I want to read the token from a text file and reference that in the connection string (making it easier to replace the token)

I am able to read the token from the text file.

YasirKazi77_0-1675609490063.png

I read the token and store it in a variable "MyToken"

YasirKazi77_1-1675609599711.png

 

When I use the variable in a connection string  :

YasirKazi77_2-1675609645880.png

I get this error :

YasirKazi77_3-1675609668329.png

 

Any idea what I can do to fix the issue?

1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @YasirKazi77 ,

 

You can right click your token column and Add as New Query. Then create a parameter suggested value as Query and use the Token Query. Then use the Parameter in your api query.

For more details you can refer to below video, it will show you how to generate the token in Power BI and then add the token into your api query for authentication dynamiclly.

Video:https://www.youtube.com/watch?v=N8qYRSqRz84

 

Best Regards,
Rico Zhou

 

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

View solution in original post

3 REPLIES 3
v-rzhou-msft
Community Support
Community Support

Hi @YasirKazi77 ,

 

You can right click your token column and Add as New Query. Then create a parameter suggested value as Query and use the Token Query. Then use the Parameter in your api query.

For more details you can refer to below video, it will show you how to generate the token in Power BI and then add the token into your api query for authentication dynamiclly.

Video:https://www.youtube.com/watch?v=N8qYRSqRz84

 

Best Regards,
Rico Zhou

 

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

Thanks Amit. I see that the solution you mentioned involves hard coding the username and password into the script , something that I want to avoid.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.