How-To Guide: Sentiment Analysis

Requests

In order to start making requests, we need to decide how to make the request. API requests are made via the HTTP methods GET, POST, PUT, DELETE, AND HEAD. In our case, we will use the GET method, since our objective is to simply retrieve data without directly modifying it.

Example GET Request

An example GET request we can make to use the Sentiment Analysis API looks like this (replace # with API key):


https://watson-api-explorer.mybluemix.net/alchemy-api/calls/url/URLGetTextSentiment?apikey=#&url=http%3A%2F%2Fwww.theatlantic.com%2Fmagazine%2Farchive%2F2016%2F11%2F
the-case-for-hillary-clinton-and-against-donald-trump%2F501161%2F&outputMode=json&showSourceText=0


Pretty intimidating, right? While the URL may look like esoteric gibberish, it’s actually packed with meaningful information we can use to make calls to the API.

Let’s break it down into its individual components:

GET Request Components


Now that we have our source URL and API key in the query string, we have all the required parameters necessary to send a valid GET request.

But wait. What about &outputMode=json and &showSourceText=0 ?

These are optional parameters. Optional parameters can be appended to our GET request, allowing us to further customize what data gets accessed and how. In order to use any of these parameters, we simply add the parameter key-value pair to the GET request as such: &key=value

Optional Parameters

Optional parameters include:

In our example GET request, we have &outputMode=json and &showSourceText=0. Based off the values of our optional parameters, we now know that we will be receiving a response in JSON format and the source text will not be included in the response