How to send the POST request in a PowerQuery?

When working with the PowerBI, you can easily consume the data from the REST service by using a Web connector. The problem with this is that the GET Http method is automatically used for this purpose. That is logical, because PowerBI should consume the data (GET) and not do some updates.

Unfortunately in the real life, services are more complex than just getting weather data or similar. I have in my projects very often very complex queries. That means that such queries in a REST service can only be designed by using the POST Http method, which is NOT supported by the PowerBI designer.
The good news is that you can send POST request, but in the Power Query only.

Following code snippet shows the complex query of an enterprise service that requires the query in the body of the POST request and ApiKey authentication in the header.

let

SvcUrl = "https://****",

ApiKey = "*****",

Content = "
{
 
  ""Tenant"": daenet"",
  ""filter"": {
    ""fields"": [
      {
        ""fieldName"": ""Field1"",
        ""operator"": 0,
        ""argument"": [
          ""003""
        ],
        ""distinct"": false
      }
    ]
  },
  ""fields"": [
    ""ProjectedField1"",""ProjectedField2"", ""EngTyp"", ""Name""
  ],
  ""top"": 100,
  ""skip"": 0,
  ""language"": ""001""
}
",

Response= Web.Contents(SvcUrl, 

[
Content=Text.ToBinary(Content),
Headers=[ApiKey=ApiKey, #"Content-Type" = "application/json"]
]
),

Json = Json.Document(Response)

in

  Json

Hope this helps.


comments powered by Disqus