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"
Hi Folks,
I am also using REST API to fetch the data from 3rd party using POST method, I have used the same parameters in Header, Body in postman, and it is giving me the data in JSON format, but when I am using the same thing in power query, it is giving me an error: Response Msg: Invalid APi credentials, Response code:11 & response : NULL
Please have a look in my power query below and help me what is wrong in this :-
let
ApiOwner= "XXXXXXXX",
ApiKey="XXXXXXXXXXXXXXXXXXXXXXXXX",
url = "https://dentalkart.vineretail.com/RestWS/api/eretail/v3/sku/inventoryStatus",
header= [#"Authorization" = ApiKey & ApiOwner,
#"Content-Type" = "application/x-www-form-urlencoded"],
RequestBody=
"{
""skuCodes"":""[]"",
""fromDate"":""18/06/2021 15:40:30"",
""toDate"":""23/06/2021 15:40:30"",
""pageNumber"":""1"",
""dropShipFlag"":""no"",
""locCode"":""
}",
webdata = Web.Contents(url, [Content = Text.ToBinary(RequestBody), Headers=header]),
response = Json.Document(webdata)
in
response
Any kind of help would really be appreciated !