Introduction

IBM Watson® Discovery is a cognitive search and content analytics engine that you can add to applications to identify patterns, trends and actionable insights to drive better decision-making. Securely unify structured and unstructured data with pre-enriched content, and use a simplified query language to eliminate the need for manual filtering of results.

This documentation describes Java SDK major version 9. For more information about how to update your code from the previous version, see the migration guide.

This documentation describes Node SDK major version 6. For more information about how to update your code from the previous version, see the migration guide.

This documentation describes Python SDK major version 5. For more information about how to update your code from the previous version, see the migration guide.

This documentation describes Ruby SDK major version 2. For more information about how to update your code from the previous version, see the migration guide.

This documentation describes .NET Standard SDK major version 5. For more information about how to update your code from the previous version, see the migration guide.

This documentation describes Go SDK major version 2. For more information about how to update your code from the previous version, see the migration guide.

This documentation describes Swift SDK major version 4. For more information about how to update your code from the previous version, see the migration guide.

This documentation describes Unity SDK major version 5. For more information about how to update your code from the previous version, see the migration guide.

The IBM Watson Unity SDK has the following requirements.

  • The SDK requires Unity version 2018.2 or later to support Transport Layer Security (TLS) 1.2.
    • Set the project settings for both the Scripting Runtime Version and the Api Compatibility Level to .NET 4.x Equivalent.
    • For more information, see TLS 1.0 support.
  • The SDK doesn't support the WebGL projects. Change your build settings to any platform except WebGL.

For more information about how to install and configure the SDK and SDK Core, see https://github.com/watson-developer-cloud/unity-sdk.

The code examples on this tab use the client library that is provided for Java.

Maven

<dependency>
  <groupId>com.ibm.watson</groupId>
  <artifactId>ibm-watson</artifactId>
  <version>11.0.0</version>
</dependency>

Gradle

compile 'com.ibm.watson:ibm-watson:11.0.0'

GitHub

The code examples on this tab use the client library that is provided for Node.js.

Installation

npm install ibm-watson@^8.0.0

GitHub

The code examples on this tab use the client library that is provided for Python.

Installation

pip install --upgrade "ibm-watson>=7.0.0"

GitHub

The code examples on this tab use the client library that is provided for Ruby.

Installation

gem install ibm_watson

GitHub

The code examples on this tab use the client library that is provided for Go.

go get -u github.com/watson-developer-cloud/go-sdk/v2@v3.0.0

GitHub

The code examples on this tab use the client library that is provided for Swift.

Cocoapods

pod 'IBMWatsonDiscoveryV2', '~> 5.0.0'

Carthage

github "watson-developer-cloud/swift-sdk" ~> 5.0.0

Swift Package Manager

.package(url: "https://github.com/watson-developer-cloud/swift-sdk", from: "5.0.0")

GitHub

The code examples on this tab use the client library that is provided for .NET Standard.

Package Manager

Install-Package IBM.Watson.Discovery.v2 -Version 7.0.0

.NET CLI

dotnet add package IBM.Watson.Discovery.v2 --version 7.0.0

PackageReference

<PackageReference Include="IBM.Watson.Discovery.v2" Version="7.0.0" />

GitHub

The code examples on this tab use the client library that is provided for Unity.

GitHub

Endpoint URLs

Identify the base URL for your service instance.

IBM Cloud URLs

The base URLs come from the service instance. To find the URL, view the service credentials by clicking the name of the service in the Resource list. Use the value of the URL. Add the method to form the complete API endpoint for your request.

The following example URL represents a Discovery instance that is hosted in Washington DC:

https://api.us-east.discovery.watson.cloud.ibm.com/instances/6bbda3b3-d572-45e1-8c54-22d6ed9e52c2

The following URLs represent the base URLs for Discovery. When you call the API, use the URL that corresponds to the location of your service instance.

  • Dallas: https://api.us-south.discovery.watson.cloud.ibm.com
  • Washington DC: https://api.us-east.discovery.watson.cloud.ibm.com
  • Frankfurt: https://api.eu-de.discovery.watson.cloud.ibm.com
  • Sydney: https://api.au-syd.discovery.watson.cloud.ibm.com
  • Tokyo: https://api.jp-tok.discovery.watson.cloud.ibm.com
  • London: https://api.eu-gb.discovery.watson.cloud.ibm.com
  • Seoul: https://api.kr-seo.discovery.watson.cloud.ibm.com

Set the correct service URL by calling the setServiceUrl() method of the service instance.

Set the correct service URL by specifying the serviceUrl parameter when you create the service instance.

Set the correct service URL by calling the set_service_url() method of the service instance.

Set the correct service URL by specifying the service_url property of the service instance.

Set the correct service URL by calling the SetServiceURL() method of the service instance.

Set the correct service URL by setting the serviceURL property of the service instance.

Set the correct service URL by calling the SetServiceUrl() method of the service instance.

Set the correct service URL by calling the SetServiceUrl() method of the service instance.

Dallas API endpoint example for services managed on IBM Cloud

curl -X {request_method} -u "apikey:{apikey}" "https://api.us-south.discovery.watson.cloud.ibm.com/instances/{instance_id}"

Your service instance might not use this URL

Default URL

https://api.us-south.discovery.watson.cloud.ibm.com

Example for the Washington DC location

IamAuthenticator authenticator = new IamAuthenticator("{apikey}");
Discovery discovery = new Discovery("{version}", authenticator);
discovery.setServiceUrl("https://api.us-east.discovery.watson.cloud.ibm.com");

Default URL

https://api.us-south.discovery.watson.cloud.ibm.com

Example for the Washington DC location

const DiscoveryV2 = require('ibm-watson/discovery/v2');
const { IamAuthenticator } = require('ibm-watson/auth');

const discovery = new DiscoveryV2({
  version: '{version}',
  authenticator: new IamAuthenticator({
    apikey: '{apikey}',
  }),
  serviceUrl: 'https://api.us-east.discovery.watson.cloud.ibm.com',
});

Default URL

https://api.us-south.discovery.watson.cloud.ibm.com

Example for the Washington DC location

from ibm_watson import DiscoveryV2
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator

authenticator = IAMAuthenticator('{apikey}')
discovery = DiscoveryV2(
    version='{version}',
    authenticator=authenticator
)

discovery.set_service_url('https://api.us-east.discovery.watson.cloud.ibm.com')

Default URL

https://api.us-south.discovery.watson.cloud.ibm.com

Example for the Washington DC location

require "ibm_watson/authenticators"
require "ibm_watson/discovery_v2"
include IBMWatson

authenticator = Authenticators::IamAuthenticator.new(
  apikey: "{apikey}"
)
discovery = DiscoveryV2.new(
  version: "{version}",
  authenticator: authenticator
)
discovery.service_url = "https://api.us-east.discovery.watson.cloud.ibm.com"

Default URL

https://api.us-south.discovery.watson.cloud.ibm.com

Example for the Washington DC location

discovery, discoveryErr := discoveryv2.NewDiscoveryV2(options)

if discoveryErr != nil {
  panic(discoveryErr)
}

discovery.SetServiceURL("https://api.us-east.discovery.watson.cloud.ibm.com")

Default URL

https://api.us-south.discovery.watson.cloud.ibm.com

Example for the Washington DC location

let authenticator = WatsonIAMAuthenticator(apiKey: "{apikey}")
let discovery = Discovery(version: "{version}", authenticator: authenticator)
discovery.serviceURL = "https://api.us-east.discovery.watson.cloud.ibm.com"

Default URL

https://api.us-south.discovery.watson.cloud.ibm.com

Example for the Washington DC location

IamAuthenticator authenticator = new IamAuthenticator(
    apikey: "{apikey}"
    );

DiscoveryService discovery = new DiscoveryService("{version}", authenticator);
discovery.SetServiceUrl("https://api.us-east.discovery.watson.cloud.ibm.com");

Default URL

https://api.us-south.discovery.watson.cloud.ibm.com

Example for the Washington DC location

var authenticator = new IamAuthenticator(
    apikey: "{apikey}"
);

while (!authenticator.CanAuthenticate())
    yield return null;

var discovery = new DiscoveryService("{version}", authenticator);
discovery.SetServiceUrl("https://api.us-east.discovery.watson.cloud.ibm.com");

Cloud Pak for Data URLs

For services installed on Cloud Pak for Data, the base URLs come from both the cluster and service instance.

You can find the base URL from the Cloud Pak for Data web client in the details page about the instance. Click the name of the service in your list of instances to see the URL.

Use that URL in your requests to Discovery v2. For Cloud Pak for Data System, use a hostname that resolves to an IP address in the cluster.

Set the URL by calling the setServiceUrl() method of the service instance. For Cloud Pak for Data System, use a hostname that resolves to an IP address in the cluster.

Set the correct service URL by specifying the serviceUrl parameter when you create the service instance. For Cloud Pak for Data System, use a hostname that resolves to an IP address in the cluster.

Set the correct service URL by specifying the url parameter when you create the service instance or by calling the set_url() method of the service instance. For Cloud Pak for Data System, use a hostname that resolves to an IP address in the cluster.

Set the correct service URL by specifying the url parameter when you create the service instance or by calling the url= method of the service instance. For Cloud Pak for Data System, use a hostname that resolves to an IP address in the cluster.

Set the correct service URL by specifying the URL parameter when you create the service instance or by calling the SetURL= method of the service instance. For Cloud Pak for Data System, use a hostname that resolves to an IP address in the cluster.

Set the correct service URL by setting the serviceURL property of the service instance. For Cloud Pak for Data System, use a hostname that resolves to an IP address in the cluster.

Set the correct service URL by calling the SetEndpoint() method of the service instance. For Cloud Pak for Data System, use a hostname that resolves to an IP address in the cluster.

Set the correct service URL by setting the Url property of the service instance. For Cloud Pak for Data System, use a hostname that resolves to an IP address in the cluster.

Endpoint example for Cloud Pak for Data

curl -X {request_method} -H "Authorization: Bearer {token}" "https://{cpd_cluster_host}{:port}/discovery/{deployment_id}/instances/{instance_id}/api"

Endpoint example for Cloud Pak for Data

CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator("https://{cpd_cluster_host}{:port}", "{username}", "{password}");
Discovery discovery = new Discovery("{version}", authenticator);
discovery.setServiceUrl("https://{cpd_cluster_host}{:port}/discovery/{deployment_id}/instances/{instance_id}/api");

Endpoint example for Cloud Pak for Data

const DiscoveryV2 = require('ibm-watson/discovery/v2');
const { CloudPakForDataAuthenticator } = require('ibm-watson/auth');

const discovery = new DiscoveryV2({
  version: '{version}',
  authenticator: new CloudPakForDataAuthenticator({
    username: '{username}',
    password: '{password}',
    url: 'https://{cpd_cluster_host}{:port}',
  }),
  serviceUrl: 'https://{cpd_cluster_host}{:port}/discovery/{deployment_id}/instances/{instance_id}/api',
});

Endpoint example for Cloud Pak for Data

