Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hello,
I am using an API as data source for PBI. The API uses POST method to authenticate with username and password in the body of the initial request, which retrieves a JWT token. The JWT token is then used in the header of subsequent API calls to get data (again using POST).
I see an issue with how these credetials are handled as they seem to appear in plain text in the custom query code. This has to be so because in order to perform POST requests the data source authentication has to be set to Anonymous and the username and password are stored in the code. Same goes for the token. For the token this is not such a big issue because it expires relatively shortly but the initial username and password to authenticate to the API are static.
Could you recomend any solutions on how to better handle these credentials with the custom query code?
Here is an example of the initial authentication code that has to contain the username and password information.
let
//URLs
urlApi = "https://api2.eu.prismacloud.io",
pathToken = "/login",
//Get JSON Web Token via API
optionsToken = [#"Content-Type"="application/json; charset=UTF-8"],
bodyToken = "{""username"":""username_value"",""password"":""password_value""}",
responseToken = Web.Contents(urlApi & pathToken,[Headers = optionsToken,Content = Text.ToBinary(bodyToken)]),
//Get Access Token and Token Type
responseJson = Json.Document(responseToken),
// name of the token property
accessToken = responseJson[token]
in
accessToken
Hi Gao. I understand that but turning the login into a function does not do anything about securing the credentials in the code. They are still there in plain text.
Hi @5kancho ,
You need to write a separate custom query to get this token and call it in the code above.
Please see if these help:
Generate dynamic token and get data from Custom API in Power BI
Solved: Re: Web.contents unbale to authenticate with anony..
Best Regards,
Gao
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 19 | |
| 10 | |
| 9 | |
| 8 | |
| 7 |