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
I really appreciate your response on this post.
I have corrected the format but there is another error that I encountered.
Expression.Error: We cannot convert the value -1 to type Text.
Details:
Value=-1
Type=[Type]
I'm really a newbie in Power BI and your reponse is highly appreciated.
Thank you.
- gilbertendaya6 years agoHelper IV
- ImkeF6 years agoCommunity Champion
if you're body shall contain the full JSON record that you've built, then you should reference that directly instead of trying to convert it to a string in step "BuildQueryString". (You'd probably have to convert the -1 back to a number then)
Something like this:
let url = URL, body = "{#(cr)#(lf) ""limit"":-1,#(cr)#(lf) ""sort"":{#(cr)#(lf) ""option"":""ASC"",#(cr)#(lf) ""field"":[#(cr)#(lf) ""FlightDate""#(cr)#(lf) ],#(cr)#(lf) ""parameters"":[#(cr)#(lf) {#(cr)#(lf)#(cr)#(lf) }#(cr)#(lf) ],#(cr)#(lf) ""range"":[#(cr)#(lf) {#(cr)#(lf) ""FlightDate"":{#(cr)#(lf) ""from"":""02/14/2020 14:02"",#(cr)#(lf) ""to"":""02/18/2020 00:02""#(cr)#(lf) }#(cr)#(lf) }#(cr)#(lf) ]#(cr)#(lf) }}", Parsed_JSON = Json.Document(body), Source = Json.Document(Web.Contents(url, [Headers=[#"Content-Type"="application/json"],Content = Parsed_JSON])) in Source- gilbertendaya6 years agoHelper IV
Thanks ImkeF
I tried the one that you suggested, but below error occurred.Expression.Error: We cannot convert a value of type Record to type Binary.
Details:
Value=[Record]
Type=[Type]
- gilbertendaya6 years agoHelper IV
What I'm trying to achieve here is to retrieve the data from DynamoDB based on the URL and the body that I have that contains the date range.
- gilbertendaya6 years agoHelper IV
When I tried to get the data after this line:
let
url = URL,//body = "{""limit"": -1,""sort"": {""option"": ""ASC"",""field"": [""FlightDate""},""parameters"": [{}],""range"": [{""FlightDate"": {""from"": ""02/14/2020 14:02"",""to"": ""02/18/2020 00:02""}}]}",
body = "{""limit"": ""-1"",""sort"": {""option"": ""ASC"",""field"": [""FlightDate""]},""parameters"": [{}],""range"": [{""FlightDate"": {""from"": ""02/14/2020 14:02"",""to"": ""02/18/2020 00:02""}}]}",
Parsed_JSON = Json.Document(body),
BuildQueryString = Uri.BuildQueryString(Parsed_JSON)
//Source = Json.Document(Web.Contents(url, [Headers=[#"Content-Type"="application/x-www-form-urlencoded"],Content = Text.ToBinary(BuildQueryString)]))
in
BuildQueryString
The error with below already occurs:Expression.Error: We cannot convert a value of type Record to type Text.
Details:
Value=[Record]
Type=[Type]