Forum Discussion
Using a REST API as a data source - POST Method Only
- 8 years ago
amenne wrote:
I got the API working in Postman, attached above is the cURL.
Any help to get tihs converted to Power Query M?
Thanks!
I don't have the account of your site for testing purpose, however I think it is the same way calling a POST Power BI API. Try to add the data JSON as Content = Text.ToBinary(dataJson)]).
let url = "https://api.powerbi.com/beta/72f988bf-86f1-41af-91ab-2d7cd011db47/datasets/29f1e104-5e56-4247-8712-8f109102109f/rows?key=cZs8uA30GFpBHTi8bCSEbt2RK6fZn3QuZDnp6pgsyk1JofKe49WjSXxbBiMlqb1NXjkCb5sSHeNS52GFIxbCnA%3D%3D", body = " [ { ""VALUE"" :198.6 } ] ", Source = Web.Contents(url,[Headers = [#"Content-Type"="application/json"], Content = Text.ToBinary(body)]) in Source - Anonymous8 years ago
how could I use POST method using username and password? (my API does not accept tokens)
I am getting error 405 METHOD NOT ALLOWED on my code below.It seems username and password are not pushed inside API.
I am new to M language and not used to the correct syntax I think...let
apiUrl = "http://xxxxx",
options = [Headers =[#"Content-Type"="application/json",
#"Authorization" = "(base64-encoded username: password)"]],
Value = Web.Contents(apiUrl,options)
in
Value - Anonymous8 years ago
REST API method POST
I manage to make it work in my API using a little bit different code. POST Rest API.
My API needs full URL, and I needed to add timeout parameter. For default, Power BI has a 5 minute timout limit.
The way the timeout duration works is (day,hour,minute,second). So my code below has a 2 hours timeout limit.for authentication, my API uses login password encoded on base 64.
The command #"Authorization" = "base64-encoded user: password" did not work, so I changed to #"Authorization" = "basic dXNlcjpwYXNzd29yZA==". (there is no space after "user:", but ":" and "p" makes a useless emoji... user
assword)Where "user: password" equals to "dXNlcjpwYXNzd29yZA==", using https://www.base64encode.org/ to encode/decode.
let
url = "http://full.api/url/here/including/all/subfolders",
body = "{""parameter as date"":""2017-10-31"",
""parameter as boolean"":true,
""parameter as number"":3
}",Source = Json.Document(Web.Contents(url,[
Headers =[#"Content-Type"="application/json", #"Authorization" = "basic "],
Content = Text.ToBinary(body) , Timeout=#duration(0,2,0,0)
]
)),
in
#"Source"
amenne wrote:
So what is the syntax to have the multiple body elements?
What do you mean multiple body elements? As per my knowledge, a POST http request only has one body, in JSON/XML/form-data etc.
- Anonymous8 years agoNot applicable
how could I use POST method using username and password? (my API does not accept tokens)
I am getting error 405 METHOD NOT ALLOWED on my code below.It seems username and password are not pushed inside API.
I am new to M language and not used to the correct syntax I think...let
apiUrl = "http://xxxxx",
options = [Headers =[#"Content-Type"="application/json",
#"Authorization" = "(base64-encoded username: password)"]],
Value = Web.Contents(apiUrl,options)
in
Value- ephysthos8 years agoNew Member
I have the same probleme. Have you found a workaround ?
Thanks,
G.- Anonymous8 years agoNot applicable
yes.
check my solution for my case at the other post.