Forum Discussion
JackSoderstrom
Helper I
5 years agoM language how to get this header to work?
Trying to create a custom connector but can't with this header for some reason. Not sure how to use it correctly. This works just fine as a GET request shared Connector.Contents = () =>
...
- 5 years ago
That's not how POST works in Web.Contents()
Content: Specifying this value changes the web request from a GET to a POST, using the value of the option as the content of the POST.
lbendlin
Super User
5 years agoThat's not how POST works in Web.Contents()
Content: Specifying this value changes the web request from a GET to a POST, using the value of the option as the content of the POST.
- JackSoderstrom5 years ago
Helper I
Hey, Thank you for the reply. How do POST requests work with Web.Contents? Should I be formatting it like so?
let url = "URL", apiKey = Extension.CurrentCredential()[Key], headers = [ #"Authorization" = Text.Combine({"Bearer ", apiKey}), #"Content-Type" = "application/json ; charset=utf-8", #"Version" = "2021-08-16" ], request = Web.Contents(url, [ Headers = headers, ManualCredentials = true , Content = Text.ToBinary("POST")]) in request;I Get a 400 Bad Request with this
- lbendlin5 years ago
Super User
instead of
Content = Text.ToBinary("POST")you need to specify the actual payload
Content = Text.ToBinary(payload)Here is an example of how to structure the payload string
M Query to use POST method on a Web API - Microsoft Power BI Community
- JackSoderstrom5 years ago
Helper I
Thank you for the reply, Is Content what you are wanting out of the request? If so when running this curl command
curl -X POST 'URL' \ -H 'Authorization: Bearer KEY' \ -H 'Version: 2021-08-16' \ -H "Content-Type: application/json" \I get this
Is there a way to grab the entire object to then go through it? or Can I just grab "results"? Ive tried to write the payload but haven't been able to get it to work. Thank you again