Forum Discussion
Get token from Post API call
- 3 years ago
I've found a solution. See below.
let
url = "https://login.windows.net/xxx/oauth2/v2.0/token",
headers = [#"Content-Type" = "application/x-www-form-urlencoded"],
postData = "grant_type=client_credentials&scope=xxx&client_id=xxx&client_secret=xxx",
response = Web.Contents(
url,
[Headers = headers,
Content = Text.ToBinary(postData)
]
),
JsonResponse=Json.Document(response),
access_token = JsonResponse[access_token]
in
access_token
I've found a solution. See below.
let
url = "https://login.windows.net/xxx/oauth2/v2.0/token",
headers = [#"Content-Type" = "application/x-www-form-urlencoded"],
postData = "grant_type=client_credentials&scope=xxx&client_id=xxx&client_secret=xxx",
response = Web.Contents(
url,
[Headers = headers,
Content = Text.ToBinary(postData)
]
),
JsonResponse=Json.Document(response),
access_token = JsonResponse[access_token]
in
access_token
- Anonymous3 years agoNot applicable
Based on the above, I tried something very similar - e.g.:
apiUrl = 'https://login.windows.net/<tenant_id>/oauth2/v2.0/token', body = [ client_id='<client_id>', grant_type='client_credentials', client_secret='<client_secret>', scope='api://462...4e7/.default' ], Source = Json.Document(Web.Contents(apiUrl, [Headers = [Accept = 'application/json'], Content = Text.ToBinary(Uri.BuildQueryString(body))])), bearerToken = Source[access_token],but it doesn't work in PBI. PBI doesn't give any helpful debug output, so if I run the equivalent from curl, it shows:
{'error':'invalid_resource','error_description':'AADSTS500011: The resource principal named api://462...4e7 was not found in the tenant named <tenant_name>. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You might have sent your authentication request to the wrong tenant.Did you do some additional step, e.g. add an "authorized client application" to your app registration (and if so, which one - a PBI app)? add some "app permission" to your app registration (and if so, which one(s))?