Home > OS >  How to connect to Webservice REST with POST from Power BI
How to connect to Webservice REST with POST from Power BI

Time:06-18

I am trying to connect to a webservice through Power BI but I still do not achieve result, first try to use the Web data source and with the Advanced Use add the Header that in my case is Content-Type and its value is application/json and additional as Body I have a token

enter image description here

Where I get as a result the following:

enter image description here

Additional also try to use as source "Blank Query", where I accessed the advanced editor section and add the following Query:

enter image description here

I get as an error the following:

enter image description here

To make sure that the Webservice works correctly and obtains a result I have used the Advanced REST Client tool and I have made the following configuration:

enter image description here

Where you can see that the Headers section I have added the Header name Content-Type and the value of the Header Value is application/json, in the Body section is where I have added the token

enter image description here

With this I realize that my Webservice gets an answer and that the service is working correctly, I would like someone to give me a little guidance in a short time to perform correctly

CodePudding user response:

Supply the content to switch the method from GET to POST eg

Perform a POST against a URL, passing a binary JSON payload and parsing the response as JSON.

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

let
    url = "https://postman-echo.com/post",
    headers = [#"Content-Type" = "application/json"],
    postData = Json.FromValue([token = "abcdef"]),
    response = Web.Contents(
        url,
        [
            Headers = headers,
            Content = postData
        ]
    ),
    jsonResponse = Json.Document(response),
    json = jsonResponse[json]
in
    json

or

let
    url = "https://postman-echo.com/post",
    headers = [#"Content-Type" = "application/json"],
    postData = Text.ToBinary("{ ""token"":""abcdef""}"),
    response = Web.Contents(
        url,
        [
            Headers = headers,
            Content = postData
        ]
    ),
    jsonResponse = Json.Document(response),
    json = jsonResponse[json]
in
    json
  • Related