The Sentiment Analysis API provided by Microsoft evaluates the text input and returns a sentiment score for each document, ranging from 0 (negative) to 1 (positive). This capability is useful for detecting positive and negative sentiment in social media, customer reviews, and discussion forums. In this article, I am going to show you how to send the feedback entered in a SharePoint Online modern list item to Sentiment Analysis API and update the response back in SharePoint. Also, I am going to show how to beautify the sentiment score with emojis using column formatting feature.
Create a SharePoint list with the following columns.
At the top of the list, click Flow, and then click "Create a flow".
Select the below flow template from the right-hand panel.
Follow the instructions on the Microsoft Flow site to connect to the list we have created. Credentials will be verified for each service used in the flow. For Office 365 services such as SharePoint and Outlook, connections will be created automatically. The next steps will be performed in the Microsoft Flow designer. The first action displayed, also known as a trigger, will determine how the flow will be started. Additional actions may be added after the first. Each new action will be dependent on the previous action.
Next step is to add an initialize variable action to set the value of the current Item Id.
Create a POST request using an HTTP action. Set the HTTP Method, URI, Headers, and Body as shown below.
Note
Login to Azure and get the Ocp-Apim-Subscription-Key. Refer to this article for steps.
Now, let us parse the sentiment score from the response we received from the HTTP action and save the value in a variable using "Initialize Variable" action as shown below.
Expression : body(‘CallSentimentAPI’)[‘documents’][0][‘score’]
Here, CallSentimentAPI is the HTTP action name.
Let us update the sentiment score in the list item using a "Send an HTTP request to SharePoint" action, as shown below.
Save the flow and go back to the list.
Let us create a new item in the SharePoint list to check the sentiment score for our feedback.
If all goes well, we should see the sentiment score in the list column.
We can check the status of every execution in the flow history as shown below
To beautify the sentiment score with emojis, we can use the SharePoint column formatting feature as shown below.
I have used the following column formatting formula to convert the sentiment score into emojis.
Hope you liked this post. If you have any questions on SharePoint or office 365, please let me know.