Forum Discussion
Connect API oauth2 to pull data
- 4 years ago
Falcon
I've just noticed that the json was malformed + I've added a relative path for the auth.
Try this:let ClientId = "XXXXXXX", ClientSecret = "XXXXXXX", Uri = "https://secure9.aladtec.com/", Body ="{ ""grant_type"": ""client_credentials"", ""client_id"": """ & ClientId & """, ""client_secret"": """ & ClientSecret & """ }", OAuth2Response = Web.Contents(Uri, [RelativePath = "mohcacc/api/v2/oauth/token", Content=Text.ToBinary(Body)]) in OAuth2Response
Hi Falcon,
You'll need to use the M function Web.Contents in Power Query in order to call a rest API.
There are many examples of how to perform an OAuth2 flow in Power BI throughout the web.
For example (this one is using a user delegation- but you'll get the idea): https://www.linkedin.com/pulse/accessing-api-oauth2-using-m-language-power-bi-diogenes-santos
- Falcon4 years agoHelper I
I followed the instructions, but I got "400 Bad Request" from the token URL from the script. Do you know why? I am sure that URL is correct. Below is what I got
DataSource.Error: Web.Contents failed to get contents from 'https://xxxxxxxxxxxx/oauth/token' (400): Bad Request
Details:
DataSourceKind=Web
DataSourcePath=https://xxxxxxxxxxxx/oauth/token
Url=https://xxxxxxxxxxxx/oauth/token