Forum Discussion
Pull data fromAPI with token from multiple query, each one invalidate each other's token
- Anonymous2 years ago
For clarity, I will write the full solution here
aj1973 provided a clue to get to my solution. in this link https://www.youtube.com/watch?v=2RZkc_qrV1g&t=610s
What I need was :
- get a access_token to be generated once and stored in order to be used by the other queries.
- do not expose that token outside of those queries
What I could not do :
- have a function that request the token and call that function in each subsequent queries because each call would generate a new accesstoken and invalidate the previous one.
Solution :
- create a queries that results in a 1 row, 1 column table with the accesstoken.
- Uncheck the "enable load" on that query
this prevent this token to be accessible outside the queries and will not be accessible by anyone consulting the resulting data
- Doesn't required premium, if you leave it check, it will be consider a premium feature
- Then in each of the query that needs that token, you can get that token like this: Table.FirstValue(get_tokenQuery)
Each time a query ask for that value from that table, if that table is empty, the get_tokenQuery will run and then return the result, if the get_tokenQuery has already ran, it will simply return the token but will not generate a new token. Thus all the query can run simultaneously with the same token
Success.
Hi Anonymous
Please watch this video, it will help you out
https://www.youtube.com/watch?v=2RZkc_qrV1g&t=610s
- Anonymous2 years agoNot applicable
Hi,
Thank you for your example.
from that video I get that he is getting all his data in one simple query and gets multiples table. That is not the case for me. All of those query can not be returned via a simple api call. They each needs multiples call with different parameters. I could include all of those api calls of my 8 queries sequentially within a MASTER query and create one table for each of those results and add them into their own column, then refer to them in the next queries, one column per query and expand them. That would make the first query very hard to troubleshoot.
I could also call the api and create a table with the access token. But I don't like having the accesstoken stored inside a table. It feels like an unecessary risk. By adding
get_token2 = Table.FirstValue(get_tokenQuery),it states "Computed tables require Premium to refresh. To enable refresh, upgrade this workspace to Premium capacity"EDIT : Nevermind about the 'computed tables requites premium..." msg. I removed the "load" from the query and it's gone now.Did I miss something?
- aj19732 years agoCommunity Champion
Hi Anonymous
We are talking about Power BI REST APIs that you are trying to use, aren't they?
If so then it would be better to an App Registration, that you won't need tokens to excute your APIs
- Anonymous2 years agoNot applicable
No, it is not regarding the powerbi API. this is an third party API . I will add this information to my question.
(did I post this in the wrong part of the forum?)