I always get the following error when trying to make a POST request:
DataSource.Error: Web.Contents failed to get contents from 'http://3.93.175.1/api/abfrage/' (400): Bad Request
Details:
DataSourceKind=Web
DataSourcePath=http://3.93.175.1/api/abfrage
Url=http://3.93.175.1/api/abfrage/
My query is the following:
let
Source = Json.Document(Web.Contents("http://3.93.175.1/api/abfrage/", [Headers=[#"Content-Type"="application/json", Authorization="Token d04b033d7fa9760147aa32743284ace16de2bbd0"], Content=Json.FromValue({[number_of_requests=1, search_term="Transalb"]})]))
in
Source
The Token is valid in case you want to check it out for yourself.
What I dont understand is that I get the right response when using this online API testing tool:
POST /api/abfrage/ HTTP/1.1
Host: 3.93.175.1
Authorization: Token d04b033d7fa9760147aa32743284ace16de2bbd0
Content-Type: application/json
Content-Length: 52
{"number_of_requests":"1",
"search_term":"Transalb"}
works like a charm:
Server: nginx/1.21.6
Date: Sat, 28 May 2022 03:55:51 GMT
Content-Type: application/json
Content-Length: 48708
Connection: keep-alive
Vary: Accept
Allow: GET, POST, HEAD, OPTIONS
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
Referrer-Policy: same-origin
{"Jahresabschluss zum Gesch\u00e4ftsjahr vom 01.01.2020 bis zum 31.12.2020": {"date": "2022-03-09T00:00:00", "name": "Jahresabschluss zum Gesch\u00e4ftsjahr vom 01.01.2020 bis zum 31.12.2020", "company": "Transalb K\u00fchl- und Express-GmbH", "report": "<!DOCTYPE html>\n<html lang=\"de\" data-signedin=\"nein\" data-siteid=\"3\">\n<head><script type=\"text/javascript\"}}
Hope you can help me. If you need any more info, just shout.
CodePudding user response:
Figured it out on my own finally, thanks to this great post:
https://community.powerbi.com/t5/Power-Query/Json-FromValue/td-p/1248394
Just needed to change my request to the following:
let
Source = Json.Document(Web.Contents("http://3.93.175.1/api/abfrage/", [Headers=[Authorization="Token 6bcc8706f68d3635f1514ce22611e83c12b1e4c1", #"Content-Type"="application/json"], Content=Json.FromValue([number_of_requests="1", search_term="Transalb"])]))
in
Source