Reputation: 65
I wrote Power query to post method like follows
let
url = "https://XXXXXXXXXX/OAuth/Token",
body = "{
""grant_type"": ""password"",
""client_id"": ""XXXXXXXX"",
""client_secret"": ""XXXXXXXXX"",
""redirect_uri"": ""https://XXXXXXX/home/"",
""username"": ""user"",
""password"": ""password""
}",
Source = Json.Document(Web.Contents(url,
[
Headers = [#"Content-Type"="application/x-www-form-urlencoded"],
Content=Text.ToBinary(body)
]
)
),
#"Converted to Table" = Record.ToTable(Source)
in
#"Converted to Table"
But iam getting 400 bad request error like
DataSource.Error: Web.Contents failed to get contents from 'https://XXXXX/OAuth/Token' (400): Bad Request
Details:
DataSourceKind=Web
DataSourcePath=https://XXXXXXX/OAuth/Token
Url=https://XXXXXXXXXX/OAuth/Token
When I tried using postman I am getting 200 Ok status . Whats the main error in my PQL code?
Upvotes: 2
Views: 12643
Reputation: 1530
You should send body as urlencoded strings joint by ampersand instead of JSON
So body should look like this
body="grant_type=password&client_id=XXXXXXXX&client_secret=XXXXXXXXX&redirect_uri=https%3A%2F%2FXXXXXXX%2Fhome%2F&username=user&password=password"
Look at this - Power Query, make http POST request with form data
Upvotes: 3