Forum Discussion
Create a Post request with application/x-www-form-urlencoded
- 4 years ago
Hi Anonymous
Remove the "{}" in Json.Document function. This should work.
let url = "https://entreprise.pole-emploi.fr/connexion/oauth2/access_token?realm=/partenaire", headers = [#"Content-Type" = "application/x-www-form-urlencoded", #"Accept" = "*/*"], postData = [ grant_type = "client_credentials", client_id = "PAR_xxxxx_xxxxxxxx", client_secret = "xxxxxxxxxxx", scope = "application_PAR_xxxxx_xxxxxxxx api_romev1 nomenclatureRome" ], response = Json.Document(Web.Contents(url, [ Headers = headers, Content = Text.ToBinary(Uri.BuildQueryString(postData)) ])) in responseRegards,
Jing
Hi Anonymous
Use Json.Document to replace Html.Table in your code. And wrap up text string with "" in postData body.
let
url = "https://entreprise.pole-emploi.fr/connexion/oauth2/access_token?realm=/partenaire",
headers = [#"Content-Type" = "application/x-www-form-urlencoded", #"Accept" = "*/*"],
postData = "{
""grant_type"":""client_credentials"",
""client_id"":myid,
""client_secret"":mykey,
""scope"":""application_myid api_romev1 nomenclatureRome""
}",
response = Json.Document(Web.Contents(url,
[
Headers = headers,
Content = Text.ToBinary(postData)
]), {})
in
response
Or
let
url = "https://entreprise.pole-emploi.fr/connexion/oauth2/access_token?realm=/partenaire",
headers = [#"Content-Type" = "application/x-www-form-urlencoded", #"Accept" = "*/*"],
postData = [
grant_type:"client_credentials",
client_id:myid,
client_secret:mykey,
scope:"application_myid api_romev1 nomenclatureRome"
],
response = Json.Document(Web.Contents(url,
[
Headers = headers,
Content = Text.ToBinary(Uri.BuildQueryString(postData))
]), {})
in
response
Reference:
API POST with Bearer Token - Microsoft Power BI Community
excel - Power Query, make http POST request with form data - Stack Overflow
Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.
- Anonymous4 years agoNot applicable
Hello Jing,
the first one return an error :
Expression.Error : Désolé... Nous n'avons pas pu convertir une valeur de type List en type Number. Détails : Value=[List] Type=[Type]"Cant convert List type to Number"
If i try the second solution i have another error saying "grant_type" isn't a valid identifier.
I have copy and paste theses two solution, just replacing myid and mykey with my id and my key with quote when needed.
- v-jingzhang4 years ago
Community Support
Hi Anonymous
Sorry I had a mistake in the second code. "postData" should be a record. Try this one
let url = "https://entreprise.pole-emploi.fr/connexion/oauth2/access_token?realm=/partenaire", headers = [#"Content-Type" = "application/x-www-form-urlencoded", #"Accept" = "*/*"], postData = [ grant_type = "client_credentials", client_id = myid, client_secret = mykey, scope = "application_myid api_romev1 nomenclatureRome" ], response = Json.Document(Web.Contents(url, [ Headers = headers, Content = Text.ToBinary(Uri.BuildQueryString(postData)) ]), {}) in responseBest regards,
Jing
- Anonymous4 years agoNot applicable
I still have the same error
here is what i have in my request :
let url = "https://entreprise.pole-emploi.fr/connexion/oauth2/access_token?realm=/partenaire", headers = [#"Content-Type" = "application/x-www-form-urlencoded", #"Accept" = "*/*"], postData = [ grant_type = "client_credentials", client_id = "PAR_xxxxx_xxxxxxxx", client_secret = "xxxxxxxxxxx", scope = "application_PAR_xxxxx_xxxxxxxx api_romev1 nomenclatureRome" ], response = Json.Document(Web.Contents(url, [ Headers = headers, Content = Text.ToBinary(Uri.BuildQueryString(postData)) ]), {}) in responseAnd as a result i have the same error as before "can't convert List to Number".
These informations still work in postman, i get my token with the same parameters.