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
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/token
In Postman, I was able to retrieve the token with the following script in body
{
"grant_type": "client_credentials",
"client_id": "xxxxxxxxxxxxxxxx",
"client_secret": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
Hi Falcon,
Try this code
let
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