Forum Discussion
(415) Unsupported media type error when using Power Query for POST request
I am trying to use Power Query in Power BI for a POST request, and I am getting this (415) unsupported media type error. The content has been tested in Postman (an API tester). Any help is appreciated.
let
content = "{
""spec"": {
""ids"": [""0001""],
""interval"":""HOUR"",
""expressions"": [
""CompoundChilledWaterConsumptionForecast""
],
""start"": ""2020-01-01T00:00:00.000"",
""end"": ""2020-01-02T09:00:00.000"",
""include"": ""start, end, interval, count, dates, data, timeZone, unit""
}
}",
Source = Json.Document(Web.Contents("https://engie-osep.c3iot.com/api/1/engie-osep/prod/Facility?action=evalMetrics", [Headers=[Authorization="Basic xxxxxx"], Content=Text.ToBinary(content)]))
in
Source
6 Replies
- Greg_Deckler
Community Champion
Assuming you meant 415, unsupported media type and not 414, URI too long.
Definitely does not like your headers. Maybe play with some of the optional parameters for ToBinary?
https://docs.microsoft.com/en-us/powerquery-m/text-tobinary
ImkeF edhans you guys do much with stuff like this? Is that endpoint really expecting that in binary?
- ImkeF
Community Champion
Hi
that's just a bracket at the wrong position. Try this:
let content = "{ ""spec"": { ""ids"": [""0001""], ""interval"":""HOUR"", ""expressions"": [ ""CompoundChilledWaterConsumptionForecast"" ], ""start"": ""2020-01-01T00:00:00.000"", ""end"": ""2020-01-02T09:00:00.000"", ""include"": ""start, end, interval, count, dates, data, timeZone, unit"" } }", Source = Json.Document(Web.Contents("https://engie-osep.c3iot.com/api/1/engie-osep/prod/Facility?action=evalMetrics", [Headers=[Authorization="Basic xxxxxx", Content=Text.ToBinary(content)]])) in Source- AnonymousNot applicable
Hi Imke,
thanks a lot for the answer.
But after changing to your way, I got a different error:
Expression.Error: We cannot convert a value of type Binary to type Text. Details: Value=[Binary] Type=[Type]which I think makes sense because, in your solution content is included in the header section. But content should be in the body of a POST request. Any thoughts?
- edhans
Community Champion
Sorry, I don't have much experience about this particular topic. 😐
- AnonymousNot applicable
sorry that was a typo, fixed it.
that Text.ToBinary() is something I copied from other threads. If I remove it and just pass the JSON body to Content, it gives another error.
- ImkeF
Community Champion
Yes Anonymous ,
my bad - your original syntax looks alright. Content has to be a binary value.
Just re-check the error message and if nothing different comes up that can give a hint you should use Fiddler to compare the commands that both tools send.