Getting started with ibm-watson-cognitive
Remarks#
This topic provides basic instructions for obtaining credentials for Watson services and provides relevant links for each service and the Watson Developer Cloud SDKs.
Watson services homepages:
- AlchemyLanguage
- AlchemyData News
- Conversation
- Discovery
- Document Conversion
- Language Translation
- Natural Language Classifier
- Natural Language Understanding
- Personality Insights
- Retrieve and Rank
- Speech to Text
- Text to Speech
- Tone Analyzer
- Tradeoff Analytics
- Visual Recognition
Versions#
Version | Release Date |
---|---|
1.0.0 | 2016-05-05 |
Getting API credentials
To authenticate to Watson services, you need credentials for each service that you plan to use. Depending on the service, you will need to pass a username and password with Basic Authentication, or you will need to pass an API key in a parameter for each request you make.
How to get credentials for a Watson service:
- Sign up for Bluemix and log in.
- Go to the service page for your desired Watson service:
- Select your desired plan, and click CREATE:
- Click the “Service Credentials” button from your service dashboard page to view your credentials. If you aren’t taken to the service dashboard automatically, go to your Bluemix dashboard and click on your desired service instance.
Calling Watson APIs with curl
Depending on the service, you will either need to use Basic Authentication with a username
and password
or pass an apikey
as a parameter in each request.
Some services also support token authentication.
GET using Tone Analyzer:
curl -X GET \
-u "username":"password" \
-d "version=2016-05-19" \
-d "text=Hey! Welcome to Watson Tone Analyzer!" \
"https://gateway.watsonplatform.net/tone-analyzer/api/v3/tone
POST using AlchemyLanguage:
curl -X POST \
-d "apikey=YOUR_API_KEY" \
-d "url=www.ibm.com" \
"https://gateway-a.watsonplatform.net/calls/url/URLGetRankedKeywords"
Using Watson Developer Cloud SDKs
The quickest way to get started with Watson services is to use the Watson Developer Cloud SDKs. The following GitHub repositories contain installation instructions and basic usage examples:
For example, here’s how to make an AlchemyLanguage API call with the Node.js SDK:
Install the SDK:
$ npm install watson-developer-cloud
Save the following code to a file (we’ll call it app.js). Make sure you replace API_KEY
with your API key.
// Instantiate the service
var AlchemyLanguageV1= require('watson-developer-cloud/alchemy-language/v1');
var alchemy_language = AlchemyLanguageV1({
api_key: 'API_KEY'
})
var parameters = {
extract: [
'entities',
'keywords'
]
url: 'https://www.ibm.com/us-en/'
};
alchemy_language.combined(parameters, function (err, response) {
if (err)
console.log('error:', err);
else
console.log(JSON.stringify(response, null, 2));
});
Run the app:
$ node app.js