Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

power query 400 bad request

I have a power query like this, and it gives me this 400 bad request error when I try to exec it. Any help would be 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 xxxxxxx"]]))
in
    Source

 

 

  • Hi Anonymous ,

     

    It seems you want to post a request, we need to ues Contens record in Web.Contents as following:

     

    let
        ContentBody = "{
        ""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://URL/api/1/engie-osep/prod/Facility?action=evalMetrics", [Headers=[#"Authorization"="Basic xxxxxxx"], Contens=ContentBody]))
    in
        Source

     

    Please refer to following document about Web.Contents function:

    https://docs.microsoft.com/en-us/powerquery-m/web-contents


    Best regards,

     

2 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    Well,

     

    The 400 Bad Request error is an HTTP status code that means that the request you sent to the website server, often something simple like a request to load a web page, was somehow incorrect or corrupted and the server couldn't understand it.

     

    I imagine it has something to do with the Headers you are sending.

  • v-lid-msft's avatar
    v-lid-msft
    Community Support

    Hi Anonymous ,

     

    It seems you want to post a request, we need to ues Contens record in Web.Contents as following:

     

    let
        ContentBody = "{
        ""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://URL/api/1/engie-osep/prod/Facility?action=evalMetrics", [Headers=[#"Authorization"="Basic xxxxxxx"], Contens=ContentBody]))
    in
        Source

     

    Please refer to following document about Web.Contents function:

    https://docs.microsoft.com/en-us/powerquery-m/web-contents


    Best regards,