Forum Discussion
rpboyer2
3 years agoFrequent Visitor
PowerBI REST API & Access Token with Power Query
Greetings, I'm looking for some input regarding obtaining data from the PowerBI REST API with a function to automate Access Token generation. I can get data from the API with Power Query using the f...
messes
2 years agoNew Member
Your function is working, but you are missing an item in the body. Using your example I only got returned a empty token missing the roles, when tested with JWT.ms . After adding the resource field in I started getting a working token and could reuse it (see second script block)
(Scope as text, Resource as text) =>
//I moved the other items to parameters which is why you don't see them here.
let
//POST Request
url = "https://login.microsoftonline.com/"&tenant_id&"/oauth2/token",
body = [
scope = Scope,
resource = Resource,
client_id = client_id,
client_secret=client_secret,
grant_type = "client_credentials"
],
Source = OData.Feed("https://graph.microsoft.com/beta/security/secureScores?$top=1",
[ Authorization = "Bearer " & Text.From(AccessToken("https://graph.microsoft.com/.default","https://graph.microsoft.com"))],
[ ExcludedFromCacheKey = {"Authorization"}, ODataVersion = 4, Implementation = "2.0" ]),