Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sentiment Azure API (M Query for PBI Custom Function)
= (text) => let
apikey = "<<Replace your APIKey here>>",
endpoint = "<<Replace your endpoint link here>>",
jsontext = Text.FromBinary(Json.FromValue(Text.Start(Text.Trim(text), 5000))),
jsonbody = "{ documents: [ { language: ""en"", id: ""0"", text: " & jsontext & " } ] }",
bytesbody = Text.ToBinary(jsonbody),
headers = [#"Ocp-Apim-Subscription-Key" = apikey],
bytesresp = Web.Contents(endpoint, [Headers=headers, Content=bytesbody]),
jsonresp = Json.Document(bytesresp),
sentiment = jsonresp[documents]{0}[confidenceScores]
in sentiment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment