Skip to content

rlbandeira/dotnet-standard-sdk

 
 

Repository files navigation

Watson Developer Cloud .NET Standard SDK

Build status Coverage Status wdc-community.slack.com

The .Net SDK uses the Watson Developer Cloud services, a collection of REST APIs and SDKs that use cognitive computing to solve complex problems.

Table of Contents

Before you begin

Ensure you have the following prerequisites:

Installing the Watson .NET Standard SDK

You can get the latest SDK packages through NuGet. Installation instructions can be found in the ReadMe of each package.

Or manually here.

Custom Request Headers

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);
}

Response Headers

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
}

IAM Authentication

You can authenticate using IAM rather than username and password. You can either allow the SDK to manage the token by providing your IAM apikey or manage the token yourself by providing an access token.

void Example()
{
    //  Provide either an iamApiKey or iamAccessToken to authenticate the service.
    TokenOptions iamAssistantTokenOptions = new TokenOptions()
    {
        IamApiKey = "<iam-apikey>",
        IamAccessToken = "<iam-access-token>"
    };

    _assistant = new AssistantService(iamAssistantTokenOptions, "<version-date>");
    var results = assistant.Message("<workspace-id>", "<message-request>");
}

Documentation

Click here for documentation by release and branch.

Questions

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.

Open Source @ IBM

Find more open source projects on the IBM Github Page.

License

This library is licensed under Apache 2.0. Full license text is available in LICENSE.

Contributing

See CONTRIBUTING.md.

About

🆕🆕🆕.NET Standard library to access Watson Services.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 97.5%
  • HTML 2.4%
  • PowerShell 0.1%