Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Sending a POST API request using PowerQuery on Excel/PBI with a request body?

I am attempting to send a POST request using an API in PowerQuery on Excel/PBI. The request requires a body, and I've tried a few different ways (see below) but I keep receiving a DataSource.Error: W...
  • Anonymous's avatar
    Anonymous
    3 years ago

    For anyone who it might help, I successfully solved this. Here is my code: 

     

    let
        url = "https://myapi.com/analytics",
        headers = [#"Content-Type"="application/json", #"X-Impersonate-User"=Impersonation_Token, Authorization="Bearer "&API_Key],
        body = "{""start_date"":""" & Start_Date &""",""end_date"":""" &End_Date &""",""time_resolution"":""" & Time_Dimension &"""}",
    response = Json.Document(Web.Contents(url,
            [
                Headers = headers,
                Content = Text.ToBinary((body))
            ])),
    in