Introduction

IBM Watson™ Language Translator translates text from one language to another. The service offers multiple IBM provided translation models that you can customize based on your unique terminology and language. Use Language Translator to take news from across the globe and present it in your language, communicate with your customers in their own language, and more.

This documentation describes Java SDK major version 8. For details about how to migrate your code from the previous version see the migration guide.

This documentation describes Node SDK major version 5. For details about how to migrate your code from the previous version, see the migration guide.

This documentation describes Python SDK major version 4. For details about how to migrate your code from the previous version, see the migration guide.

This documentation describes Ruby SDK major version 1. For details about how to migrate your code from the previous version, see the migration guide.

This documentation describes .NET Standard SDK major version 4. For details about how to migrate your code from the previous version, see the migration guide.

This documentation describes Go SDK major version 1. For details about how to migrate your code from the previous version, see the migration guide.

This documentation describes Swift SDK major version 3. For details about how to migrate your code from the previous version, see the migration guide.

This documentation describes Unity SDK major version 4. For details about how to migrate your code from the previous version, see the migration guide.

Beginning with version 4.0.0, the Node SDK returns a Promise for all methods when a callback is not specified.

The package location moved to ibm-watson. It remains available at watson-developer-cloud but is not updated there. Use ibm-watson to stay up to date.

The IBM Watson Unity SDK has the following requirements.

  • The SDK requires Unity version 2018.2 or later to support 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 does not support the WebGL projects. Change your build settings to any platform except WebGL.

For 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>8.1.0</version>
</dependency>

Gradle

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

GitHub

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

Installation

npm install ibm-watson@^5.2.0

GitHub

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

Installation

pip install --upgrade "ibm-watson>=4.1.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@v1.2.0

GitHub

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

Cocoapods

pod 'IBMWatsonLanguageTranslatorV3', '~> 3.1.0'

Carthage

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

Swift Package Manager

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

GitHub

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

Package Manager

Install-Package IBM.Watson.LanguageTranslator.v3 -Version 4.1.0

.NET CLI

dotnet add package IBM.Watson.LanguageTranslator.v3 -version 4.1.0

PackageReference

<PackageReference Include="IBM.Watson.LanguageTranslator.v3" Version="4.1.0" />

GitHub

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

Github

Authentication

To authenticate to the API, you pass a bearer token in an Authorization header. The token is associated with a username.

For testing and development, you can use the bearer token that's displayed in the IBM Cloud Pak for Data web client. To find this token, view the details for the provisioned service instance. 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 IBM Cloud Pak for Data web client to use for authentication. Generate a token from that user's credentials with the POST preauth/validateAuth method.

To authenticate to the API, pass either username and password credentials or a bearer token that you generate. 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 IBM 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 preauth/validateAuth 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.

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 {cpd_cluster_host}, {:port}, and {instance_id}, view the service credentials by viewing the details for the provisioned service instance in the IBM Cloud Pak for Data web client.

Generating a bearer token. The response includes an accessToken property.

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

curl -k -u "{username}:{password}" "https://{cpd_cluster_host}{:port}/v1/preauth/validateAuth"

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

curl -H "Authorization: Bearer {token}" "https://{cpd_cluster_host}{:port}/v3/{method}"

SDK managing the token.

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

CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator("https://{cpd_cluster_host}{:port}", "{username}", "{password}");
LanguageTranslator languageTranslator = new LanguageTranslator("{version}", authenticator);
languageTranslator.setServiceUrl("https://{cpd_cluster_host}{:port}/language-translator/{release}/instances/{instance_id}/api");

SDK managing the token.

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

const LanguageTranslatorV3 = require('ibm-watson/language-translator/v3');
const { CloudPakForDataAuthenticator } = require('ibm-watson/auth');

const languageTranslator = new LanguageTranslatorV3({
  version: '{version}',
  authenticator: new CloudPakForDataAuthenticator({
    username: '{username}',
    password: '{password}',
    url: 'https://{cpd_cluster_host}{:port}',
  }),
  url: 'https://{cpd_cluster_host}{:port}/language-translator/{release}/instances/{instance_id}/api',
});

SDK managing the token.

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

from ibm_watson import LanguageTranslatorV3
from ibm_cloud_sdk_core.authenticators import CloudPakForDataAuthenticator

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

language_translator = LanguageTranslatorV3(
    version='{version}',
    authenticator=authenticator
)

language_translator.set_service_url('https://{cpd_cluster_host}{:port}/language-translator/{release}/instances/{instance_id}/api')

SDK managing the token.

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

require "ibm_watson/authenticators"
require "ibm_watson/language_translator_v3"
include IBMWatson

authenticator = Authenticators::CloudPakForDataAuthenticator.new(
  username: "{username}",
  password: "{password}",
  url: "https://{cpd_cluster_host}{:port}"
)
language_translator = LanguageTranslatorV3.new(
  version: "{version}",
  authenticator: authenticator
)
language_translator.service_url = "https://{cpd_cluster_host}{:port}/language-translator/{release}/instances/{instance_id}/api"

SDK managing the token.

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

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

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

  options := &languagetranslatorv3.LanguageTranslatorV3Options{
    Version: "{version}",
    Authenticator: authenticator,
  }

  languageTranslator, languageTranslatorErr := languagetranslatorv3.NewLanguageTranslatorV3(options)

  if languageTranslatorErr != nil {
    panic(languageTranslatorErr)
  }

  languageTranslator.SetServiceURL("https://{cpd_cluster_host}{:port}/language-translator/{release}/instances/{instance_id}/api")
}

