Search code examples
powerquerypowerbi-desktoppodio

400 Bad Request when using POST request to get all items


I'm quite new to API's and Power BI, so please excuse my lack of knowledge.

I'm trying to get data from my podio application into Power BI with the Podio API through the Power Query Editor. I'm having the issue that I either get 20 results (as is the standard with the Podio API) with a GET Request, thus I cannot change the limit. Or I use a POST Request and get a 400 bad request.

This is the code where I'm getting 20 results.

let 
url = "https://api.podio.com/item/app/appid/",
  Source = Json.Document(Web.Contents(url, [Headers=[Authorization="OAuth2 AuthToken", #"Content-Type"="application/json"]]))
in
    Source

This is the code where I'm getting the 400 Bad Request. My best guess is that it goes wrong at Text.ToBinary, as I'm using an INT in the body, but I'm not sure.

let 
url = "https://api.podio.com/item/app/appid/filter/",
body = "{
  ""limit"":500
}",
Parsed_JSON = Json.Document(body),
BuildQueryString = Uri.BuildQueryString(Parsed_JSON),
  Source = Json.Document(Web.Contents(url, [Headers=[Authorization="OAuth2 AuthToken", #"Content-Type"="application/json"], Content = Text.ToBinary("PostContent")]))
in
    Source

Solution

  • First of all, if that is actually your code, Text.ToBinary is just sending the string "PostContent". Secondly if that was meant to be a placeholder reference for BuildQueryString, I don't think you would want to use Uri.BuildQueryString anyways (this is for converting certain characters to url escaped variants). You should just be able to put your text body in Text.ToBinary like:

     Source = Json.Document(Web.Contents(url, [Headers=[Authorization="OAuth2 AuthToken", #"Content-Type"="application/json"], Content = Text.ToBinary(body)]))