Forum Discussion
API with Python Returns Nothing
hi
do you know how I can debug the errors I am getting with my code? I have been trying to find out why I get a bad request 400. I noticed in a SW called insomnia that if I remove any parameter from the payload I get a message from the server saying what is expecting to receive but with power BI all I get is bad request
Details:
DataSourceKind=Web
Here is my code
let
payload = "[{
""fromdate"":""2022-07-22T12:30:59.422Z"",
""todate"":""2022-07-23T12:29:59.422Z"",
""hourfilter"":-1,
""customer"":""T"",
""filters"":[{""id"":""NetworkElementID"",""value"":""9J""}],
""sortby"":[{""id"":""customer"",""desc"":true}],
""sites"":null,
""selectedbox"":null,
""currentpage"":0,
""pagesize"":25,
""teams"":""NI"",
""flagged"":false,
""dump"":true
}]",
url = "https://internal.com/apiserver/nic/dashboard/content",
Source =Json.Document(Web.Contents(url,[Content=Text.ToBinary(payload)]))
in
Source
Thank you !
I made it work!
to debug the issues I added a Web.Contents(url, [ManualStatusHandling={400..499}, Content=payload]) and then I was adding line by line in my payload and debugging the errors
It turns out that the syntax for empty filters changes from [] to {} and also the syntax for list inside the payload changed from [A="X",B="Y"] to {[A="X",B="Y"]}
I used to code in borland c++ and it was easy to debug. now wit these new technologies I struggle specially with json syntax.
fromdate= "2022-07-22T12:30:59.422Z",
todate="2022-07-23T12:29:59.422Z",
sortby={[id="customer",desc=true]},
filters={},
hourfilter=-1,
customer="T",
sites=null,
selectedbox=null,
currentpage=0,
pagesize=25,
teams="NI",
flagged=false,
dump=true
]