SDK managing the token.

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

let authenticator = WatsonCloudPakForDataAuthenticator(username: "{username}", password: "{password}", url: "https://{cpd_cluster_host}{:port}")
let languageTranslator = LanguageTranslator(version: "{version}", authenticator: authenticator)
languageTranslator.serviceURL = "https://{cpd_cluster_host}{:port}/language-translator/{release}/instances/{instance_id}/api"

SDK managing the token.

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

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

LanguageTranslatorService languageTranslator = new LanguageTranslatorService("{version}", authenticator);
languageTranslator.SetServiceUrl("https://{cpd_cluster_host}{:port}/language-translator/{release}/instances/{instance_id}/api");

SDK managing the token.

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

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

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

var languageTranslator = new LanguageTranslatorService("{version}", authenticator);
languageTranslator.SetServiceUrl("https://{cpd_cluster_host}{:port}/language-translator/{release}/instances/{instance_id}/api");

Service endpoint

The service endpoint is based on the IBM Cloud Pak for Data cluster and add-on service instance. The URL follows this pattern:

https://{cpd_cluster_host}{:port}/language-translator/{release}/instances/{instance_id}/api
  • {cpd_cluster_host} represents the name or IP address of your deployed cluster.
  • {port} represents the port number on which the service listens.
  • {release} represents the release name that was specified when the Helm chart was installed.
  • {instance_id} represents the identifier of the service instance.

To find the base URL, view the details for the service instance from the IBM Cloud Pak for Data web client.

Use that URL in your requests to Language Translator for IBM Cloud Pak for Data API.

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

Set the correct service URL by calling the url parameter when you create the service instance.

Set the correct service URL by calling the url parameter when you create the service instance or by calling the set_url() method of the service instance.

Set the correct service URL by calling the url parameter when you create the service instance or by calling the url= method of the service instance.

Set the correct service URL by the URL parameter when you create the service instance or by calling the SetURL= 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 SetEndpoint() method of the service instance.

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

Example

curl -H "Authorization: Bearer {token}" -X {request_method} "https://{cpd_cluster_host}{:port}/language-translator/{release}/instances/{instance_id}/api/v3/{method}"

Example

CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator("https://{cpd_cluster_host}{:port}", "{username}", "{password}");
LanguageTranslator languageTranslator = new LanguageTranslator("{version}", authenticator);
languageTranslator.setServiceUrl("https://{cpd_cluster_host}{:port}/language-translator/{release}/instances/{instance_id}/api");

Example

const LanguageTranslatorV3 = require('ibm-watson/language-translator/v3');
const { CloudPakForDataAuthenticator } = require('ibm-watson/auth');

const languageTranslator = new LanguageTranslatorV3({
  version: '{version}',
  authenticator: new CloudPakForDataAuthenticator({
    username: '{username}',
    password: '{password}',
    url: 'https://{cpd_cluster_host}{:port}',
  }),
  url: 'https://{cpd_cluster_host}{:port}/language-translator/{release}/instances/{instance_id}/api',
});

Example

from ibm_watson import LanguageTranslatorV3
from ibm_cloud_sdk_core.authenticators import CloudPakForDataAuthenticator

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

language_translator = LanguageTranslatorV3(
    version='{version}',
    authenticator=authenticator
)

language_translator.set_service_url('https://{cpd_cluster_host}{:port}/language-translator/{release}/instances/{instance_id}/api')

Example

require "ibm_watson/authenticators"
require "ibm_watson/language_translator_v3"
include IBMWatson

authenticator = Authenticators::CLoudPakForDataAuthenticator.new(
  username: "{username}",
  password: "{password}",
  url: "https://{cpd_cluster_host}{:port}"
)
language_translator = LanguageTranslatorV3.new(
  version: "{version}",
  authenticator: authenticator
)
language_translator.service_url = "https://{cpd_cluster_host}{:port}/language-translator/{release}/instances/{instance_id}/api"

Example

languageTranslator, languageTranslatorErr := languagetranslatorv3.NewLanguageTranslatorV3(options)

if languageTranslatorErr != nil {
  panic(languageTranslatorErr)
}

languageTranslator.SetServiceURL("https://{cpd_cluster_host}{:port}/language-translator/{release}/instances/{instance_id}/api")

Example

let authenticator = CloudPakForDataAuthenticator(username: "{username}", password: "{password}", url: "https://{cpd_cluster_host}{:port}")
let languageTranslator = LanguageTranslator(version: "{version}", authenticator: authenticator)
languageTranslator.serviceURL = "https://{cpd_cluster_host}{:port}/language-translator/{release}/instances/{instance_id}/api"

Example

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

LanguageTranslatorService languageTranslator = new LanguageTranslatorService("{version}", authenticator);
languageTranslator.SetServiceUrl("https://{cpd_cluster_host}{:port}/language-translator/{release}/instances/{instance_id}/api");

Default URL

https://gateway.watsonplatform.net/language-translator/api

Example for the Washington DC location

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

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

