ibm-watson-cognitive

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:

Versions#

VersionRelease Date
1.0.02016-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:

  1. Sign up for Bluemix and log in.
  2. Go to the service page for your desired Watson service:
  3. Select your desired plan, and click CREATE:

Bluemix service catalog page

  1. 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.

Location of credentials on your Bluemix service dashboard

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 

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow