Last active
February 20, 2021 18:34
-
-
Save jayantkodwani/f24aa577ad9c393fbfe57c19e0e4b98b to your computer and use it in GitHub Desktop.
Sentiment Azure API (M Query for PBI Custom Function)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= (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