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,
The TenantId & scope are relevant for the AAD OAuth2 flow. In your case, you probably do not need them.
Did you try changing
let body = "{
""username"" = " & tokenUserName & ",
""password"" = " & tokenPassword & "
}",to
let body = "{
""client_id"" = " & tokenUserName & ",
""client_secret"" = " & tokenPassword & "
}",?
If this doesn't help, please share the successful "get token" postman request.
- Falcon4 years agoHelper I
Yes, I did change username and password to client_id and client_secret as you suggested. I just got the error message
DataSource.Error: Web.Contents failed to get contents from 'https://xxxxxxxxxxx/mohcacc/api/v2/oauth/token' (400): Bad Request
Details:
DataSourceKind=Web
DataSourcePath=https://xxxxxxxxxxx/mohcacc/api/v2/oauth/token
Url=https://xxxxxxxxxxx/mohcacc/api/v2/oauth/tokenIn Postman, I was able to retrieve the token with the following script in body
{
"grant_type": "client_credentials",
"client_id": "xxxxxxxxxxxxxxxx",
"client_secret": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
- SpartaBI4 years agoCommunity Champion
Hi Falcon,
Try this codelet ClientId = "XXXXXX", ClientSecret = "XXXXXX", Uri = "https://xxxxxxxxxxx/mohcacc/api/v2/oauth/token", Body ="{ ""grant_type"" = ""client_credentials"", ""client_id"" = """ & ClientId & """, ""client_secret"" = """ & ClientSecret & """, }", OAuth2Response = Json.Document(Web.Contents(Uri, [Content=Text.ToBinary(Body)])) in OAuth2Response- Falcon4 years agoHelper I
Here is the code I entered
let
ClientId = "xxxxxxx",
ClientSecret = "xxxxxxxxxxxx",
Uri = "https://secure9.aladtec.com/mohcacc/api/v2/oauth/token",
Body ="{
""grant_type"" = ""client_credentials"",
""client_id"" = """ & ClientId & """,
""client_secret"" = """ & ClientSecret & """,
}",
OAuth2Response = Json.Document(Web.Contents(Uri, [Content=Text.ToBinary(Body)]))
in
OAuth2ResponseHere is what response I got
DataSource.Error: Web.Contents failed to get contents from 'https://secure9.aladtec.com/mohcacc/api/v2/oauth/token' (400): Bad Request
Details:
DataSourceKind=Web
DataSourcePath=https://secure9.aladtec.com/mohcacc/api/v2/oauth/token
Url=https://secure9.aladtec.com/mohcacc/api/v2/oauth/token