The .Net SDK uses the Watson Developer Cloud services, a collection of REST APIs and SDKs that use cognitive computing to solve complex problems.
- Before you begin
- Installing the Watson .NET Standard SDK
- Documentation
- Questions
- Open Source @ IBM
- License
- Contributing
Ensure you have the following prerequisites:
- You need an IBM Cloud account.
- Install Visual Studio for Windows or Visual Studio Code for OSX or Linux.
- Install .NET Core.
You can get the latest SDK packages through NuGet. Installation instructions can be found in the ReadMe of each package.
- Assistant
- Conversation
- Discovery
- Language Translator V2 (deprecated)
- Language Translator V3
- Natural Language Understanding
- Natural Language Classifier
- Personality Insights
- Speech to Text
- Text to Speech
- Tone Analyzer
- Visual Recognition
Or manually here.
Watson services are migrating to token-based Identity and Access Management (IAM) authentication.
- With some service instances, you authenticate to the API by using IAM.
- In other instances, you authenticate by providing the username and password for the service instance.
- Visual Recognition uses a form of API key only with instances created before May 23, 2018. Newer instances of Visual Recognition use IAM.
To find out which authentication to use, view the service credentials. You find the service credentials for authentication the same way for all Watson services:
- Go to the IBM Cloud [Dashboard][watson-dashboard] page.
- Either click an existing Watson service instance or click Create.
- Click Show to view your service credentials.
- Copy the
url
and eitherapikey
orusername
andpassword
.
In your code, you can use these values in the service constructor or with a method call after instantiating your service.
Some services use token-based Identity and Access Management (IAM) authentication. IAM authentication uses a service API key to get an access token that is passed with the call. Access tokens are valid for approximately one hour and must be regenerated.
You supply either an IAM service API key or an access token:
- 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 if you want to manage the lifecycle yourself. For details, see Authenticating with IAM tokens. If you want to switch to API key override your stored IAM credentials with an IAM API key.
void Example()
{
TokenOptions iamAssistantTokenOptions = new TokenOptions()
{
IamApiKey = "<iam-apikey>",
IamUrl = "<service-endpoint>"
};
_assistant = new AssistantService(iamAssistantTokenOptions, "<version-date>");
}
void Example()
{
TokenOptions iamAssistantTokenOptions = new TokenOptions()
{
IamAccessToken = "<iam-access-token>"
};
_assistant = new AssistantService(iamAssistantTokenOptions, "<version-date>");
}
void Example()
{
_assistant = new AssistantService("<username>", "<password>", "<version-date>");
}
Important: This type of authentication works only with Visual Recognition instances created before May 23, 2018. Newer instances of Visual Recognition use IAM.
void Example()
{
_visualRecognition = new VisualRecognitionService("<apikey>", "<version-date>");
}
You can send custom request headers by adding them to the customData
object.
void Example()
{
AssistantService assistant = new AssistantService("<username>", "<password>", "<version-date>");
// Create customData object
Dictionary<string, object> customData = new Dictionary<string, object>();
// Create a dictionary of custom headers
Dictionary<string, string> customHeaders = new Dictionary<string, string>();
// Add to the header dictionary
customHeaders.Add("X-Watson-Metadata", "customer_id=some-assistant-customer-id");
// Add the header dictionary to the custom data object
customData.Add(Constants.String.CUSTOM_REQUEST_HEADERS, customHeaders);
var results = assistant.Message("<workspace-id>", "<message-request>", customData: customData);
}
You can get the response headers and the raw json response in the result object.
void Example()
{
AssistantService assistant = new AssistantService("<username>", "<password>", "<version-date>");
var results = assistant.Message("<workspace-id>", "<message-request>");
var responseHeaders = results.ResponseHeaders; // The response headers
var responseJson = results.ResponseJson; // The raw response json
}
Click here for documentation by release and branch.
If you are having difficulties using the APIs or have a question about the IBM Watson Services, please ask a question on dW Answers or Stack Overflow.
Find more open source projects on the IBM Github Page.
This library is licensed under Apache 2.0. Full license text is available in LICENSE.
See CONTRIBUTING.md.