cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
dpombal Helper V
Helper V

HTTP POST request with form urlencoded data

Hi all,

 

I am trying to reproduce below API HTTP Post call , successful in Postman:

Postman configuration

  1. Authorization key with a tokensequence
  2. Body with 3 parameters and important select option x-www-form-urlencoded

 

API1.PNGHeaderAPI2.PNGParameters

 

I tried several M codes with this template and modifications

 

let
auth_key ="XXXXXXXXXXXXX",
base_url = "www.WEBPAGE.com",
extension = "/api/datos_de_recarga/chargedata.php",
url = base_url &extension,
header= [#"Authorization" = auth_key,
#"Content-Type" = "application/x-www-form-urlencoded"],
content1= "{
""LOGIN"":""USER@domain.es"",
""PASSWORD"":""PASS"",
""INICIO"":""2019-11-01T00:00:00Z""
}",
webdata1 = Web.Contents(url, [Headers=header,Content = Text.ToBinary(content1)]),
response1 = Json.Document(webdata1)
in
response1

 

 

 

All with denied access

Regards

1 ACCEPTED SOLUTION

Accepted Solutions
dpombal Helper V
Helper V

Re: HTTP POST request with form urlencoded data

This option worked finally for me, will try to make code better using parameters, but is is a good start.

 

CODE OK

let
auth_key ="XXXXXXXXXXXXXXXXXXX",
base_url = "www.hostname.com",
extension = "/api/datos_de_recarga/chargedata.php",
url = base_url &extension,
header= [#"Authorization" = auth_key,
#"Content-Type" = "application/x-www-form-urlencoded"],
content1= "LOGIN=USER@DOMAIN.es&PASSWORD=XXXXXX&INICIO=2019-11-01T00:00:00Z",
webdata1 = Web.Contents(url, [Headers=[#"Authorization" = auth_key,
#"Content-Type" = "application/x-www-form-urlencoded"],Content = Text.ToBinary(content1)]),
response1 = Json.Document(webdata1)
in
response1

View solution in original post

4 REPLIES 4
Microsoft artemus
Microsoft

Re: HTTP POST request with form urlencoded data

Try using: Uri.BuildQueryString(record) to build your query string instead of manually entering it as a string. Might be some encoding issue.

dpombal Helper V
Helper V

Re: HTTP POST request with form urlencoded data

can you assist me? i tried my characters with and without encoding...think this is not my current issue

where to use Uri.BuildQueryString(record)

Microsoft artemus
Microsoft

Re: HTTP POST request with form urlencoded data

First change

content1= "{
""LOGIN"":""USER@domain.es"",
""PASSWORD"":""PASS"",
""INICIO"":""2019-11-01T00:00:00Z""
}",

 

to

 

content1 =

[

   LOGIN = "USER@domain.es",

   PASSWORD = "PASS",

   INCIO = #datetimezone(2019, 11, 1, 0, 0, 0, 0, 0)

]

 

then change:

Text.ToBinary(content1)

with

Text.ToBinary(Uri.BuildQueryString(content1))

dpombal Helper V
Helper V

Re: HTTP POST request with form urlencoded data

This option worked finally for me, will try to make code better using parameters, but is is a good start.

 

CODE OK

let
auth_key ="XXXXXXXXXXXXXXXXXXX",
base_url = "www.hostname.com",
extension = "/api/datos_de_recarga/chargedata.php",
url = base_url &extension,
header= [#"Authorization" = auth_key,
#"Content-Type" = "application/x-www-form-urlencoded"],
content1= "LOGIN=USER@DOMAIN.es&PASSWORD=XXXXXX&INICIO=2019-11-01T00:00:00Z",
webdata1 = Web.Contents(url, [Headers=[#"Authorization" = auth_key,
#"Content-Type" = "application/x-www-form-urlencoded"],Content = Text.ToBinary(content1)]),
response1 = Json.Document(webdata1)
in
response1

View solution in original post

Helpful resources

Announcements
New Ranks Launched March 24th!

New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

‘Better Together’ Contest Finalists Announced!

‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Arun 'Triple A' Event Video, Q&A, and Slides

Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

Join THE global Microsoft Power Platform event series.

Join THE global Power Platform event series.

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors