Forum Discussion
M language how to get this header to work?
- 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.
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
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
- lbendlin5 years ago
Super User
No, Content are the form fields (if you want) that you are adding to the request, not as URL parameters but as a payload in the body.
In your case you seem to want to run a POST without having an actual payload. You could specify a fake payload or switch your request to GET.
- JackSoderstrom5 years ago
Helper I
Yeah, the POST request isn't sending any data it is just getting data but needs the "-X POST" to work. What type of Dummy payload would work? https://developers.notion.com/reference/post-database-query
This is the request if you are wanting more context. Im not sure why they don't just have this as a GET request but it is POST