Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
Hey folks, I hope I can get some help with an issue I am facing.
I am retrieving data from an API that uses JWT token for authentication. So I have to make 2 requests:
1. To login and get the token.
//Get JSON Web Token via API
optionsToken = [#"Content-Type"="application/json; charset=UTF-8"],
bodyToken = "{""username"":""real_username"",""password"":""real_password""}",
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]
2. Make the data request with the token
//Get Data
optionsData = [#"Content-Type"="application/json; charset=UTF-8",#"x-redlock-auth"=accessToken],
postData = "{""sample_post_data""}",
responseData = Web.Contents(
urlApi & pathData,
[
Headers = optionsData,
Content = Text.ToBinary(postData)
]
),
data = Json.Document(responseData)
The API requires using POST method so I need to use Anonymous authentication and format the headers and body properly with using the `Content` option.
All of that is working fine and I am able to get the data with the data call. But when I attempt to perform any transformations on the data I get the error "We couldn't authenticate with the credentials provided.
If I go into advanced editor and copy the code with the new transform step and use it in a newly openned document it works. This is the case for any subsequent step I attempt on the data.
Solved! Go to Solution.
Hi @5kancho
You have two data sources in the same query:
urlApi & pathToken
and
urlApi & pathData
I recommend that you use the common part urlApi as the basic url in Web.Contents(), then pass pathToken and pathData to RelativePath property. This may solve the problem.
Another method you can try is to paste the first part code (To login and get the token) into a new blank query, then convert this query into a custom function.
()=>
let
//Get JSON Web Token via API
optionsToken = [#"Content-Type"="application/json; charset=UTF-8"],
bodyToken = "{""username"":""real_username"",""password"":""real_password""}",
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
Then in your original query, call this custom function in the header to get access token.
#"x-redlock-auth"=getAccessToken()
Hope this helps.
Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.
Thanks, @v-jingzhang ! I used your second suggested approach and it works well.
Hi @5kancho
You have two data sources in the same query:
urlApi & pathToken
and
urlApi & pathData
I recommend that you use the common part urlApi as the basic url in Web.Contents(), then pass pathToken and pathData to RelativePath property. This may solve the problem.
Another method you can try is to paste the first part code (To login and get the token) into a new blank query, then convert this query into a custom function.
()=>
let
//Get JSON Web Token via API
optionsToken = [#"Content-Type"="application/json; charset=UTF-8"],
bodyToken = "{""username"":""real_username"",""password"":""real_password""}",
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
Then in your original query, call this custom function in the header to get access token.
#"x-redlock-auth"=getAccessToken()
Hope this helps.
Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.