Forum Discussion
API error 415: Unsupported Media Type
the way M works you need to get address to the status where it could be opened in the browser with desired result
https://docs.microsoft.com/en-us/powerquery-m/web-contents
Web.Contents("www.microsoft.com") equals The binary contents from the URL www.microsoft.com when accessed via HTTP
I think in this case you could try with something like this:
postAuth = Web.Contents(
authURL,
[username="XXX",
password="YYY"]
)or
postAuth = Web.Contents(
authURL & "username=XXX&password=YYY"
)if you can get it working in that format then taking the references from JSON is trivial
I'm afraid I cannot help more without any documentation on the API itself
Hi Stachu,
First let me say thank you for taking the time to help me with this. I deeply appreciate it.
Web.Contents() by default is uses the GET method. However, my API requires that you POST some JSON containing your username/password. Using your first suggestion below results in an error because [username="xxx", password="yyy"] is not one of the arguments that Web.Contents() accepts. I am specifically using the Content=[] argument because that changes the Web.Contents method from GET to POST, which is what I need to do (see prior link for reference). The authentication JSON needs to be in the body, which is why I'm not using Header or paramaters.
Your suggestion did make me think that perhaps I need to nest Web.Contents: once to POST and then once to GET. I've been trying that, but no luck so far.
- Stachu7 years agoCommunity Champion
Chris Webb did bunch of articles on the API handling in Power Query
https://blog.crossjoin.co.uk/2014/03/26/working-with-web-services-in-power-query/there are some examples there, so maybe it will help you get the proper syntax
there is also example with POST authentication here
https://chris.koester.io/index.php/2015/07/16/get-data-from-twitter-api-with-power-query/
that uses Text.ToBinary/Binary.ToText transformations - worth giving it a try :)