var languageTranslator = new LanguageTranslatorService("{version}", authenticator);
languageTranslator.SetServiceUrl("https://{cpd_cluster_host}{:port}/language-translator/{release}/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 absolutely 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, update the call in two places. Specify True on disable_ssl_verification in the authenticator and on the set_disable_ssl_verification method for the service instance.

To disable SSL verification, specify true on 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 property to true in the Icp4dConfig object and set the DisableSslVerification method to true on the service instance.

To disable SSL verification, set the DisableSslVerification property in the Icp4dTokenOptions object.

Example that disables SSL verification

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

Example that disables SSL verification

CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator("https://{cpd_cluster_host}{:port}", "{username}", "{password}");
LanguageTranslator languageTranslator = new LanguageTranslator("{version}", authenticator);
languageTranslator.setServiceUrl("https://{cpd_cluster_host}{:port}/language-translator/{release}/instances/{instance_id}/api";

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

Example that disables SSL verification

const LanguageTranslatorV3 = require('ibm-watson/language-translator/v3');
const { CloudPakForDataAuthenticator } = require('ibm-watson/auth');

const languageTranslator = new LanguageTranslatorV3({
  version: '{version}',
  authenticator: new CloudPakForDataAuthenticator({
    username: '{username}',
    password: '{password}',
    url: 'https://{cpd_cluster_host}{:port}',
  }),
  url: 'https://{cpd_cluster_host}{:port}/language-translator/{release}/instances/{instance_id}/api',
  disableSslVerification: true,
});

Example that disables SSL verification

from ibm_watson import LanguageTranslatorV3
from ibm_cloud_sdk_core.authenticators import CloudPakForDataAuthenticator

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

language_translator = LanguageTranslatorV3(
    version='{version}',
    authenticator=authenticator
)

language_translator.set_service_url('https://{cpd_cluster_host}{:port}/language-translator/{release}/instances/{instance_id}/api')

language_translator.set_disable_ssl_verification(True)

Example that disables SSL verification

require "ibm_watson/authenticators"
require "ibm_watson/language_translator_v3"
include IBMWatson

authenticator = Authenticators::CLoudPakForDataAuthenticator.new(
  username: "{username}",
  password: "{password}",
  url: "https://{cpd_cluster_host}{:port}"
)
language_translator = LanguageTranslatorV3.new(
  version: "{version}",
  authenticator: authenticator
)
language_translator.service_url = "https://{cpd_cluster_host}{:port}/language-translator/{release}/instances/{instance_id}/api"

language_translator.configure_http_client(disable_ssl: true)

Example that disables SSL verification

languageTranslator, languageTranslatorErr := languagetranslatorv3.NewLanguageTranslatorV3(options)

if languageTranslatorErr != nil {
  panic(languageTranslatorErr)
}

languageTranslator.SetServiceURL("https://{cpd_cluster_host}{:port}/language-translator/{release}/instances/{instance_id}/api")

languageTranslator.DisableSSLVerification()

Example that disables SSL verification

let authenticator = WatsonCloudPakForDataAuthenticator(username: "{username}", password: "{password}", url: "https://{cpd_cluster_host}{:port}")
let languageTranslator = LanguageTranslator(version: "{version}", authenticator: authenticator)
languageTranslator.serviceURL = "https://{cpd_cluster_host}{:port}/language-translator/{release}/instances/{instance_id}/api"

languageTranslator.disableSSLVerification()

Example that disables SSL verification

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

LanguageTranslatorService languageTranslator = new LanguageTranslatorService("{version}", authenticator);
languageTranslator.SetServiceUrl("https://{cpd_cluster_host}{:port}/language-translator/{release}/instances/{instance_id}/api");

languageTranslator.DisableSslVerification(true);

Example that disables SSL verification

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

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

var languageTranslator = new LanguageTranslatorService("{version}", authenticator);
languageTranslator.SetServiceUrl("https://{cpd_cluster_host}{:port}/language-translator/{release}/instances/{instance_id}/api");

languageTranslator.DisableSslVerification = true;

Versioning

API requests require a version parameter that takes a date in the format version=YYYY-MM-DD. When we change the API in a backwards-incompatible way, we release a new version date.

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 Language Translator for IBM Cloud Pak for Data API, 2018-05-01. In some cases, differences in earlier versions are noted in the descriptions of parameters and response models.

Error handling

Language Translator for IBM Cloud Pak for Data 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 illegal argument was passed to the method.

When the Java SDK receives an error response from the Language Translator for IBM Cloud Pak for Data API 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 Language Translator for IBM Cloud Pak for Data 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 Language Translator for IBM Cloud Pak for Data service, it generates an ApiException that contains 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 Language Translator for IBM Cloud Pak for Data service, it generates an ApiException that contains 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 Language Translator service, it generates a ServiceResponseException that contains 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 Language Translator service, it generates an IBMError that contains 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

languageTranslator.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/languagetranslatorv3"

// Instantiate a service
languageTranslator, languageTranslatorErr := languagetranslatorv3.NewLanguageTranslatorV3(options)

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

// Call a method
result, response, responseErr := languageTranslator.methodName(&methodOptions)

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

Example error handling

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

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.

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.

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.

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.

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.

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.

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 "Authorization: Bearer {token}" -X {request_method} --header "Request-Header: {header_value}" "{url}/v3/{method}"

Example header parameter in a request

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

Example header parameter in a request

const parameters = {
  {parameters}
};

languageTranslator.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 = language_translator.methodName(
    parameters,
    headers = {
        'Custom-Header': '{header_value}'
    })

Example header parameter in a request

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

Example header parameter in a request

result, response, responseErr := languageTranslator.methodName(
  &methodOptions{
    Headers: map[string]string{
      "Accept": "application/json",
    },
  },
)

Example header parameter in a request

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

Example header parameter in a request

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

LanguageTranslatorService languageTranslator = new LanguageTranslatorService("{version}", authenticator);
languageTranslator.SetServiceUrl("https://{cpd_cluster_host}{:port}/language-translator/{release}/instances/{instance_id}/api");

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

Example header parameter in a request

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

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

var languageTranslator = new LanguageTranslatorService("{version}", authenticator);
languageTranslator.SetServiceUrl("https://{cpd_cluster_host}{:port}/language-translator/{release}/instances/{instance_id}/api");

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

Response details

Language Translator for IBM Cloud Pak for Data API 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 additional debugging information, include the --verbose (-v) option with the request.

Example request to access response headers

curl "Authorization: Bearer {token}" -X {request_method} --include "{url}/v3/{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 = languageTranslator.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

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

language_translator.set_detailed_response(True)
response = language_translator.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 = language_translator.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/languagetranslatorv3"
)

result, response, responseErr := languageTranslator.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

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

Example request to access response headers

var results = languageTranslator.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
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.

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()
{
    languageTranslator.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
}

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 = languageTranslator.method(parameters).execute();

Example asynchronous request

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

Example synchronous request

response = language_translator.method_name(parameters)

or

response = language_translator.await.method_name(parameters)

Example asynchronous request

response = language_translator.async.method_name(parameters)

Methods

Translate

Translates the input text from the source language to the target language.

Translates the input text from the source language to the target language.

Translates the input text from the source language to the target language.

Translates the input text from the source language to the target language.

Translates the input text from the source language to the target language.

Translates the input text from the source language to the target language.

Translates the input text from the source language to the target language.

Translates the input text from the source language to the target language.

Translates the input text from the source language to the target language.

POST /v3/translate
(languageTranslatorForIbmCloudPakForDataApi *LanguageTranslatorForIbmCloudPakForDataApiV3) Translate(translateOptions *TranslateOptions) (result *TranslationResult, response *core.DetailedResponse, err error)
ServiceCall<TranslationResult> translate(TranslateOptions translateOptions)
translate(params, [callback()])
translate(self, text, model_id=None, source=None, target=None, **kwargs)
translate(text:, model_id: nil, source: nil, target: nil)
func translate(
    text: [String],
    modelID: String? = nil,
    source: String? = nil,
    target: String? = nil,
    headers: [String: String]? = nil,
    completionHandler: @escaping (WatsonResponse<TranslationResult>?, WatsonError?) -> Void)
Translate(List<string> text, string modelId = null, string source = null, string target = null)
Translate(Callback<TranslationResult> callback, List<string> text, string modelId = null, string source = null, string target = null)
Request

Instantiate the TranslateOptions struct and set the fields to provide parameter values for the Translate method.

Use the TranslateOptions.Builder to create a TranslateOptions object that contains the parameter values for the translate method.

Query Parameters

  • Release date of the API version you want to use. Specify dates in YYYY-MM-DD format. The current version is 2018-05-01.

    Constraints: Value must match regular expression ^\d{4}-\d{2}-\d{2}$

The translate request containing the text, and either a model ID or source and target language pair.

Example:

The Translate options.

The translate options.

parameters

  • Input text in UTF-8 encoding. Multiple entries will result in multiple translations in the response.

  • A globally unique string that identifies the underlying model that is used for translation.

  • Translation source language code.

  • Translation target language code.

parameters

  • Input text in UTF-8 encoding. Multiple entries will result in multiple translations in the response.

  • A globally unique string that identifies the underlying model that is used for translation.

  • Translation source language code.

  • Translation target language code.

parameters

  • Input text in UTF-8 encoding. Multiple entries will result in multiple translations in the response.

  • A globally unique string that identifies the underlying model that is used for translation.

  • Translation source language code.

  • Translation target language code.

parameters

  • Input text in UTF-8 encoding. Multiple entries will result in multiple translations in the response.

  • A globally unique string that identifies the underlying model that is used for translation.

  • Translation source language code.

  • Translation target language code.

parameters

  • Input text in UTF-8 encoding. Multiple entries will result in multiple translations in the response.

  • A globally unique string that identifies the underlying model that is used for translation.

  • Translation source language code.

  • Translation target language code.

parameters

  • Input text in UTF-8 encoding. Multiple entries will result in multiple translations in the response.

  • A globally unique string that identifies the underlying model that is used for translation.

  • Translation source language code.

  • Translation target language code.

Response

Status Code

  • Success

  • Invalid request. See the response body for details.

  • Model Not Found: the specified model_id does not exist or specified source - target language pair is not supported

Example responses

List identifiable languages

Lists the languages that the service can identify. Returns the language code (for example, en for English or es for Spanish) and name of each language.

Lists the languages that the service can identify. Returns the language code (for example, en for English or es for Spanish) and name of each language.

Lists the languages that the service can identify. Returns the language code (for example, en for English or es for Spanish) and name of each language.

Lists the languages that the service can identify. Returns the language code (for example, en for English or es for Spanish) and name of each language.

Lists the languages that the service can identify. Returns the language code (for example, en for English or es for Spanish) and name of each language.

Lists the languages that the service can identify. Returns the language code (for example, en for English or es for Spanish) and name of each language.

Lists the languages that the service can identify. Returns the language code (for example, en for English or es for Spanish) and name of each language.

Lists the languages that the service can identify. Returns the language code (for example, en for English or es for Spanish) and name of each language.

Lists the languages that the service can identify. Returns the language code (for example, en for English or es for Spanish) and name of each language.

GET /v3/identifiable_languages
(languageTranslatorForIbmCloudPakForDataApi *LanguageTranslatorForIbmCloudPakForDataApiV3) ListIdentifiableLanguages(listIdentifiableLanguagesOptions *ListIdentifiableLanguagesOptions) (result *IdentifiableLanguages, response *core.DetailedResponse, err error)
ServiceCall<IdentifiableLanguages> listIdentifiableLanguages()
listIdentifiableLanguages(params, [callback()])
list_identifiable_languages(self, **kwargs)
list_identifiable_languages
func listIdentifiableLanguages(
    headers: [String: String]? = nil,
    completionHandler: @escaping (WatsonResponse<IdentifiableLanguages>?, WatsonError?) -> Void)
ListIdentifiableLanguages()
ListIdentifiableLanguages(Callback<IdentifiableLanguages> callback)
Request

Query Parameters

  • Release date of the API version you want to use. Specify dates in YYYY-MM-DD format. The current version is 2018-05-01.

    Constraints: Value must match regular expression ^\d{4}-\d{2}-\d{2}$

No Request Parameters

This method does not accept any request parameters.

No Request Parameters

This method does not accept any request parameters.

No Request Parameters

This method does not accept any request parameters.

No Request Parameters

This method does not accept any request parameters.

No Request Parameters

This method does not accept any request parameters.

No Request Parameters

This method does not accept any request parameters.

No Request Parameters

This method does not accept any request parameters.

No Request Parameters

This method does not accept any request parameters.

Response

Status Code

  • Success

  • Invalid request. See the response body for details.

Example responses

Identify language

Identifies the language of the input text.

Identifies the language of the input text.

Identifies the language of the input text.

Identifies the language of the input text.

Identifies the language of the input text.

Identifies the language of the input text.

Identifies the language of the input text.

Identifies the language of the input text.

Identifies the language of the input text.

POST /v3/identify
(languageTranslatorForIbmCloudPakForDataApi *LanguageTranslatorForIbmCloudPakForDataApiV3) Identify(identifyOptions *IdentifyOptions) (result *IdentifiedLanguages, response *core.DetailedResponse, err error)
ServiceCall<IdentifiedLanguages> identify(IdentifyOptions identifyOptions)
identify(params, [callback()])
identify(self, text, **kwargs)
identify(text:)
func identify(
    text: String,
    headers: [String: String]? = nil,
    completionHandler: @escaping (WatsonResponse<IdentifiedLanguages>?, WatsonError?) -> Void)
Identify(string text)
Identify(Callback<IdentifiedLanguages> callback, string text)
Request

Instantiate the IdentifyOptions struct and set the fields to provide parameter values for the Identify method.

Use the IdentifyOptions.Builder to create a IdentifyOptions object that contains the parameter values for the identify method.

Query Parameters

  • Release date of the API version you want to use. Specify dates in YYYY-MM-DD format. The current version is 2018-05-01.

    Constraints: Value must match regular expression ^\d{4}-\d{2}-\d{2}$

Input text in UTF-8 format.

The Identify options.

The identify options.

parameters

  • Input text in UTF-8 format.

parameters

  • Input text in UTF-8 format.

parameters

  • Input text in UTF-8 format.

parameters

  • Input text in UTF-8 format.

parameters

  • Input text in UTF-8 format.

parameters

  • Input text in UTF-8 format.

Response

Status Code

  • Success

  • Invalid request. See the response body for details.

Example responses

List models

Lists available translation models.

Lists available translation models.

Lists available translation models.

Lists available translation models.

Lists available translation models.

Lists available translation models.

Lists available translation models.

Lists available translation models.

Lists available translation models.

GET /v3/models
(languageTranslatorForIbmCloudPakForDataApi *LanguageTranslatorForIbmCloudPakForDataApiV3) ListModels(listModelsOptions *ListModelsOptions) (result *TranslationModels, response *core.DetailedResponse, err error)
ServiceCall<TranslationModels> listModels(ListModelsOptions listModelsOptions)
listModels(params, [callback()])
list_models(self, source=None, target=None, default=None, **kwargs)
list_models(source: nil, target: nil, default: nil)
func listModels(
    source: String? = nil,
    target: String? = nil,
    `default`: Bool? = nil,
    headers: [String: String]? = nil,
    completionHandler: @escaping (WatsonResponse<TranslationModels>?, WatsonError?) -> Void)
ListModels(string source = null, string target = null, bool? _default = null)
ListModels(Callback<TranslationModels> callback, string source = null, string target = null, bool? _default = null)
Request

Instantiate the ListModelsOptions struct and set the fields to provide parameter values for the ListModels method.

Use the ListModelsOptions.Builder to create a ListModelsOptions object that contains the parameter values for the listModels method.

Query Parameters

  • Release date of the API version you want to use. Specify dates in YYYY-MM-DD format. The current version is 2018-05-01.

    Constraints: Value must match regular expression ^\d{4}-\d{2}-\d{2}$

  • Specify a language code to filter results by source language.

  • Specify a language code to filter results by target language.

  • If the default parameter isn't specified, the service will return all models (default and non-default) for each language pair. To return only default models, set this to true. To return only non-default models, set this to false. There is exactly one default model per language pair, the IBM provided base model.

The ListModels options.

The listModels options.

parameters

  • Specify a language code to filter results by source language.

  • Specify a language code to filter results by target language.

  • If the default parameter isn't specified, the service will return all models (default and non-default) for each language pair. To return only default models, set this to true. To return only non-default models, set this to false. There is exactly one default model per language pair, the IBM provided base model.

parameters

  • Specify a language code to filter results by source language.

  • Specify a language code to filter results by target language.

  • If the default parameter isn't specified, the service will return all models (default and non-default) for each language pair. To return only default models, set this to true. To return only non-default models, set this to false. There is exactly one default model per language pair, the IBM provided base model.

parameters

  • Specify a language code to filter results by source language.

  • Specify a language code to filter results by target language.

  • If the default parameter isn't specified, the service will return all models (default and non-default) for each language pair. To return only default models, set this to true. To return only non-default models, set this to false. There is exactly one default model per language pair, the IBM provided base model.

parameters

  • Specify a language code to filter results by source language.

  • Specify a language code to filter results by target language.

  • If the default parameter isn't specified, the service will return all models (default and non-default) for each language pair. To return only default models, set this to true. To return only non-default models, set this to false. There is exactly one default model per language pair, the IBM provided base model.

parameters

  • Specify a language code to filter results by source language.

  • Specify a language code to filter results by target language.

  • If the default parameter isn't specified, the service will return all models (default and non-default) for each language pair. To return only default models, set this to true. To return only non-default models, set this to false. There is exactly one default model per language pair, the IBM provided base model.

parameters

  • Specify a language code to filter results by source language.

  • Specify a language code to filter results by target language.

  • If the default parameter isn't specified, the service will return all models (default and non-default) for each language pair. To return only default models, set this to true. To return only non-default models, set this to false. There is exactly one default model per language pair, the IBM provided base model.

Response

The response type for listing existing translation models.

The response type for listing existing translation models.

The response type for listing existing translation models.

The response type for listing existing translation models.

The response type for listing existing translation models.

The response type for listing existing translation models.

The response type for listing existing translation models.

The response type for listing existing translation models.

The response type for listing existing translation models.

Status Code

  • Success

  • Invalid request. See the response body for details.

Example responses

Get model details

Gets information about a translation model, including training status for custom models. Use this API call to poll the status of your customization request. A successfully completed training will have a status of available.

Gets information about a translation model, including training status for custom models. Use this API call to poll the status of your customization request. A successfully completed training will have a status of available.

Gets information about a translation model, including training status for custom models. Use this API call to poll the status of your customization request. A successfully completed training will have a status of available.

Gets information about a translation model, including training status for custom models. Use this API call to poll the status of your customization request. A successfully completed training will have a status of available.

Gets information about a translation model, including training status for custom models. Use this API call to poll the status of your customization request. A successfully completed training will have a status of available.

Gets information about a translation model, including training status for custom models. Use this API call to poll the status of your customization request. A successfully completed training will have a status of available.

Gets information about a translation model, including training status for custom models. Use this API call to poll the status of your customization request. A successfully completed training will have a status of available.

Gets information about a translation model, including training status for custom models. Use this API call to poll the status of your customization request. A successfully completed training will have a status of available.

Gets information about a translation model, including training status for custom models. Use this API call to poll the status of your customization request. A successfully completed training will have a status of available.

GET /v3/models/{model_id}
(languageTranslatorForIbmCloudPakForDataApi *LanguageTranslatorForIbmCloudPakForDataApiV3) GetModel(getModelOptions *GetModelOptions) (result *TranslationModel, response *core.DetailedResponse, err error)
ServiceCall<TranslationModel> getModel(GetModelOptions getModelOptions)
getModel(params, [callback()])
get_model(self, model_id, **kwargs)
get_model(model_id:)
func getModel(
    modelID: String,
    headers: [String: String]? = nil,
    completionHandler: @escaping (WatsonResponse<TranslationModel>?, WatsonError?) -> Void)
GetModel(string modelId)
GetModel(Callback<TranslationModel> callback, string modelId)
Request

Instantiate the GetModelOptions struct and set the fields to provide parameter values for the GetModel method.

Use the GetModelOptions.Builder to create a GetModelOptions object that contains the parameter values for the getModel method.

Path Parameters

  • Model ID of the model to get

Query Parameters

  • Release date of the API version you want to use. Specify dates in YYYY-MM-DD format. The current version is 2018-05-01.

    Constraints: Value must match regular expression ^\d{4}-\d{2}-\d{2}$

The GetModel options.

The getModel options.

parameters

  • Model ID of the model to get.

parameters

  • Model ID of the model to get.

parameters

  • Model ID of the model to get.

parameters

  • Model ID of the model to get.

parameters

  • Model ID of the model to get.

parameters

  • Model ID of the model to get.

Response

Response payload for models.

Response payload for models.

Response payload for models.

Response payload for models.

Response payload for models.

Response payload for models.

Response payload for models.

Response payload for models.

Response payload for models.

Status Code

  • Status : OK

  • Invalid request. See the response body for details.

  • The specified model was not found.

Example responses

List documents

Lists documents that have been submitted for translation

Lists documents that have been submitted for translation.

Lists documents that have been submitted for translation.

Lists documents that have been submitted for translation.

Lists documents that have been submitted for translation.

Lists documents that have been submitted for translation.

Lists documents that have been submitted for translation.

Lists documents that have been submitted for translation.

Lists documents that have been submitted for translation.

GET /v3/documents
(languageTranslatorForIbmCloudPakForDataApi *LanguageTranslatorForIbmCloudPakForDataApiV3) ListDocuments(listDocumentsOptions *ListDocumentsOptions) (result *DocumentList, response *core.DetailedResponse, err error)
ServiceCall<DocumentList> listDocuments()
listDocuments(params, [callback()])
list_documents(self, **kwargs)
list_documents
func listDocuments(
    headers: [String: String]? = nil,
    completionHandler: @escaping (WatsonResponse<DocumentList>?, WatsonError?) -> Void)
ListDocuments()
ListDocuments(Callback<DocumentList> callback)
Request

Query Parameters

  • Release date of the API version you want to use. Specify dates in YYYY-MM-DD format. The current version is 2018-05-01.

    Constraints: Value must match regular expression ^\d{4}-\d{2}-\d{2}$

No Request Parameters

This method does not accept any request parameters.

No Request Parameters

This method does not accept any request parameters.

No Request Parameters

This method does not accept any request parameters.

No Request Parameters

This method does not accept any request parameters.

No Request Parameters

This method does not accept any request parameters.

No Request Parameters

This method does not accept any request parameters.

No Request Parameters

This method does not accept any request parameters.

No Request Parameters

This method does not accept any request parameters.

Response

Status Code

  • Success

  • Invalid request. See the response body for details.

Example responses

Translate document

Submit a document for translation. You can submit the document contents in the file parameter, or you can reference a previously submitted document by document ID.

Submit a document for translation. You can submit the document contents in the file parameter, or you can reference a previously submitted document by document ID.

Submit a document for translation. You can submit the document contents in the file parameter, or you can reference a previously submitted document by document ID.

Submit a document for translation. You can submit the document contents in the file parameter, or you can reference a previously submitted document by document ID.

Submit a document for translation. You can submit the document contents in the file parameter, or you can reference a previously submitted document by document ID.

Submit a document for translation. You can submit the document contents in the file parameter, or you can reference a previously submitted document by document ID.

Submit a document for translation. You can submit the document contents in the file parameter, or you can reference a previously submitted document by document ID.

Submit a document for translation. You can submit the document contents in the file parameter, or you can reference a previously submitted document by document ID.

Submit a document for translation. You can submit the document contents in the file parameter, or you can reference a previously submitted document by document ID.

POST /v3/documents
(languageTranslatorForIbmCloudPakForDataApi *LanguageTranslatorForIbmCloudPakForDataApiV3) TranslateDocument(translateDocumentOptions *TranslateDocumentOptions) (result *DocumentStatus, response *core.DetailedResponse, err error)
ServiceCall<DocumentStatus> translateDocument(TranslateDocumentOptions translateDocumentOptions)
translateDocument(params, [callback()])
translate_document(self, file, filename=None, file_content_type=None, model_id=None, source=None, target=None, document_id=None, **kwargs)
translate_document(file:, filename: nil, file_content_type: nil, model_id: nil, source: nil, target: nil, document_id: nil)
func translateDocument(
    file: Data,
    filename: String,
    fileContentType: String? = nil,
    modelID: String? = nil,
    source: String? = nil,
    target: String? = nil,
    documentID: String? = nil,
    headers: [String: String]? = nil,
    completionHandler: @escaping (WatsonResponse<DocumentStatus>?, WatsonError?) -> Void)
TranslateDocument(System.IO.MemoryStream file, string filename, string fileContentType = null, string modelId = null, string source = null, string target = null, string documentId = null)
TranslateDocument(Callback<DocumentStatus> callback, System.IO.MemoryStream file, string filename, string fileContentType = null, string modelId = null, string source = null, string target = null, string documentId = null)
Request

Instantiate the TranslateDocumentOptions struct and set the fields to provide parameter values for the TranslateDocument method.

Use the TranslateDocumentOptions.Builder to create a TranslateDocumentOptions object that contains the parameter values for the translateDocument method.

Query Parameters

  • Release date of the API version you want to use. Specify dates in YYYY-MM-DD format. The current version is 2018-05-01.

    Constraints: Value must match regular expression ^\d{4}-\d{2}-\d{2}$

Form Parameters

  • The source file to translate.

    Supported file types

    Maximum file size: 20 MB

  • The model to use for translation. model_id or both source and target are required.

  • Language code that specifies the language of the source document.

  • Language code that specifies the target language for translation.

  • To use a previously submitted document as the source for a new translation, enter the document_id of the document.

The TranslateDocument options.

The translateDocument options.

parameters

  • The source file to translate.

    Supported file types

    Maximum file size: 20 MB.

  • The filename for file.

  • The content type of file.

    Allowable values: [application/powerpoint,application/mspowerpoint,application/x-rtf,application/json,application/xml,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.oasis.opendocument.spreadsheet,application/vnd.oasis.opendocument.presentation,application/vnd.oasis.opendocument.text,application/pdf,application/rtf,text/html,text/json,text/plain,text/richtext,text/rtf,text/xml]

  • The model to use for translation. model_id or both source and target are required.

  • Language code that specifies the language of the source document.

  • Language code that specifies the target language for translation.

  • To use a previously submitted document as the source for a new translation, enter the document_id of the document.

parameters

  • The source file to translate.

    Supported file types

    Maximum file size: 20 MB.

  • The filename for file.

  • The content type of file.

    Allowable values: [application/powerpoint,application/mspowerpoint,application/x-rtf,application/json,application/xml,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.oasis.opendocument.spreadsheet,application/vnd.oasis.opendocument.presentation,application/vnd.oasis.opendocument.text,application/pdf,application/rtf,text/html,text/json,text/plain,text/richtext,text/rtf,text/xml]

  • The model to use for translation. model_id or both source and target are required.

  • Language code that specifies the language of the source document.

  • Language code that specifies the target language for translation.

  • To use a previously submitted document as the source for a new translation, enter the document_id of the document.

parameters

  • The source file to translate.

    Supported file types

    Maximum file size: 20 MB.

  • The filename for file.

  • The content type of file.

    Allowable values: [application/powerpoint,application/mspowerpoint,application/x-rtf,application/json,application/xml,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.oasis.opendocument.spreadsheet,application/vnd.oasis.opendocument.presentation,application/vnd.oasis.opendocument.text,application/pdf,application/rtf,text/html,text/json,text/plain,text/richtext,text/rtf,text/xml]

  • The model to use for translation. model_id or both source and target are required.

  • Language code that specifies the language of the source document.

  • Language code that specifies the target language for translation.

  • To use a previously submitted document as the source for a new translation, enter the document_id of the document.

parameters

  • The source file to translate.

    Supported file types

    Maximum file size: 20 MB.

  • The filename for file.

  • The content type of file.

    Allowable values: [application/powerpoint,application/mspowerpoint,application/x-rtf,application/json,application/xml,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.oasis.opendocument.spreadsheet,application/vnd.oasis.opendocument.presentation,application/vnd.oasis.opendocument.text,application/pdf,application/rtf,text/html,text/json,text/plain,text/richtext,text/rtf,text/xml]

  • The model to use for translation. model_id or both source and target are required.

  • Language code that specifies the language of the source document.

  • Language code that specifies the target language for translation.

  • To use a previously submitted document as the source for a new translation, enter the document_id of the document.

parameters

  • The source file to translate.

    Supported file types

    Maximum file size: 20 MB.

  • The filename for file.

  • The content type of file.

    Allowable values: [application/powerpoint,application/mspowerpoint,application/x-rtf,application/json,application/xml,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.oasis.opendocument.spreadsheet,application/vnd.oasis.opendocument.presentation,application/vnd.oasis.opendocument.text,application/pdf,application/rtf,text/html,text/json,text/plain,text/richtext,text/rtf,text/xml]

  • The model to use for translation. model_id or both source and target are required.

  • Language code that specifies the language of the source document.

  • Language code that specifies the target language for translation.

  • To use a previously submitted document as the source for a new translation, enter the document_id of the document.

parameters

  • The source file to translate.

    Supported file types

    Maximum file size: 20 MB.

  • The filename for file.

  • The content type of file.

    Allowable values: [application/powerpoint,application/mspowerpoint,application/x-rtf,application/json,application/xml,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.oasis.opendocument.spreadsheet,application/vnd.oasis.opendocument.presentation,application/vnd.oasis.opendocument.text,application/pdf,application/rtf,text/html,text/json,text/plain,text/richtext,text/rtf,text/xml]

  • The model to use for translation. model_id or both source and target are required.

  • Language code that specifies the language of the source document.

  • Language code that specifies the target language for translation.

  • To use a previously submitted document as the source for a new translation, enter the document_id of the document.

Response

Document information, including translation status.

Document information, including translation status.

Document information, including translation status.

Document information, including translation status.

Document information, including translation status.

Document information, including translation status.

Document information, including translation status.

Document information, including translation status.

Document information, including translation status.

Status Code

  • Success. Use the returned document_id with the Get document status method to get the status of the translation.

  • Invalid request. See the response body for details.

  • The specified document was not found.

Example responses

Get document status

Gets the translation status of a document

Gets the translation status of a document.

Gets the translation status of a document.

Gets the translation status of a document.

Gets the translation status of a document.

Gets the translation status of a document.

Gets the translation status of a document.

Gets the translation status of a document.

Gets the translation status of a document.

GET /v3/documents/{document_id}
(languageTranslatorForIbmCloudPakForDataApi *LanguageTranslatorForIbmCloudPakForDataApiV3) GetDocumentStatus(getDocumentStatusOptions *GetDocumentStatusOptions) (result *DocumentStatus, response *core.DetailedResponse, err error)
ServiceCall<DocumentStatus> getDocumentStatus(GetDocumentStatusOptions getDocumentStatusOptions)
getDocumentStatus(params, [callback()])