Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago

(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

    • ImkeF's avatar
      ImkeF
      Icon for Community Champion rankCommunity 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

       

      • Anonymous's avatar
        Anonymous
        Not 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's avatar
      edhans
      Icon for Community Champion rankCommunity Champion

      Sorry, I don't have much experience about this particular topic. 😐

    • Anonymous's avatar
      Anonymous
      Not 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's avatar
        ImkeF
        Icon for Community Champion rankCommunity 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.