from ibm_watson import DiscoveryV2
from ibm_cloud_sdk_core.authenticators import CloudPakForDataAuthenticator

authenticator = CloudPakForDataAuthenticator(
    '{username}',
    '{password}',
    'https://{cpd_cluster_host}{:port}'
)

discovery = DiscoveryV2(
    version='{version}',
    authenticator=authenticator
)

discovery.set_service_url('https://{cpd_cluster_host}{:port}/discovery/{deployment_id}/instances/{instance_id}/api')

Endpoint example for Cloud Pak for Data

require "ibm_watson/authenticators"
require "ibm_watson/discovery_v2"
include IBMWatson

authenticator = Authenticators::CLoudPakForDataAuthenticator.new(
  username: "{username}",
  password: "{password}",
  url: "https://{cpd_cluster_host}{:port}"
)
discovery = DiscoveryV2.new(
  version: "{version}",
  authenticator: authenticator
)
discovery.service_url = "https://{cpd_cluster_host}{:port}/discovery/{deployment_id}/instances/{instance_id}/api"

Endpoint example for Cloud Pak for Data

discovery, discoveryErr := discoveryv2.NewDiscoveryV2(options)

if discoveryErr != nil {
  panic(discoveryErr)
}

discovery.SetServiceURL("https://{cpd_cluster_host}{:port}/discovery/{deployment_id}/instances/{instance_id}/api")

Endpoint example for Cloud Pak for Data

let authenticator = CloudPakForDataAuthenticator(username: "{username}", password: "{password}", url: "https://{cpd_cluster_host}{:port}")
let discovery = Discovery(version: "{version}", authenticator: authenticator)
discovery.serviceURL = "https://{cpd_cluster_host}{:port}/discovery/{deployment_id}/instances/{instance_id}/api"

Endpoint example for Cloud Pak for Data

CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator(
    url: "https://{cpd_cluster_host}{:port}",
    username: "{username}",
    password: "{password}"
    );

DiscoveryService discovery = new DiscoveryService("{version}", authenticator);
discovery.SetServiceUrl("https://{cpd_cluster_host}{:port}/discovery/{deployment_id}/instances/{instance_id}/api");

Endpoint example for Cloud Pak for Data

var authenticator = new CloudPakForDataAuthenticator(
    url: "https://{cpd_cluster_host}{:port}",
    username: "{username}",
    password: "{password}"
);

while (!authenticator.CanAuthenticate())
    yield return null;

var discovery = new DiscoveryService("{version}", authenticator);
discovery.SetServiceUrl("https://{cpd_cluster_host}{:port}/discovery/{deployment_id}/instances/{instance_id}/api");

Disabling SSL verification

All Watson services use Secure Sockets Layer (SSL) (or Transport Layer Security (TLS)) for secure connections between the client and server. The connection is verified against the local certificate store to ensure authentication, integrity, and confidentiality.

If you use a self-signed certificate, you need to disable SSL verification to make a successful connection.

Enabling SSL verification is highly recommended. Disabling SSL jeopardizes the security of the connection and data. Disable SSL only if necessary, and take steps to enable SSL as soon as possible.

To disable SSL verification for a curl request, use the --insecure (-k) option with the request.

To disable SSL verification, create an HttpConfigOptions object and set the disableSslVerification property to true. Then, pass the object to the service instance by using the configureClient method.

To disable SSL verification, set the disableSslVerification parameter to true when you create the service instance.

To disable SSL verification, specify True on the set_disable_ssl_verification method for the service instance.

To disable SSL verification, set the disable_ssl_verification parameter to true in the configure_http_client() method for the service instance.

To disable SSL verification, call the DisableSSLVerification method on the service instance.

To disable SSL verification, call the disableSSLVerification() method on the service instance. You cannot disable SSL verification on Linux.

To disable SSL verification, set the DisableSslVerification method to true on the service instance.

To disable SSL verification, set the DisableSslVerification method to true on the service instance.

Example to disable SSL verification with a service managed on IBM Cloud. Replace {apikey} and {url} with your service credentials.

curl -k -X {request_method} -u "apikey:{apikey}" "{url}/{method}"

Example to disable SSL verification with a service managed on IBM Cloud

IamAuthenticator authenticator = new IamAuthenticator("{apikey}");
Discovery discovery = new Discovery("{version}", authenticator);
discovery.setServiceUrl("{url}");

HttpConfigOptions configOptions = new HttpConfigOptions.Builder()
  .disableSslVerification(true)
  .build();
discovery.configureClient(configOptions);

Example to disable SSL verification with a service managed on IBM Cloud

const DiscoveryV2 = require('ibm-watson/discovery/v2');
const { IamAuthenticator } = require('ibm-watson/auth');

const discovery = new DiscoveryV2({
  version: '{version}',
  authenticator: new IamAuthenticator({
    apikey: '{apikey}',
  }),
  serviceUrl: '{url}',
  disableSslVerification: true,
});

Example to disable SSL verification with a service managed on IBM Cloud

from ibm_watson import DiscoveryV2
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator

authenticator = IAMAuthenticator('{apikey}')
discovery = DiscoveryV2(
    version='{version}',
    authenticator=authenticator
)

discovery.set_service_url('{url}')

discovery.set_disable_ssl_verification(True)

Example to disable SSL verification with a service managed on IBM Cloud

require "ibm_watson/authenticators"
require "ibm_watson/discovery_v2"
include IBMWatson

authenticator = Authenticators::IamAuthenticator.new(
  apikey: "{apikey}"
)
discovery = DiscoveryV2.new(
  version: "{version}",
  authenticator: authenticator
)
discovery.service_url = "{url}"

discovery.configure_http_client(disable_ssl_verification: true)

Example to disable SSL verification with a service managed on IBM Cloud

discovery, discoveryErr := discoveryv2.NewDiscoveryV2(options)

if discoveryErr != nil {
  panic(discoveryErr)
}

discovery.SetServiceURL("{url}")

discovery.DisableSSLVerification()

Example to disable SSL verification with a service managed on IBM Cloud

let authenticator = WatsonIAMAuthenticator(apiKey: "{apikey}")
let discovery = Discovery(version: "{version}", authenticator: authenticator)
discovery.serviceURL = "{url}"

discovery.disableSSLVerification()

Example to disable SSL verification with a service managed on IBM Cloud

IamAuthenticator authenticator = new IamAuthenticator(
    apikey: "{apikey}"
    );

DiscoveryService discovery = new DiscoveryService("{version}", authenticator);
discovery.SetServiceUrl("{url}");

discovery.DisableSslVerification(true);

Example to disable SSL verification with a service managed on IBM Cloud

var authenticator = new IamAuthenticator(
    apikey: "{apikey}"
);

while (!authenticator.CanAuthenticate())
    yield return null;

var discovery = new DiscoveryService("{version}", authenticator);
discovery.SetServiceUrl("{url}");

discovery.DisableSslVerification = true;

Example to disable SSL verification with an installed service

curl -k -X {request_method} -H "Authorization: Bearer {token}" "{url}/v2/{method}"

Example to disable SSL verification with an installed service

CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator("https://{cpd_cluster_host}{:port}", "{username}", "{password}");
Discovery discovery = new Discovery("{version}", authenticator);
discovery.setServiceUrl("{url}";

HttpConfigOptions configOptions = new HttpConfigOptions.Builder()
  .disableSslVerification(true)
  .build();
discovery.configureClient(configOptions);

Example to disable SSL verification with an installed service

const DiscoveryV2 = require('ibm-watson/discovery/v2');
const { CloudPakForDataAuthenticator } = require('ibm-watson/auth');

const discovery = new DiscoveryV2({
  version: '{version}',
  authenticator: new CloudPakForDataAuthenticator({
    username: '{username}',
    password: '{password}',
    url: 'https://{cpd_cluster_host}{:port}',
  }),
  serviceUrl: '{url}',
  disableSslVerification: true,
});

Example to disable SSL verification with an installed service

from ibm_watson import DiscoveryV2
from ibm_cloud_sdk_core.authenticators import CloudPakForDataAuthenticator

authenticator = CloudPakForDataAuthenticator(
    '{username}',
    '{password}'
)

discovery = DiscoveryV2(
    version='{version}',
    authenticator=authenticator
)

discovery.set_service_url('{url}')

discovery.set_disable_ssl_verification(True)

Example to disable SSL verification with an installed service

require "ibm_watson/authenticators"
require "ibm_watson/discovery_v2"
include IBMWatson

authenticator = Authenticators::CLoudPakForDataAuthenticator.new(
  username: "{username}",
  password: "{password}",
  url: "https://{cpd_cluster_host}{:port}"
)
discovery = DiscoveryV2.new(
  version: "{version}",
  authenticator: authenticator
)
discovery.service_url = "{url}"

discovery.configure_http_client(disable_ssl_verification: true)

Example to disable SSL verification with an installed service

discovery, discoveryErr := discoveryv2.NewDiscoveryV2(options)

if discoveryErr != nil {
  panic(discoveryErr)
}

discovery.SetServiceURL("{url}")

discovery.DisableSSLVerification()

Example to disable SSL verification with an installed service

let authenticator = WatsonCloudPakForDataAuthenticator(username: "{username}", password: "{password}", url: "https://{cpd_cluster_host}{:port}")
let discovery = Discovery(version: "{version}", authenticator: authenticator)
discovery.serviceURL = "{url}"

discovery.disableSSLVerification()

Example to disable SSL verification with an installed service

CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator(
    url: "https://{cpd_cluster_host}{:port}",
    username: "{username}",
    password: "{password}"
    );

DiscoveryService discovery = new DiscoveryService("{version}", authenticator);
discovery.SetServiceUrl("{url}");

discovery.DisableSslVerification(true);

Example to disable SSL verification with an installed service

var authenticator = new CloudPakForDataAuthenticator(
    url: "https://{cpd_cluster_host}{:port}",
    username: "{username}",
    password: "{password}"
);

while (!authenticator.CanAuthenticate())
    yield return null;

var discovery = new DiscoveryService("{version}", authenticator);
discovery.SetServiceUrl("{url}");

discovery.DisableSslVerification = true;

Authentication

IBM Cloud services use IBM Cloud Identity and Access Management (IAM) to authenticate. With IBM Cloud Pak for Data, you pass a bearer token.

IBM Cloud

For IBM Cloud instances, you authenticate to the API by using IBM Cloud Identity and Access Management (IAM).

You can pass either a bearer token in an authorization header or an API key. Tokens support authenticated requests without embedding service credentials in every call. API keys use basic authentication. For more information, see Authenticating to Watson services.

  • For testing and development, you can pass an API key directly.
  • For production use, unless you use the Watson SDKs, use an IAM token.

If you pass in an API key, use apikey for the username and the value of the API key as the password. For example, if the API key is f5sAznhrKQyvBFFaZbtF60m5tzLbqWhyALQawBg5TjRI in the service credentials, include the credentials in your call like this:

curl -u "apikey:f5sAznhrKQyvBFFaZbtF60m5tzLbqWhyALQawBg5TjRI"

For IBM Cloud instances, the SDK provides initialization methods for each form of authentication.

  • Use the API key to have the SDK manage the lifecycle of the access token. The SDK requests an access token, ensures that the access token is valid, and refreshes it if necessary.
  • Use the access token to manage the lifecycle yourself. You must periodically refresh the token.

For more information, see IAM authentication with the SDK.For more information, see IAM authentication with the SDK.For more information, see IAM authentication with the SDK.For more information, see IAM authentication with the SDK.For more information, see IAM authentication with the SDK.For more information, see IAM authentication with the SDK.For more information, see IAM authentication with the SDK.For more information, see IAM authentication with the SDK.

IBM Cloud. Replace {apikey} and {url} with your service credentials.

curl -X {request_method} -u "apikey:{apikey}" "{url}/v2/{method}"

IBM Cloud. SDK managing the IAM token. Replace {apikey}, {version}, and {url}.

IamAuthenticator authenticator = new IamAuthenticator("{apikey}");
Discovery discovery = new Discovery("{version}", authenticator);
discovery.setServiceUrl("{url}");

IBM Cloud. SDK managing the IAM token. Replace {apikey}, {version}, and {url}.

const DiscoveryV2 = require('ibm-watson/discovery/v2');
const { IamAuthenticator } = require('ibm-watson/auth');

const discovery = new DiscoveryV2({
  version: '{version}',
  authenticator: new IamAuthenticator({
    apikey: '{apikey}',
  }),
  serviceUrl: '{url}',
});

IBM Cloud. SDK managing the IAM token. Replace {apikey}, {version}, and {url}.

from ibm_watson import DiscoveryV2
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator

authenticator = IAMAuthenticator('{apikey}')
discovery = DiscoveryV2(
    version='{version}',
    authenticator=authenticator
)

discovery.set_service_url('{url}')

IBM Cloud. SDK managing the IAM token. Replace {apikey}, {version}, and {url}.

require "ibm_watson/authenticators"
require "ibm_watson/discovery_v2"
include IBMWatson

authenticator = Authenticators::IamAuthenticator.new(
  apikey: "{apikey}"
)
discovery = DiscoveryV2.new(
  version: "{version}",
  authenticator: authenticator
)
discovery.service_url = "{url}"

IBM Cloud. SDK managing the IAM token. Replace {apikey}, {version}, and {url}.

import (
  "github.com/IBM/go-sdk-core/core"
  "github.com/watson-developer-cloud/go-sdk/discoveryv2"
)

func main() {
  authenticator := &core.IamAuthenticator{
    ApiKey: "{apikey}",
  }

  options := &discoveryv2.DiscoveryV2Options{
    Version: "{version}",
    Authenticator: authenticator,
  }

  discovery, discoveryErr := discoveryv2.NewDiscoveryV2(options)

  if discoveryErr != nil {
    panic(discoveryErr)
  }

  discovery.SetServiceURL("{url}")
}

IBM Cloud. SDK managing the IAM token. Replace {apikey}, {version}, and {url}.

let authenticator = WatsonIAMAuthenticator(apiKey: "{apikey}")
let discovery = Discovery(version: "{version}", authenticator: authenticator)
discovery.serviceURL = "{url}"

IBM Cloud. SDK managing the IAM token. Replace {apikey}, {version}, and {url}.

IamAuthenticator authenticator = new IamAuthenticator(
    apikey: "{apikey}"
    );

DiscoveryService discovery = new DiscoveryService("{version}", authenticator);
discovery.SetServiceUrl("{url}");

IBM Cloud. SDK managing the IAM token. Replace {apikey}, {version}, and {url}.

var authenticator = new IamAuthenticator(
    apikey: "{apikey}"
);

while (!authenticator.CanAuthenticate())
    yield return null;

var discovery = new DiscoveryService("{version}", authenticator);
discovery.SetServiceUrl("{url}");

Cloud Pak for Data

For Cloud Pak for Data, you pass a bearer token in an Authorization header to authenticate to the API. The token is associated with a username.

  • For testing and development, you can use the bearer token that's displayed in the Cloud Pak for Data web client. To find this token, view the details for the service instance by clicking the name of the service in your list of instances. The details also include the service endpoint URL. Don't use this token in production because it does not expire.
  • For production use, create a user in the Cloud Pak for Data web client to use for authentication. Generate a token from that user's credentials with the POST /v1/authorize method.

For more information, see the Get authorization token method of the Cloud Pak for Data API reference.

For Cloud Pak for Data instances, pass either username and password credentials or a bearer token that you generate to authenticate to the API. Username and password credentials use basic authentication. However, the SDK manages the lifecycle of the token. Tokens are temporary security credentials. If you pass a token, you maintain the token lifecycle.

For production use, create a user in the Cloud Pak for Data web client to use for authentication, and decide which authentication mechanism to use.

  • To have the SDK manage the lifecycle of the token, use the username and password for that new user in your calls.
  • To manage the lifecycle of the token yourself, generate a token from that user's credentials. Call the POST /v1/authorize method to generate the token, and then pass the token in an Authorization header in your calls. You can see an example of the method on the Curl tab.

For more information, see the Get authorization token method of the Cloud Pak for Data API reference.

Don't use the bearer token that's displayed in the web client for the instance except during testing and development because that token does not expire.

To find your value for {url}, view the details for the service instance by clicking the name of the service in your list of instances in the Cloud Pak for Data web client.

Cloud Pak for Data. Generating a bearer token.

Replace {cpd_cluster_host} and {port} with the details for the service instance. Replace {username} and {password} with your Cloud Pak for Data credentials.

curl -k -X POST -H "cache-control: no-cache" -H "Content-Type: application/json" -d "{\"username\":\"{username}\",\"password\":\"{password}\"}" "https://{cpd_cluster_host}{:port}/icp4d-api/v1/authorize"

The response includes a token property.

Authenticating to the API. Replace {token} with your details.

curl -H "Authorization: Bearer {token}" "{url}/v2/{method}"

Cloud Pak for Data. SDK managing the token.

Replace {username} and {password} with your Cloud Pak for Data credentials. Replace {version} with the service version date. For {url}, see Endpoint URLs.

CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator("https://{cpd_cluster_host}{:port}/icp4d-api/v1/authorize", "{username}", "{password}");
Discovery discovery = new Discovery("{version}", authenticator);
discovery.setServiceUrl("{url}");

Cloud Pak for Data. SDK managing the token.

Replace {username} and {password} with your Cloud Pak for Data credentials. Replace {version} with the service version date. For {url}, see Endpoint URLs.

const DiscoveryV2 = require('ibm-watson/discovery/v2');
const { CloudPakForDataAuthenticator } = require('ibm-watson/auth');

const discovery = new DiscoveryV2({
  version: '{version}',
  authenticator: new CloudPakForDataAuthenticator({
    username: '{username}',
    password: '{password}',
    url: 'https://{cpd_cluster_host}{:port}/icp4d-api/v1/authorize',
  }),
  serviceUrl: '{url}',
});

Cloud Pak for Data. SDK managing the token.

Replace {username} and {password} with your Cloud Pak for Data credentials. Replace {version} with the service version date. For {url}, see Endpoint URLs.

from ibm_watson import DiscoveryV2
from ibm_cloud_sdk_core.authenticators import CloudPakForDataAuthenticator

authenticator = CloudPakForDataAuthenticator(
    '{username}',
    '{password}',
    'https://{cpd_cluster_host}{:port}/icp4d-api/v1/authorize'
)

discovery = DiscoveryV2(
    version='{version}',
    authenticator=authenticator
)

discovery.set_service_url('{url}')

Cloud Pak for Data. SDK managing the token.

Replace {username} and {password} with your Cloud Pak for Data credentials. Replace {version} with the service version date. For {url}, see Endpoint URLs.

require "ibm_watson/authenticators"
require "ibm_watson/discovery_v2"
include IBMWatson

authenticator = Authenticators::CloudPakForDataAuthenticator.new(
  username: "{username}",
  password: "{password}",
  url: "https://{cpd_cluster_host}{:port}/icp4d-api/v1/authorize"
)
discovery = DiscoveryV2.new(
  version: "{version}",
  authenticator: authenticator
)
discovery.service_url = "{url}"

Cloud Pak for Data. SDK managing the token.

Replace {username} and {password} with your Cloud Pak for Data credentials. Replace {version} with the service version date. For {url}, see Endpoint URLs.

import (
  "github.com/IBM/go-sdk-core/core"
  "github.com/watson-developer-cloud/go-sdk/discoveryv2"
)

func main() {
  authenticator := &core.CloudPakForDataAuthenticator{
    URL: "https://{cpd_cluster_host}{:port}/icp4d-api/v1/authorize",
    Username: "{username}",
    Password: "{password}",
  }

  options := &discoveryv2.DiscoveryV2Options{
    Version: "{version}",
    Authenticator: authenticator,
  }

  discovery, discoveryErr := discoveryv2.NewDiscoveryV2(options)

  if discoveryErr != nil {
    panic(discoveryErr)
  }

  discovery.SetServiceURL("{url}")
}

Cloud Pak for Data. SDK managing the token.

Replace {username} and {password} with your Cloud Pak for Data credentials. Replace {version} with the service version date. For {url}, see Endpoint URLs.

let authenticator = WatsonCloudPakForDataAuthenticator(username: "{username}", password: "{password}", url: "https://{cpd_cluster_host}{:port}/icp4d-api/v1/authorize")
let discovery = Discovery(version: "{version}", authenticator: authenticator)
discovery.serviceURL = "{url}"

Cloud Pak for Data. SDK managing the token.

Replace {username} and {password} with your Cloud Pak for Data credentials. Replace {version} with the service version date. For {cpd_cluster_host}, {port}, {release}, and {instance_id}, see Endpoint URLs.

CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator(
    url: "https://{cpd_cluster_host}{:port}/icp4d-api/v1/authorize",
    username: "{username}",
    password: "{password}"
    );

DiscoveryService discovery = new DiscoveryService("{version}", authenticator);
discovery.SetServiceUrl("{url}");

Cloud Pak for Data. SDK managing the token.

Replace {username} and {password} with your Cloud Pak for Data credentials. Replace {version} with the service version date. For {cpd_cluster_host}, {port}, {release}, and {instance_id}, see Endpoint URLs.

var authenticator = new CloudPakForDataAuthenticator(
    url: "https://{cpd_cluster_host}{:port}/icp4d-api/v1/authorize",
    username: "{username}",
    password: "{password}"
);

while (!authenticator.CanAuthenticate())
    yield return null;

var discovery = new DiscoveryService("{version}", authenticator);
discovery.SetServiceUrl("{url}");

Access between services

Your application might use more than one Watson service. You can grant access between services and you can grant access to more than one service for your applications.

For IBM Cloud services, the method to grant access between Watson services varies depending on the type of API key. For more information, see IAM access.

  • To grant access between IBM Cloud services, create an authorization between the services. For more information, see Granting access between services.
  • To grant access to your services by applications without using user credentials, create a service ID, add an API key, and assign access policies. For more information, see Creating and working with service IDs.

When you give a user ID access to multiple services, use an endpoint URL that includes the service instance ID (for example, https://api.us-south.discovery.watson.cloud.ibm.com/instances/6bbda3b3-d572-45e1-8c54-22d6ed9e52c2). You can find the instance ID in two places:

  • By clicking the service instance row in the Resource list. The instance ID is the GUID in the details pane.

  • By clicking the name of the service instance in the list and looking at the credentials URL.

    If you don't see the instance ID in the URL, the credentials predate service IDs. Add new credentials from the Service credentials page and use those credentials.

Because the Cloud Pak for Data bearer token is associated with a username, you can use the token for all CPD Watson services that are associated with the username.

Versioning

API requests require a version parameter that takes a date in the format version=YYYY-MM-DD. When the API is updated with any breaking changes, the service introduces a new version date for the API.

Send the version parameter with every API request. The service uses the API version for the date you specify, or the most recent version before that date. Don't default to the current date. Instead, specify a date that matches a version that is compatible with your app, and don't change it until your app is ready for a later version.

Specify the version to use on API requests with the version parameter when you create the service instance. The service uses the API version for the date you specify, or the most recent version before that date. Don't default to the current date. Instead, specify a date that matches a version that is compatible with your app, and don't change it until your app is ready for a later version.

This documentation describes the current version of Discovery, 2023-03-31. In some cases, differences in earlier versions are noted in the descriptions of parameters and response models.

Error handling

Discovery uses standard HTTP response codes to indicate whether a method completed successfully. HTTP response codes in the 2xx range indicate success. A response in the 4xx range is some sort of failure, and a response in the 5xx range usually indicates an internal system error that cannot be resolved by the user. Response codes are listed with the method.

ErrorResponse

Name Description
code
integer
The HTTP response code.
error
string
General description of an error.

The Java SDK generates an exception for any unsuccessful method invocation. All methods that accept an argument can also throw an IllegalArgumentException.

Exception Description
IllegalArgumentException An invalid argument was passed to the method.

When the Java SDK receives an error response from the Discovery service, it generates an exception from the com.ibm.watson.developer_cloud.service.exception package. All service exceptions contain the following fields.

Field Description
statusCode The HTTP response code that is returned.
message A message that describes the error.

When the Node SDK receives an error response from the Discovery service, it creates an Error object with information that describes the error that occurred. This error object is passed as the first parameter to the callback function for the method. The contents of the error object are as shown in the following table.

Error

Field Description
code The HTTP response code that is returned.
message A message that describes the error.

The Python SDK generates an exception for any unsuccessful method invocation. When the Python SDK receives an error response from the Discovery service, it generates an ApiException with the following fields.

Field Description
code The HTTP response code that is returned.
message A message that describes the error.
info A dictionary of additional information about the error.

When the Ruby SDK receives an error response from the Discovery service, it generates an ApiException with the following fields.

Field Description
code The HTTP response code that is returned.
message A message that describes the error.
info A dictionary of additional information about the error.

The Go SDK generates an error for any unsuccessful service instantiation and method invocation. You can check for the error immediately. The contents of the error object are as shown in the following table.

Error

Field Description
code The HTTP response code that is returned.
message A message that describes the error.

The Swift SDK returns a WatsonError in the completionHandler any unsuccessful method invocation. This error type is an enum that conforms to LocalizedError and contains an errorDescription property that returns an error message. Some of the WatsonError cases contain associated values that reveal more information about the error.

Field Description
errorDescription A message that describes the error.

When the .NET Standard SDK receives an error response from the Discovery service, it generates a ServiceResponseException with the following fields.

Field Description
Message A message that describes the error.
CodeDescription The HTTP response code that is returned.

When the Unity SDK receives an error response from the Discovery service, it generates an IBMError with the following fields.

Field Description
Url The URL that generated the error.
StatusCode The HTTP response code returned.
ErrorMessage A message that describes the error.
Response The contents of the response from the server.
ResponseHeaders A dictionary of headers returned by the request.

Example error handling

try {
  // Invoke a method
} catch (NotFoundException e) {
  // Handle Not Found (404) exception
} catch (RequestTooLargeException e) {
  // Handle Request Too Large (413) exception
} catch (ServiceResponseException e) {
  // Base class for all exceptions caused by error responses from the service
  System.out.println("Service returned status code "
    + e.getStatusCode() + ": " + e.getMessage());
}

Example error handling

discovery.method(params)
  .catch(err => {
    console.log('error:', err);
  });

Example error handling

from ibm_watson import ApiException
try:
    # Invoke a method
except ApiException as ex:
    print "Method failed with status code " + str(ex.code) + ": " + ex.message

Example error handling

require "ibm_watson"
begin
  # Invoke a method
rescue IBMWatson::ApiException => ex
  print "Method failed with status code #{ex.code}: #{ex.error}"
end

Example error handling

import "github.com/watson-developer-cloud/go-sdk/discoveryv2"

// Instantiate a service
discovery, discoveryErr := discoveryv2.NewDiscoveryV2(options)

// Check for errors
if discoveryErr != nil {
  panic(discoveryErr)
}

// Call a method
result, _, responseErr := discovery.MethodName(&methodOptions)

// Check for errors
if responseErr != nil {
  panic(responseErr)
}

Example error handling

discovery.method() {
  response, error in

  if let error = error {
    switch error {
    case let .http(statusCode, message, metadata):
      switch statusCode {
      case .some(404):
        // Handle Not Found (404) exception
        print("Not found")
      case .some(413):
        // Handle Request Too Large (413) exception
        print("Payload too large")
      default:
        if let statusCode = statusCode {
          print("Error - code: \(statusCode), \(message ?? "")")
        }
      }
    default:
      print(error.localizedDescription)
    }
    return
  }

  guard let result = response?.result else {
    print(error?.localizedDescription ?? "unknown error")
    return
  }

  print(result)
}

Example error handling

try
{
    // Invoke a method
}
catch(ServiceResponseException e)
{
    Console.WriteLine("Error: " + e.Message);
}
catch (Exception e)
{
    Console.WriteLine("Error: " + e.Message);
}

Example error handling

// Invoke a method
discovery.MethodName(Callback, Parameters);

// Check for errors
private void Callback(DetailedResponse<ExampleResponse> response, IBMError error)
{
    if (error == null)
    {
        Log.Debug("ExampleCallback", "Response received: {0}", response.Response);
    }
    else
    {
        Log.Debug("ExampleCallback", "Error received: {0}, {1}, {3}", error.StatusCode, error.ErrorMessage, error.Response);
    }
}

Data handling

Additional headers

Some Watson services accept special parameters in headers that are passed with the request.

You can pass request header parameters in all requests or in a single request to the service.

To pass a request header, use the --header (-H) option with a curl request.

To pass header parameters with every request, use the setDefaultHeaders method of the service object. See Data collection for an example use of this method.

To pass header parameters in a single request, use the addHeader method as a modifier on the request before you execute it.

To pass header parameters with every request, specify the headers parameter when you create the service object. See Data collection for an example use of this method.

To pass header parameters in a single request, use the headers method as a modifier on the request before you execute it.

To pass header parameters with every request, specify the set_default_headers method of the service object. See Data collection for an example use of this method.

To pass header parameters in a single request, include headers as a dict in the request.

To pass header parameters with every request, specify the add_default_headers method of the service object. See Data collection for an example use of this method.

To pass header parameters in a single request, specify the headers method as a chainable method in the request.

To pass header parameters with every request, specify the SetDefaultHeaders method of the service object. See Data collection for an example use of this method.

To pass header parameters in a single request, specify the Headers as a map in the request.

To pass header parameters with every request, add them to the defaultHeaders property of the service object. See Data collection for an example use of this method.

To pass header parameters in a single request, pass the headers parameter to the request method.

To pass header parameters in a single request, use the WithHeader() method as a modifier on the request before you execute it. See Data collection for an example use of this method.

To pass header parameters in a single request, use the WithHeader() method as a modifier on the request before you execute it.

Example header parameter in a request

curl -X {request_method} -H "Request-Header: {header_value}" "{url}/v2/{method}"

Example header parameter in a request

ReturnType returnValue = discovery.methodName(parameters)
  .addHeader("Custom-Header", "{header_value}")
  .execute();

Example header parameter in a request

const parameters = {
  {parameters}
};

discovery.methodName(
  parameters,
  headers: {
    'Custom-Header': '{header_value}'
  })
   .then(result => {
    console.log(response);
  })
  .catch(err => {
    console.log('error:', err);
  });

Example header parameter in a request

response = discovery.methodName(
    parameters,
    headers = {
        'Custom-Header': '{header_value}'
    })

Example header parameter in a request

response = discovery.headers(
  "Custom-Header" => "{header_value}"
).methodName(parameters)

Example header parameter in a request

result, _, responseErr := discovery.MethodName(
  &methodOptions{
    Headers: map[string]string{
      "Accept": "application/json",
    },
  },
)

Example header parameter in a request

let customHeader: [String: String] = ["Custom-Header": "{header_value}"]
discovery.methodName(parameters, headers: customHeader) {
  response, error in
}

Example header parameter in a request for a service managed on IBM Cloud

IamAuthenticator authenticator = new IamAuthenticator(
    apikey: "{apikey}"
    );

DiscoveryService discovery = new DiscoveryService("{version}", authenticator);
discovery.SetServiceUrl("{url}");

discovery.WithHeader("Custom-Header", "header_value");

Example header parameter in a request for an installed service

CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator(
    url: "https://{cpd_cluster_host}{:port}",
    username: "{username}",
    password: "{password}"
    );

DiscoveryService discovery = new DiscoveryService("{version}", authenticator);
discovery.SetServiceUrl("https://{cpd_cluster_host}{:port}/discovery/{release}/instances/{instance_id}/api");

discovery.WithHeader("Custom-Header", "header_value");

Example header parameter in a request for a service managed on IBM Cloud

var authenticator = new IamAuthenticator(
    apikey: "{apikey}"
);

while (!authenticator.CanAuthenticate())
    yield return null;

var discovery = new DiscoveryService("{version}", authenticator);
discovery.SetServiceUrl("{url}");

discovery.WithHeader("Custom-Header", "header_value");

Example header parameter in a request for an installed service

var authenticator = new CloudPakForDataAuthenticator(
    url: "https://{cpd_cluster_host}{:port}",
    username: "{username}",
    password: "{password}"
);

while (!authenticator.CanAuthenticate())
    yield return null;

var discovery = new DiscoveryService("{version}", authenticator);
discovery.SetServiceUrl("https://{cpd_cluster_host}{:port}/discovery/{release}/instances/{instance_id}/api");

discovery.WithHeader("Custom-Header", "header_value");

Response details

The Discovery service might return information to the application in response headers.

To access all response headers that the service returns, include the --include (-i) option with a curl request. To see detailed response data for the request, including request headers, response headers, and extra debugging information, include the --verbose (-v) option with the request.

Example request to access response headers

curl -X {request_method} {authentication_method} --include "{url}/v2/{method}"

To access information in the response headers, use one of the request methods that returns details with the response: executeWithDetails(), enqueueWithDetails(), or rxWithDetails(). These methods return a Response<T> object, where T is the expected response model. Use the getResult() method to access the response object for the method, and use the getHeaders() method to access information in response headers.

Example request to access response headers

Response<ReturnType> response = discovery.methodName(parameters)
  .executeWithDetails();
// Access response from methodName
ReturnType returnValue = response.getResult();
// Access information in response headers
Headers responseHeaders = response.getHeaders();

All response data is available in the Response<T> object that is returned by each method. To access information in the response object, use the following properties.

Property Description
result Returns the response for the service-specific method.
headers Returns the response header information.
status Returns the HTTP status code.

Example request to access response headers

discovery.methodName(parameters)
  .then(response => {
    console.log(response.headers);
  })
  .catch(err => {
    console.log('error:', err);
  });

The return value from all service methods is a DetailedResponse object. To access information in the result object or response headers, use the following methods.

DetailedResponse

Method Description
get_result() Returns the response for the service-specific method.
get_headers() Returns the response header information.
get_status_code() Returns the HTTP status code.

Example request to access response headers

discovery.set_detailed_response(True)
response = discovery.methodName(parameters)
# Access response from methodName
print(json.dumps(response.get_result(), indent=2))
# Access information in response headers
print(response.get_headers())
# Access HTTP response status
print(response.get_status_code())

The return value from all service methods is a DetailedResponse object. To access information in the response object, use the following properties.

DetailedResponse

Property Description
result Returns the response for the service-specific method.
headers Returns the response header information.
status Returns the HTTP status code.

Example request to access response headers

response = discovery.methodName(parameters)
# Access response from methodName
print response.result
# Access information in response headers
print response.headers
# Access HTTP response status
print response.status

The return value from all service methods is a DetailedResponse object. To access information in the response object or response headers, use the following methods.

DetailedResponse

Method Description
GetResult() Returns the response for the service-specific method.
GetHeaders() Returns the response header information.
GetStatusCode() Returns the HTTP status code.

Example request to access response headers

import (
  "github.com/IBM/go-sdk-core/core"
  "github.com/watson-developer-cloud/go-sdk/discoveryv2"
)
result, response, responseErr := discovery.MethodName(
  &methodOptions{})
// Access result
core.PrettyPrint(response.GetResult(), "Result ")

// Access response headers
core.PrettyPrint(response.GetHeaders(), "Headers ")

// Access status code
core.PrettyPrint(response.GetStatusCode(), "Status Code ")

All response data is available in the WatsonResponse<T> object that is returned in each method's completionHandler.

Example request to access response headers

discovery.methodName(parameters) {
  response, error in

  guard let result = response?.result else {
    print(error?.localizedDescription ?? "unknown error")
    return
  }
  print(result) // The data returned by the service
  print(response?.statusCode)
  print(response?.headers)
}

The response contains fields for response headers, response JSON, and the status code.

DetailedResponse

Property Description
Result Returns the result for the service-specific method.
Response Returns the raw JSON response for the service-specific method.
Headers Returns the response header information.
StatusCode Returns the HTTP status code.

Example request to access response headers

var results = discovery.MethodName(parameters);

var result = results.Result;            //  The result object
var responseHeaders = results.Headers;  //  The response headers
var responseJson = results.Response;    //  The raw response JSON
var statusCode = results.StatusCode;    //  The response status code

The response contains fields for response headers, response JSON, and the status code.

DetailedResponse

Property Description
Result Returns the result for the service-specific method.
Response Returns the raw JSON response for the service-specific method.
Headers Returns the response header information.
StatusCode Returns the HTTP status code.

Example request to access response headers

private void Example()
{
    discovery.MethodName(Callback, Parameters);
}

private void Callback(DetailedResponse<ResponseType> response, IBMError error)
{
    var result = response.Result;                 //  The result object
    var responseHeaders = response.Headers;       //  The response headers
    var responseJson = reresponsesults.Response;  //  The raw response JSON
    var statusCode = response.StatusCode;         //  The response status code
}

Data collection (IBM Cloud)

By default, Discovery service instances managed on IBM Cloud that are not part of Premium plans collect data about API requests and their results. This data is collected only to improve the services for future users. The collected data is not shared or made public. Data is not collected for services that are part of Premium plans.

To prevent IBM usage of your data for an API request, set the X-Watson-Learning-Opt-Out header parameter to true. You can also disable request logging at the account level. For more information, see Controlling request logging for Watson services.

You must set the header on each request that you do not want IBM to access for general service improvements.

You can set the header by using the setDefaultHeaders method of the service object.

You can set the header by using the headers parameter when you create the service object.

You can set the header by using the set_default_headers method of the service object.

You can set the header by using the add_default_headers method of the service object.

You can set the header by using the SetDefaultHeaders method of the service object.

You can set the header by adding it to the defaultHeaders property of the service object.

You can set the header by using the WithHeader() method of the service object.

Example request with a service managed on IBM Cloud

curl -u "apikey:{apikey}" -H "X-Watson-Learning-Opt-Out: true" "{url}/{method}"

Example request with a service managed on IBM Cloud

Map<String, String> headers = new HashMap<String, String>();
headers.put("X-Watson-Learning-Opt-Out", "true");

discovery.setDefaultHeaders(headers);

Example request with a service managed on IBM Cloud

const DiscoveryV2 = require('ibm-watson/discovery/v2');
const { IamAuthenticator } = require('ibm-watson/auth');

const discovery = new DiscoveryV2({
  version: '{version}',
  authenticator: new IamAuthenticator({
    apikey: '{apikey}',
  }),
  serviceUrl: '{url}',
  headers: {
    'X-Watson-Learning-Opt-Out': 'true'
  }
});

Example request with a service managed on IBM Cloud

discovery.set_default_headers({'x-watson-learning-opt-out': "true"})

Example request with a service managed on IBM Cloud

discovery.add_default_headers(headers: {"x-watson-learning-opt-out" => "true"})

Example request with a service managed on IBM Cloud

import "net/http"

headers := http.Header{}
headers.Add("x-watson-learning-opt-out", "true")
discovery.SetDefaultHeaders(headers)

Example request with a service managed on IBM Cloud

discovery.defaultHeaders["X-Watson-Learning-Opt-Out"] = "true"

Example request with a service managed on IBM Cloud

IamAuthenticator authenticator = new IamAuthenticator(
    apikey: "{apikey}"
    );

DiscoveryService discovery = new DiscoveryService("{version}", authenticator);
discovery.SetServiceUrl("{url}");

discovery.WithHeader("X-Watson-Learning-Opt-Out", "true");

Example request with a service managed on IBM Cloud

var authenticator = new IamAuthenticator(
    apikey: "{apikey}"
);

while (!authenticator.CanAuthenticate())
    yield return null;

var discovery = new DiscoveryService("{version}", authenticator);
discovery.SetServiceUrl("{url}");

discovery.WithHeader("X-Watson-Learning-Opt-Out", "true");

Synchronous and asynchronous requests

The Java SDK supports both synchronous (blocking) and asynchronous (non-blocking) execution of service methods. All service methods implement the ServiceCall interface.

  • To call a method synchronously, use the execute method of the ServiceCall interface. You can call the execute method directly from an instance of the service.
  • To call a method asynchronously, use the enqueue method of the ServiceCall interface to receive a callback when the response arrives. The ServiceCallback interface of the method's argument provides onResponse and onFailure methods that you override to handle the callback.

The Ruby SDK supports both synchronous (blocking) and asynchronous (non-blocking) execution of service methods. All service methods implement the Concurrent::Async module. When you use the synchronous or asynchronous methods, an IVar object is returned. You access the DetailedResponse object by calling ivar_object.value.

For more information about the Ivar object, see the IVar class docs.

  • To call a method synchronously, either call the method directly or use the .await chainable method of the Concurrent::Async module.

    Calling a method directly (without .await) returns a DetailedResponse object.

  • To call a method asynchronously, use the .async chainable method of the Concurrent::Async module.

You can call the .await and .async methods directly from an instance of the service.

Example synchronous request

ReturnType returnValue = discovery.method(parameters).execute();

Example asynchronous request

discovery.method(parameters).enqueue(new ServiceCallback<ReturnType>() {
  @Override public void onResponse(ReturnType response) {
    . . .
  }
  @Override public void onFailure(Exception e) {
    . . .
  }
});

Example synchronous request

response = discovery.method_name(parameters)

or

response = discovery.await.method_name(parameters)

Example asynchronous request

response = discovery.async.method_name(parameters)

Methods

List projects

Lists existing projects for this instance.

Lists existing projects for this instance.

Lists existing projects for this instance.

Lists existing projects for this instance.

Lists existing projects for this instance.

GET /v2/projects
ServiceCall<ListProjectsResponse> listProjects(ListProjectsOptions listProjectsOptions)
listProjects(params)
list_projects(
        self,
        **kwargs,
    ) -> DetailedResponse
ListProjects()

Request

Use the ListProjectsOptions.Builder to create a ListProjectsOptions object that contains the parameter values for the listProjects method.

Query Parameters

  • Release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. The current version is 2023-03-31.

parameters

    parameters

      parameters

        • curl {auth} "{url}/v2/projects?version=2023-03-31"

        Response

        A list of projects in this instance.

        A list of projects in this instance.

        A list of projects in this instance.

        A list of projects in this instance.

        A list of projects in this instance.

        Status Code

        • Successful response.

        • Bad request.

        Example responses
        • {
            "projects": [
              {
                "project_id": "fe119406-4111-4cd8-8418-6f0074ee5a12",
                "type": "document_retrieval",
                "name": "Sample Project",
                "collection_count": 1
              },
              {
                "project_id": "b1722e7b-0b42-4fce-a6a4-d7cd8a4895f1",
                "type": "document_retrieval",
                "name": "My search bar",
                "collection_count": 5
              },
              {
                "project_id": "c8a8f4f1-9bcb-4035-85ae-5ec2336f2e62",
                "type": "conversational_search",
                "name": "Tutorial project",
                "collection_count": 1
              }
            ]
          }
        • {
            "projects": [
              {
                "project_id": "fe119406-4111-4cd8-8418-6f0074ee5a12",
                "type": "document_retrieval",
                "name": "Sample Project",
                "collection_count": 1
              },
              {
                "project_id": "b1722e7b-0b42-4fce-a6a4-d7cd8a4895f1",
                "type": "document_retrieval",
                "name": "My search bar",
                "collection_count": 5
              },
              {
                "project_id": "c8a8f4f1-9bcb-4035-85ae-5ec2336f2e62",
                "type": "conversational_search",
                "name": "Tutorial project",
                "collection_count": 1
              }
            ]
          }

        Create a project

        Create a new project for this instance

        Create a new project for this instance.

        Create a new project for this instance.

        Create a new project for this instance.

        Create a new project for this instance.

        POST /v2/projects
        ServiceCall<ProjectDetails> createProject(CreateProjectOptions createProjectOptions)
        createProject(params)
        create_project(
                self,
                name: str,
                type: str,
                *,
                default_query_parameters: 'DefaultQueryParams' = None,
                **kwargs,
            ) -> DetailedResponse
        CreateProject(string name, string type, DefaultQueryParams defaultQueryParameters = null)

        Request

        Use the CreateProjectOptions.Builder to create a CreateProjectOptions object that contains the parameter values for the createProject method.

        Query Parameters

        • Release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. The current version is 2023-03-31.

        An object that represents the project to be created.

        The createProject options.

        parameters

        • The human readable name of this project.

        • The type of project.

          The content_intelligence type is a Document Retrieval for Contracts project and the other type is a Custom project.

          The content_mining and content_intelligence types are available with Premium plan managed deployments and installed deployments only.

          Allowable values: [document_retrieval,conversational_search,content_intelligence,content_mining,other]

        • Default query parameters for this project.

        parameters

        • The human readable name of this project.

        • The type of project.

          The content_intelligence type is a Document Retrieval for Contracts project and the other type is a Custom project.

          The content_mining and content_intelligence types are available with Premium plan managed deployments and installed deployments only.

          Allowable values: [document_retrieval,conversational_search,content_intelligence,content_mining,other]

        • Default query parameters for this project.

        parameters

        • The human readable name of this project.

        • The type of project.

          The content_intelligence type is a Document Retrieval for Contracts project and the other type is a Custom project.

          The content_mining and content_intelligence types are available with Premium plan managed deployments and installed deployments only.

          Allowable values: [document_retrieval,conversational_search,content_intelligence,content_mining,other]

        • Default query parameters for this project.

        • curl -X POST {auth} --header "Content-Type: application/json" --data "{   \"name\": \"My project\",   \"type\": \"document_retrieval\" }" "{url}/v2/projects?version=2023-03-31"

        Response

        Detailed information about the specified project.

        Detailed information about the specified project.

        Detailed information about the specified project.

        Detailed information about the specified project.

        Detailed information about the specified project.

        Status Code

        • The project has successfully been created.

        • Bad request.

        Example responses
        • {
            "project_id": "6b18887d-d68e-434d-99f1-20925c7654e0",
            "type": "document_retrieval",
            "name": "My project",
            "collection_count": 0,
            "default_query_parameters": {
              "aggregation": "[term(enriched_text.entities.text,name:entities)]",
              "count": 10,
              "sort": "",
              "return": [],
              "passages": {
                "enabled": true,
                "count": 10,
                "fields": [
                  "text",
                  "title"
                ],
                "characters": 200,
                "per_document": true,
                "max_per_document": 1,
                "find_answers": false,
                "max_answers_per_passage": 1
              },
              "highlight": false,
              "spelling_suggestions": false,
              "table_results": {
                "enabled": false,
                "count": 10,
                "per_document": 0
              }
            }
          }
        • {
            "project_id": "6b18887d-d68e-434d-99f1-20925c7654e0",
            "type": "document_retrieval",
            "name": "My project",
            "collection_count": 0,
            "default_query_parameters": {
              "aggregation": "[term(enriched_text.entities.text,name:entities)]",
              "count": 10,
              "sort": "",
              "return": [],
              "passages": {
                "enabled": true,
                "count": 10,
                "fields": [
                  "text",
                  "title"
                ],
                "characters": 200,
                "per_document": true,
                "max_per_document": 1,
                "find_answers": false,
                "max_answers_per_passage": 1
              },
              "highlight": false,
              "spelling_suggestions": false,
              "table_results": {
                "enabled": false,
                "count": 10,
                "per_document": 0
              }
            }
          }

        Get project

        Get details on the specified project.

        Get details on the specified project.

        Get details on the specified project.

        Get details on the specified project.

        Get details on the specified project.

        GET /v2/projects/{project_id}
        ServiceCall<ProjectDetails> getProject(GetProjectOptions getProjectOptions)
        getProject(params)
        get_project(
                self,
                project_id: str,
                **kwargs,
            ) -> DetailedResponse
        GetProject(string projectId)

        Request

        Use the GetProjectOptions.Builder to create a GetProjectOptions object that contains the parameter values for the getProject method.

        Path Parameters

        • The ID of the project. This information can be found from the Integrate and Deploy page in Discovery.

          Possible values: 1 ≤ length ≤ 255, Value must match regular expression ^[a-zA-Z0-9_-]*$

        Query Parameters

        • Release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. The current version is 2023-03-31.

        The getProject options.

        parameters

        • The ID of the project. This information can be found from the Integrate and Deploy page in Discovery.

          Possible values: 1 ≤ length ≤ 255, Value must match regular expression /^[a-zA-Z0-9_-]*$/

        parameters

        • The ID of the project. This information can be found from the Integrate and Deploy page in Discovery.

          Possible values: 1 ≤ length ≤ 255, Value must match regular expression /^[a-zA-Z0-9_-]*$/

        parameters

        • The ID of the project. This information can be found from the Integrate and Deploy page in Discovery.

          Possible values: 1 ≤ length ≤ 255, Value must match regular expression /^[a-zA-Z0-9_-]*$/

        • curl {auth} "{url}/v2/projects/{project_id}?version=2023-03-31"

        Response

        Detailed information about the specified project.

        Detailed information about the specified project.

        Detailed information about the specified project.

        Detailed information about the specified project.

        Detailed information about the specified project.

        Status Code

        • Returns information about the specified project if it exists.

        • Project not found.

        Example responses
        • {
            "project_id": "6b18887d-d68e-434d-99f1-20925c7654e0",
            "type": "document_retrieval",
            "name": "My project",
            "collection_count": 0,
            "relevancy_training_status": {
              "total_examples": 0,
              "sufficient_label_diversity": false,
              "processing": false,
              "minimum_examples_added": false,
              "available": false,
              "notices": 0,
              "minimum_queries_added": false
            },
            "default_query_parameters": {
              "aggregation": "[term(enriched_text.entities.text,name:entities)]",
              "count": 10,
              "sort": "",
              "return": [],
              "passages": {
                "enabled": true,
                "count": 10,
                "fields": [
                  "text",
                  "title"
                ],
                "characters": 200,
                "per_document": true,
                "max_per_document": 1,
                "find_answers": false,
                "max_answers_per_passage": 1
              },
              "highlight": false,
              "spelling_suggestions": false,
              "table_results": {
                "enabled": false,
                "count": 10,
                "per_document": 0
              }
            }
          }
        • {
            "project_id": "6b18887d-d68e-434d-99f1-20925c7654e0",
            "type": "document_retrieval",
            "name": "My project",
            "collection_count": 0,
            "relevancy_training_status": {
              "total_examples": 0,
              "sufficient_label_diversity": false,
              "processing": false,
              "minimum_examples_added": false,
              "available": false,
              "notices": 0,
              "minimum_queries_added": false
            },
            "default_query_parameters": {
              "aggregation": "[term(enriched_text.entities.text,name:entities)]",
              "count": 10,
              "sort": "",
              "return": [],
              "passages": {
                "enabled": true,
                "count": 10,
                "fields": [
                  "text",
                  "title"
                ],
                "characters": 200,
                "per_document": true,
                "max_per_document": 1,
                "find_answers": false,
                "max_answers_per_passage": 1
              },
              "highlight": false,
              "spelling_suggestions": false,
              "table_results": {
                "enabled": false,
                "count": 10,
                "per_document": 0
              }
            }
          }

        Update a project

        Update the specified project's name.

        Update the specified project's name.

        Update the specified project's name.

        Update the specified project's name.

        Update the specified project's name.

        POST /v2/projects/{project_id}
        ServiceCall<ProjectDetails> updateProject(UpdateProjectOptions updateProjectOptions)
        updateProject(params)
        update_project(
                self,
                project_id: str,
                *,
                name: str = None,
                **kwargs,
            ) -> DetailedResponse
        UpdateProject(string projectId, string name = null)

        Request

        Use the UpdateProjectOptions.Builder to create a UpdateProjectOptions object that contains the parameter values for the updateProject method.

        Path Parameters

        • The ID of the project. This information can be found from the Integrate and Deploy page in Discovery.

          Possible values: 1 ≤ length ≤ 255, Value must match regular expression ^[a-zA-Z0-9_-]*$

        Query Parameters

        • Release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. The current version is 2023-03-31.

        An object that represents the new name of the project.

        The updateProject options.

        parameters

        • The ID of the project. This information can be found from the Integrate and Deploy page in Discovery.

          Possible values: 1 ≤ length ≤ 255, Value must match regular expression /^[a-zA-Z0-9_-]*$/

        • The new name to give this project.

        parameters

        • The ID of the project. This information can be found from the Integrate and Deploy page in Discovery.

          Possible values: 1 ≤ length ≤ 255, Value must match regular expression /^[a-zA-Z0-9_-]*$/

        • The new name to give this project.

        parameters

        • The ID of the project. This information can be found from the Integrate and Deploy page in Discovery.

          Possible values: 1 ≤ length ≤ 255, Value must match regular expression /^[a-zA-Z0-9_-]*$/

        • The new name to give this project.

        • curl -X POST {auth} --header "Content-Type: application/json" --data "{   \"name\": \"My updated project\" }" "{url}/v2/projects/{project_id}?version=2023-03-31"

        Response

        Detailed information about the specified project.

        Detailed information about the specified project.

        Detailed information about the specified project.

        Detailed information about the specified project.

        Detailed information about the specified project.

        Status Code

        • Returns the updated project information.

        • Bad request.

        • Project not found

        Example responses
        • {
            "project_id": "6b18887d-d68e-434d-99f1-20925c7654e0",
            "type": "document_retrieval",
            "name": "My updated project",
            "collection_count": 0,
            "relevancy_training_status": {
              "total_examples": 0,
              "sufficient_label_diversity": false,
              "processing": false,
              "minimum_examples_added": false,
              "available": false,
              "notices": 0,
              "minimum_queries_added": false
            },
            "default_query_parameters": {
              "aggregation": "[term(enriched_text.entities.text,name:entities)]",
              "count": 10,
              "sort": "",
              "return": [],
              "passages": {
                "enabled": true,
                "count": 10,
                "fields": [
                  "text",
                  "title"
                ],
                "characters": 200,
                "per_document": true,
                "max_per_document": 1,
                "find_answers": false,
                "max_answers_per_passage": 1
              },
              "highlight": false,
              "spelling_suggestions": false,
              "table_results": {
                "enabled": false,
                "count": 10,
                "per_document": 0
              }
            }
          }
        • {
            "project_id": "6b18887d-d68e-434d-99f1-20925c7654e0",
            "type": "document_retrieval",
            "name": "My updated project",
            "collection_count": 0,
            "relevancy_training_status": {
              "total_examples": 0,
              "sufficient_label_diversity": false,
              "processing": false,
              "minimum_examples_added": false,
              "available": false,
              "notices": 0,
              "minimum_queries_added": false
            },
            "default_query_parameters": {
              "aggregation": "[term(enriched_text.entities.text,name:entities)]",
              "count": 10,
              "sort": "",
              "return": [],
              "passages": {
                "enabled": true,
                "count": 10,
                "fields": [
                  "text",
                  "title"
                ],
                "characters": 200,
                "per_document": true,
                "max_per_document": 1,
                "find_answers": false,
                "max_answers_per_passage": 1
              },
              "highlight": false,
              "spelling_suggestions": false,
              "table_results": {
                "enabled": false,
                "count": 10,
                "per_document": 0
              }
            }
          }

        Delete a project

        Deletes the specified project.

        Important: Deleting a project deletes everything that is part of the specified project, including all collections.

        Deletes the specified project.

        Important: Deleting a project deletes everything that is part of the specified project, including all collections.

        Deletes the specified project.

        Important: Deleting a project deletes everything that is part of the specified project, including all collections.

        Deletes the specified project.

        Important: Deleting a project deletes everything that is part of the specified project, including all collections.

        Deletes the specified project.

        Important: Deleting a project deletes everything that is part of the specified project, including all collections.

        DELETE /v2/projects/{project_id}
        ServiceCall<Void> deleteProject(DeleteProjectOptions deleteProjectOptions)
        deleteProject(params)
        delete_project(
                self,
                project_id: str,
                **kwargs,
            ) -> DetailedResponse
        DeleteProject(string projectId)

        Request

        Use the DeleteProjectOptions.Builder to create a DeleteProjectOptions object that contains the parameter values for the deleteProject method.

        Path Parameters

        • The ID of the project. This information can be found from the Integrate and Deploy page in Discovery.

          Possible values: 1 ≤ length ≤ 255, Value must match regular expression ^[a-zA-Z0-9_-]*$

        Query Parameters

        • Release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. The current version is 2023-03-31.

        The deleteProject options.

        parameters

        • The ID of the project. This information can be found from the Integrate and Deploy page in Discovery.

          Possible values: 1 ≤ length ≤ 255, Value must match regular expression /^[a-zA-Z0-9_-]*$/

        parameters

        • The ID of the project. This information can be found from the Integrate and Deploy page in Discovery.

          Possible values: 1 ≤ length ≤ 255, Value must match regular expression /^[a-zA-Z0-9_-]*$/

        parameters

        • The ID of the project. This information can be found from the Integrate and Deploy page in Discovery.

          Possible values: 1 ≤ length ≤ 255, Value must match regular expression /^[a-zA-Z0-9_-]*$/

        • curl -X DELETE {auth} "{url}/v2/projects/{project_id}?version=2023-03-31"

        Response

        Response type: object

        Status Code

        • The project has been deleted.

        • Bad request.

        • Project not found

        No Sample Response

        This method does not specify any sample responses.

        List fields

        Gets a list of the unique fields (and their types) stored in the specified collections.

        Gets a list of the unique fields (and their types) stored in the specified collections.

        Gets a list of the unique fields (and their types) stored in the specified collections.

        Gets a list of the unique fields (and their types) stored in the specified collections.

        Gets a list of the unique fields (and their types) stored in the specified collections.

        GET /v2/projects/{project_id}/fields
        ServiceCall<ListFieldsResponse> listFields(ListFieldsOptions listFieldsOptions)
        listFields(params)
        list_fields(
                self,
                project_id: str,
                *,
                collection_ids: List[str] = None,
                **kwargs,
            ) -> DetailedResponse
        ListFields(string projectId, List<string> collectionIds = null)

        Request

        Use the ListFieldsOptions.Builder to create a ListFieldsOptions object that contains the parameter values for the listFields method.

        Path Parameters

        • The ID of the project. This information can be found from the Integrate and Deploy page in Discovery.

          Possible values: 1 ≤ length ≤ 255, Value must match regular expression ^[a-zA-Z0-9_-]*$

        Query Parameters

        • Release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. The current version is 2023-03-31.

        • Comma separated list of the collection IDs. If this parameter is not specified, all collections in the project are used.

        The listFields options.

        parameters

        • The ID of the project. This information can be found from the Integrate and Deploy page in Discovery.

          Possible values: 1 ≤ length ≤ 255, Value must match regular expression /^[a-zA-Z0-9_-]*$/

        • Comma separated list of the collection IDs. If this parameter is not specified, all collections in the project are used.

        parameters

        • The ID of the project. This information can be found from the Integrate and Deploy page in Discovery.

          Possible values: 1 ≤ length ≤ 255, Value must match regular expression /^[a-zA-Z0-9_-]*$/

        • Comma separated list of the collection IDs. If this parameter is not specified, all collections in the project are used.

        parameters

        • The ID of the project. This information can be found from the Integrate and Deploy page in Discovery.

          Possible values: 1 ≤ length ≤ 255, Value must match regular expression /^[a-zA-Z0-9_-]*$/

        • Comma separated list of the collection IDs. If this parameter is not specified, all collections in the project are used.

        • curl {auth} "{url}/v2/projects/{project_id}/fields?collection_ids={collection_id_1},{collection_id_2}&version=2023-03-31"
        • CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator(
              url: "https://{cpd_cluster_host}{:port}/icp4d-api/v1/authorize",
              username: "{username}",
              password: "{password}"
              );
          
          DiscoveryService service = new DiscoveryService("2020-08-30", authenticator);
          service.SetServiceUrl("{https://{cpd_cluster_host}{:port}/discovery/{release}/instances/{instance_id}/api}");
          
          var result = service.ListFields(
              projectId: "{project_id}",
              collectionIds: new List<string>() { "{collection_id_1}","{collection_id_2}" }
              );
          
          Console.WriteLine(result.Response);
        • CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator("https://{cpd_cluster_host}{:port}/icp4d-api/v1/authorize", "{username}", "{password}");
          Discovery discovery = new Discovery("2020-08-30", authenticator);
          discovery.setServiceUrl("https://{cpd_cluster_host}{:port}/discovery/{release}/instances/{instance_id}/api");
          
          ListFieldsOptions options = new ListFieldsOptions.Builder()
            .projectId("{project_id}")
            .addCollectionIds("{collection_id_1}")
            .addCollectionIds("{collection_id_2}")
            .build();
          
          ListFieldsResponse response = discovery.listFields(options).execute().getResult();
          
          System.out.println(response);
        • const DiscoveryV2 = require('ibm-watson/discovery/v2');
          const { CloudPakForDataAuthenticator } = require('ibm-watson/auth');
          
          const discovery = new DiscoveryV2({
            authenticator: new CloudPakForDataAuthenticator({
              url: 'https://{cpd_cluster_host}{:port}/icp4d-api/v1/authorize',
              username: '{username}',
              password: '{password}',
            }),
            version: '2020-08-30',
            serviceUrl: 'https://{cpd_cluster_host}{:port}/discovery/{release}/instances/{instance_id}/api',
          });
          
          const params = {
            projectId: '{projectId}',
            collectionIds: ['{collection_id_1}','{collection_id_2}'],
          };
          
          discovery.listFields(params)
            .then(response => {
              console.log(JSON.stringify(response.result, null, 2));
            })
            .catch(err => {
              console.log('error:', err);
            });
          
        • import json
          from ibm_watson import DiscoveryV2
          from ibm_cloud_sdk_core.authenticators import CloudPakForDataAuthenticator
          
          authenticator = CloudPakForDataAuthenticator(
                                        '{username}',
                                        '{password}',
                                        'https://{cpd_cluster_host}{:port}/icp4d-api/v1/authorize',
                                         disable_ssl_verification=True)
          discovery = DiscoveryV2(
            version='2020-08-30',
            authenticator=authenticator
          )
          discovery.set_service_url('{https://{cpd_cluster_host}{:port}/discovery/{release}/instances/{instance_id}/api}')
          
          response = discovery.list_fields(
            project_id='{project_id}',
            collection_ids=['{collection_id_1}','{collection_id_2}']
          ).get_result()
          print(json.dumps(response, indent=2))
          

        Response

        The list of fetched fields.

        The fields are returned using a fully qualified name format, however, the format differs slightly from that used by the query operations.

        • Fields which contain nested objects are assigned a type of "nested".

        • Fields which belong to a nested object are prefixed with .properties (for example, warnings.properties.severity means that the warnings object has a property called severity).

        The list of fetched fields.

        The fields are returned using a fully qualified name format, however, the format differs slightly from that used by the query operations.

        • Fields which contain nested objects are assigned a type of "nested".

        • Fields which belong to a nested object are prefixed with .properties (for example, warnings.properties.severity means that the warnings object has a property called severity).

        The list of fetched fields.

        The fields are returned using a fully qualified name format, however, the format differs slightly from that used by the query operations.

        • Fields which contain nested objects are assigned a type of "nested".

        • Fields which belong to a nested object are prefixed with .properties (for example, warnings.properties.severity means that the warnings object has a property called severity).

        The list of fetched fields.

        The fields are returned using a fully qualified name format, however, the format differs slightly from that used by the query operations.

        • Fields which contain nested objects are assigned a type of "nested".

        • Fields which belong to a nested object are prefixed with .properties (for example, warnings.properties.severity means that the warnings object has a property called severity).

        The list of fetched fields.

        The fields are returned using a fully qualified name format, however, the format differs slightly from that used by the query operations.

        • Fields which contain nested objects are assigned a type of "nested".

        • Fields which belong to a nested object are prefixed with .properties (for example, warnings.properties.severity means that the warnings object has a property called severity).

        Status Code

        • The list of fetched fields.

          The fields are returned using a fully qualified name format, however, the format differs slightly from that used by the query operations:

          • Fields which contain nested JSON objects are assigned a type of "nested".

          • Fields which belong to a nested object are prefixed with .properties (for example, warnings.properties.severity means that the warnings object has a property called severity).

        • Bad request.

        Example responses
        • {
            "fields": [
              {
                "field": "enriched_text",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "nested"
              },
              {
                "field": "enriched_text.entities",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "nested"
              },
              {
                "field": "enriched_text.entities.mentions",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "nested"
              },
              {
                "field": "enriched_text.entities.mentions.location.begin",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "double"
              },
              {
                "field": "enriched_text.entities.mentions.location.end",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "double"
              },
              {
                "field": "enriched_text.entities.mentions.text",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "string"
              },
              {
                "field": "enriched_text.entities.model_name",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "string"
              },
              {
                "field": "enriched_text.entities.text",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "string"
              },
              {
                "field": "enriched_text.entities.type",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "string"
              },
              {
                "field": "extracted_metadata.file_type",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "string"
              },
              {
                "field": "extracted_metadata.filename",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "string"
              },
              {
                "field": "extracted_metadata.numPages",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "string"
              },
              {
                "field": "extracted_metadata.publicationdate",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "date"
              },
              {
                "field": "extracted_metadata.sha1",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "string"
              },
              {
                "field": "metadata",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "nested"
              },
              {
                "field": "metadata.customer_id",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "string"
              },
              {
                "field": "metadata.parent_document_id",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "string"
              },
              {
                "field": "text",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "string"
              },
              {
                "field": "document_id",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "string"
              }
            ]
          }
        • {
            "fields": [
              {
                "field": "enriched_text",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "nested"
              },
              {
                "field": "enriched_text.entities",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "nested"
              },
              {
                "field": "enriched_text.entities.mentions",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "nested"
              },
              {
                "field": "enriched_text.entities.mentions.location.begin",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "double"
              },
              {
                "field": "enriched_text.entities.mentions.location.end",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "double"
              },
              {
                "field": "enriched_text.entities.mentions.text",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "string"
              },
              {
                "field": "enriched_text.entities.model_name",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "string"
              },
              {
                "field": "enriched_text.entities.text",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "string"
              },
              {
                "field": "enriched_text.entities.type",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "string"
              },
              {
                "field": "extracted_metadata.file_type",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "string"
              },
              {
                "field": "extracted_metadata.filename",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "string"
              },
              {
                "field": "extracted_metadata.numPages",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "string"
              },
              {
                "field": "extracted_metadata.publicationdate",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "date"
              },
              {
                "field": "extracted_metadata.sha1",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "string"
              },
              {
                "field": "metadata",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "nested"
              },
              {
                "field": "metadata.customer_id",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "string"
              },
              {
                "field": "metadata.parent_document_id",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "string"
              },
              {
                "field": "text",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "string"
              },
              {
                "field": "document_id",
                "collection_id": "a3a41b30-8336-dc17-0000-017b75119cfe",
                "type": "string"
              }
            ]
          }

        List collections

        Lists existing collections for the specified project.

        Lists existing collections for the specified project.

        Lists existing collections for the specified project.

        Lists existing collections for the specified project.

        Lists existing collections for the specified project.

        GET /v2/projects/{project_id}/collections
        ServiceCall<ListCollectionsResponse> listCollections(ListCollectionsOptions listCollectionsOptions)
        listCollections(params)
        list_collections(
                self,
                project_id: str,
                **kwargs,
            ) -> DetailedResponse
        ListCollections(string projectId)

        Request

        Use the ListCollectionsOptions.Builder to create a ListCollectionsOptions object that contains the parameter values for the listCollections method.

        Path Parameters

        • The ID of the project. This information can be found from the Integrate and Deploy page in Discovery.

          Possible values: 1 ≤ length ≤ 255, Value must match regular expression ^[a-zA-Z0-9_-]*$

        Query Parameters

        • Release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. The current version is 2023-03-31.

        The listCollections options.

        parameters

        • The ID of the project. This information can be found from the Integrate and Deploy page in Discovery.

          Possible values: 1 ≤ length ≤ 255, Value must match regular expression /^[a-zA-Z0-9_-]*$/

        parameters

        • The ID of the project. This information can be found from the Integrate and Deploy page in Discovery.

          Possible values: 1 ≤ length ≤ 255, Value must match regular expression /^[a-zA-Z0-9_-]*$/

        parameters

        • The ID of the project. This information can be found from the Integrate and Deploy page in Discovery.

          Possible values: 1 ≤ length ≤ 255, Value must match regular expression /^[a-zA-Z0-9_-]*$/

        • curl {auth} "{url}/v2/projects/{project_id}/collections?version=2023-03-31"
        • CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator(
              url: "https://{cpd_cluster_host}{:port}/icp4d-api/v1/authorize",
              username: "{username}",
              password: "{password}"
              );
          
          DiscoveryService service = new DiscoveryService("2020-08-30", authenticator);
          service.SetServiceUrl("{https://{cpd_cluster_host}{:port}/discovery/{release}/instances/{instance_id}/api}");
          
          var result = service.ListCollections(
              projectId: "{project_id}"
              );
          
          Console.WriteLine(result.Response);
        • CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator("https://{cpd_cluster_host}{:port}/icp4d-api/v1/authorize", "{username}", "{password}");
          Discovery discovery = new Discovery("2020-08-30", authenticator);
          discovery.setServiceUrl("https://{cpd_cluster_host}{:port}/discovery/{release}/instances/{instance_id}/api");
          
          ListCollectionsOptions options = new ListCollectionsOptions.Builder()
            .projectId("{project_id}")
            .build();
          
          ListCollectionsResponse response = discovery.listCollections(options).execute().getResult();
          
          System.out.println(response);
        • const DiscoveryV2 = require('ibm-watson/discovery/v2');
          const { CloudPakForDataAuthenticator } = require('ibm-watson/auth');
          
          const discovery = new DiscoveryV2({
            authenticator: new CloudPakForDataAuthenticator({
              url: 'https://{cpd_cluster_host}{:port}/icp4d-api/v1/authorize',
              username: '{username}',
              password: '{password}',
            }),
            version: '2020-08-30',
            serviceUrl: 'https://{cpd_cluster_host}{:port}/discovery/{release}/instances/{instance_id}/api',
          });
          
          const params = {
            projectId: '{projectId}',
          };
          
          discovery.listCollections(params)
            .then(response => {
              console.log(JSON.stringify(response.result, null, 2));
            })
            .catch(err => {
              console.log('error:', err);
            });
          
        • import json
          from ibm_watson import DiscoveryV2
          from ibm_cloud_sdk_core.authenticators import CloudPakForDataAuthenticator
          
          authenticator = CloudPakForDataAuthenticator(
                                        '{username}',
                                        '{password}',
                                        'https://{cpd_cluster_host}{:port}/icp4d-api/v1/authorize',
                                         disable_ssl_verification=True)
          discovery = DiscoveryV2(
            version='2020-08-30',
            authenticator=authenticator
          )
          discovery.set_service_url('{https://{cpd_cluster_host}{:port}/discovery/{release}/instances/{instance_id}/api}')
          
          response = discovery.list_collections(
            project_id='{project_id}'
          ).get_result()
          
          print(json.dumps(response, indent=2))
          

        Response

        Response object that contains an array of collection details.

        Response object that contains an array of collection details.

        Examples:
        View

        Response object that contains an array of collection details.

        Examples:
        View

        Response object that contains an array of collection details.

        Examples:
        View

        Response object that contains an array of collection details.

        Examples:
        View

        Status Code

        • Successful response.

        • Bad request.

        Example responses
        • {
            "collections": [
              {
                "collection_id": "f1360220-ea2d-4271-9d62-89a910b13c37",
                "name": "example"
              }
            ]
          }
        • {
            "collections": [
              {
                "collection_id": "f1360220-ea2d-4271-9d62-89a910b13c37",
                "name": "example"
              }
            ]
          }

        Create a collection

        Create a new collection in the specified project.

        Create a new collection in the specified project.

        Create a new collection in the specified project.

        Create a new collection in the specified project.

        Create a new collection in the specified project.

        POST /v2/projects/{project_id}/collections
        ServiceCall<CollectionDetails> createCollection(CreateCollectionOptions createCollectionOptions)
        createCollection(params)
        create_collection(
                self,
                project_id: str,
                name: str,
                *,
                description: str = None,
                language: str = None,
                enrichments: List['CollectionEnrichment'] = None,
                conversions: 'Conversions' = None,
                normalizations: List['NormalizationOperation'] = None,
                **kwargs,
            ) -> DetailedResponse
        CreateCollection(string projectId, string name, string description = null, string language = null, List<CollectionEnrichment> enrichments = null, Conversions conversions = null, List<NormalizationOperation> normalizations = null)

        Request

        Use the CreateCollectionOptions.Builder to create a CreateCollectionOptions object that contains the parameter values for the createCollection method.

        Path Parameters

        • The ID of the project. This information can be found from the Integrate and Deploy page in Discovery.

          Possible values: 1 ≤ length ≤ 255, Value must match regular expression ^[a-zA-Z0-9_-]*$

        Query Parameters

        • Release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. The current version is 2023-03-31.

        An object that represents the collection to be created.

        The createCollection options.

        parameters

        • The ID of the project. This information can be found from the Integrate and Deploy page in Discovery.

          Possible values: 1 ≤ length ≤ 255, Value must match regular expression /^[a-zA-Z0-9_-]*$/

        • The name of the collection.

          Possible values: 0 ≤ length ≤ 255

        • A description of the collection.

        • The language of the collection. For a list of supported languages, see the product documentation.

          Default: en

        • An array of enrichments that are applied to this collection. To get a list of enrichments that are available for a project, use the List enrichments method.

          If no enrichments are specified when the collection is created, the default enrichments for the project type are applied. For more information about project default settings, see the product documentation.

        • Document processing operations that occur during the document conversion phase of ingestion.

          Note: Available only from service instances that are managed by IBM Cloud.

        • Defines operations that normalize the JSON representation of data after enrichments are applied. Operations run in the order that is specified in this array.

          New fields that are added with a post-enrichment normalization are displayed in the JSON representation of query results, but are not available from product user interface pages, such as Manage fields.

          Note: Available only from service instances that are managed by IBM Cloud.

        parameters

        • The ID of the project. This information can be found from the Integrate and Deploy page in Discovery.

          Possible values: 1 ≤ length ≤ 255, Value must match regular expression /^[a-zA-Z0-9_-]*$/

        • The name of the collection.

          Possible values: 0 ≤ length ≤ 255

        • A description of the collection.

        • The language of the collection. For a list of supported languages, see the product documentation.

          Default: en

        • An array of enrichments that are applied to this collection. To get a list of enrichments that are available for a project, use the List enrichments method.

          If no enrichments are specified when the collection is created, the default enrichments for the project type are applied. For more information about project default settings, see the product documentation.

        • Document processing operations that occur during the document conversion phase of ingestion.

          Note: Available only from service instances that are managed by IBM Cloud.

        • Defines operations that normalize the JSON representation of data after enrichments are applied. Operations run in the order that is specified in this array.

          New fields that are added with a post-enrichment normalization are displayed in the JSON representation of query results, but are not available from product user interface pages, such as Manage fields.

          Note: Available only from service instances that are managed by IBM Cloud.

        parameters

        • The ID of the project. This information can be found from the Integrate and Deploy page in Discovery.

          Possible values: 1 ≤ length ≤ 255, Value must match regular expression /^[a-zA-Z0-9_-]*$/

        • The name of the collection.

          Possible values: 0 ≤ length ≤ 255

        • A description of the collection.

        • The language of the collection. For a list of supported languages, see the product documentation.

          Default: en

        • An array of enrichments that are applied to this collection. To get a list of enrichments that are available for a project, use the List enrichments method.

          If no enrichments are specified when the collection is created, the default enrichments for the project type are applied. For more information about project default settings, see the product documentation.

        • Document processing operations that occur during the document conversion phase of ingestion.

          Note: Available only from service instances that are managed by IBM Cloud.

        • Defines operations that normalize the JSON representation of data after enrichments are applied. Operations run in the order that is specified in this array.

          New fields that are added with a post-enrichment normalization are displayed in the JSON representation of query results, but are not available from product user interface pages, such as Manage fields.

          Note: Available only from service instances that are managed by IBM Cloud.

        • curl -X POST {auth} --header "Content-Type: application/json" --data "{ \"name\": \"Tutorials\",   \"description\": \"Instructional PDFs\" }" "{url}/v2/projects/{project_id}/collections?version=2023-03-31"

        Response

        A collection for storing documents.

        A collection for storing documents.

        A collection for storing documents.

        A collection for storing documents.

        A collection for storing documents.