Forum Discussion

gilbertendaya's avatar
gilbertendaya
Helper IV
6 years ago
Solved

Error in getting POST request in an API

Hi,

 

Need your help with my issue in Power BI.

Here is the M-Script

 

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""}}]}",
Parsed_JSON = Json.Document(body),
BuildQueryString = Uri.BuildQueryString(Parsed_JSON),
Source = Json.Document(Web.Contents(url, [Headers=[#"Content-Type"="application/json"],Content = Text.ToBinary(BuildQueryString)]))
in
Source

 

But I'm encountering this error:

 

DataFormat.Error: We found an invalid array in JSON input.
Details:
Value=
Position=60

 

What is the problem on this? Please advise.

 

ImkeF tonmcg 
Thank you.

  • ImkeF's avatar
    ImkeF
    6 years ago

    Hi gilbertendaya 

    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.

     

20 Replies

  • This is working well in Postman but when I translate it to Power BI, the error occurs. I have set a parameter for the URL.

      • gilbertendaya's avatar
        gilbertendaya
        Helper IV

        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.

  • srinivaspappu's avatar
    srinivaspappu
    Frequent Visitor

    Hello All,

     

    Can I use M script to make a call to a .NET URL in POST method, by passing the selected filter values of PowerBI report, as JSON / any object format ? Please suggest.

     

    Thanks,

    Srinivas Pappu.