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
OMG that worked, thanks SpartaBI, you're such a big help
- Falcon4 years agoHelper I
Hello SpartaBi,
Can you help me a bit further? Now I got the token, how do I use it to retrieve the data?
- SpartaBI4 years agoCommunity Champion
Hi Falcon,
With an OAuth2 token, you should probably do something like:let Token = "XXXXXXXXX", DataUri = "https://secure9.aladtec.com/XXXXXXXXX", AuthHeaders = [Authorization = "Bearer " & Token], Response = Json.Document(Web.Contents(DataUri, [Headers = AuthHeaders])) in Response
You can create a different PQ query for the second API call, or add it to the same query.
If this doesn't work, please create a new issue with details regarding the API that should retrieve the data (e.g., a successful postman request with a hardcoded token). This makes it easier for community members to locate solutions to similar problems.
Tag me (using @) in the new issue, so I'll get a notification, and I'll try to look into it.