Skip to content

Instantly share code, notes, and snippets.

@jayantkodwani
Last active February 20, 2021 18:34
Show Gist options
  • Save jayantkodwani/f24aa577ad9c393fbfe57c19e0e4b98b to your computer and use it in GitHub Desktop.
Save jayantkodwani/f24aa577ad9c393fbfe57c19e0e4b98b to your computer and use it in GitHub Desktop.
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