Forum Discussion
Get data from web error: A web API key can only be specified when a web API key name is provided
Hi Lukasz
I am trying to do something similar. I am trying to query the MS Cognitive Services Text Analytics API via the function below. As that API is asynchronous I need to extract the Operation-Location header value in order to retrieve the results. However, the Web.Contents function seems to only return Response Status.
For testing, I have modified the function to return the headers for the response metadata as per your example code but all I get is Content-Type field with a null value. Am I right in summising that it is not possible to extract response header data (except for status) and therefore this sort of processing is only possible if link/location values are retuned as content rather than in headers?
(Source as table) as any =>
let
JsonRecords = Text.FromBinary(Json.FromValue(Source)),
JsonRequest = "{ ""stopWords"": [], ""topicsToExclude"": [],""documents"": " & JsonRecords & "}",
JsonContent = Text.ToBinary(JsonRequest, TextEncoding.Ascii),
Response =
Web.Contents("https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/topics",
[
Headers = [#"Ocp-Apim-Subscription-Key"= "xxxxxxxxxxxxxxxxxxxxxxxxxx",
#"Content-Type"="application/json"],
Content=JsonContent,
ManualStatusHandling={202}
]),
ResponseMeta = Value.Metadata(Response),
ResponseStatus = ResponseMeta[Response.Status],
Output = if ResponseStatus = 200 then Json.Document(Response,1252) else ResponseMeta[Headers]
in
Output
- mllopis9 years agoCommunity Admin
Hi all,
In order to be able to supply an “Api Key” via the credential UI, the user’s M has to look like this:
Web.Contents(URL, [ApiKeyName="mykey"])
If the user enters a key of SECRET, this will produce a final URL of URL?mykey=SECRET
NOTE: this is not supported in cloud refresh.
With respect to other messages on the thread,
- There’s no way to set arbitrary HTTP request headers through the credential system.
- There’s no way to get arbitrary HTTP response headers
Hope this helps.
- Sokon9 years agoAdvocate V
Obviously, there was no OData feed-Connector available in earlier versions of PBID, right?
Because now, there is one - which doesn't mean much, because the error stays the same:
I would expect the build-in editor is able to compose correct API-Queries. If so, what do I do wrong? (Not many options here, right)
- BrentonC3 years agoHelper I
"NOTE: this is not supported in cloud refresh."
Can you point me towards the documentation that says this? I have been trying to get this working for a while, although have not come across this in the documentation. It could have saved me some time.
https://learn.microsoft.com/en-gb/powerquery-m/web-contents