Forum Discussion
Error in getting POST request in an API
- 6 years ago
You could simply using different code.
This first example you've posted contained wrong brackets.
Why is that?
Could it be that JSON you've been using in Postman has different nesting structure?
Must your -1 be a text instead of a number?
Honestly, I've been there a couple of times to recognize that a simple typo is throwing things off.
Very had to believe that Power Query is the issue here.
Hi ImkeF
What will be the difference with the Fiddler?
In Postman, I just use Post method and the URL and then the body.
It throws the data from the database.
Not sure what will be the difference in it.
You could simply using different code.
This first example you've posted contained wrong brackets.
Why is that?
Could it be that JSON you've been using in Postman has different nesting structure?
Must your -1 be a text instead of a number?
Honestly, I've been there a couple of times to recognize that a simple typo is throwing things off.
Very had to believe that Power Query is the issue here.
- tonmcg6 years agoResolver II
It's far easier to convert your JSON to a Power Query M record and use that as the `Content` value in `Web.Contents`, like so:
let url = URL, bodyContent = [ limit = -1, sort = [ option = "ASC", field = { "FlightDate" }, parameters = {[]}, range = { [ FlightDate = [ from = "02/14/202014:02", to = "02/18/202000:02" ] ] } ] ], binaryContent = Json.FromValue(bodyContent), request = Web.Contents( url, [ Headers = [ #"Content-Type"="application/json" ], Content = binaryContent ] ), jsonResponse = Json.Document(request) in jsonResponseSome advantages:
- you can parameterize values within the record; e.g., the values for the `from` and `to` fields
- you can use native Power Query M `Record` functions to update the record easily
- you don't have to manually parse a JSON string and enclose parts of it with two double quotes ("")
- debugging your code is far easier
To convert JSON to a record in Power Query M, remember that a JSON object is a Power Query M record and a JSON array is a Power Query M list. In other words, {} = [] and [] = {}.
- gilbertendaya6 years agoHelper IV
Hi ImkeF
It seems the issue was really the way I copy and use the body from PostMan to Power BI Advanced editor.This resolves now my issue.
Thank you very much for the assistance. 🙂