how to call ibm watson api from .net core how to call ibm watson api from .net core curl curl

how to call ibm watson api from .net core


You can use the Watson Developer Cloud .NET Standard SDK. Install the Personality Insights service via NuGet using

Install-Package IBM.WatsonDeveloperCloud.PersonalityInsights -Pre

Instantiate the service

// create a Personality Insights Service instancePersonalityInsightsService _personalityInsights = new PersonalityInsightsService();// set the credentials_personalityInsights.SetCredential("<username>", "<password>");

Call the service

var results = _personalityInsights.GetProfile(ProfileOptions.CreateOptions()                                                         .WithTextPlain()                                                         .AsEnglish()                                                         .AcceptJson()                                                         .AcceptEnglishLanguage()                                                         .WithBody("some text"));

In a future release you will be able to call the service using named parameters instead of building options.

var results = _personalityInsights.GetProfile(        "<input>",         "<content-type>",         "<content-language>",         "<accept>",         "<accept-language>",        "<raw-scores>",        "<csv-headers>"        "<consumption-preferences>",        "<version>"    );


in this case are you use curl to call the API? According your example...

Call the Personality Insights by providing the username and password that are provided in the service credentials for the service instance that you want to use. The API uses HTTP basic authentication.

For authentication:

curl -u "{username}":"{password}""https://gateway.watsonplatform.net/personality-insights/api/v3/{method}"

Bluemix collects data from all requests and uses the data to improve the Watson services.

Request logging:

curl -u "{username}":"{password}"--header "X-Watson-Learning-Opt-Out: true""https://gateway.watsonplatform.net/personality-insights/api/v3/{method}"

Methods to call and get the response:

curl -X POST -u "{username}:{password}"--header "Content-Type: application/json"--data-binary @profile.json"https://gateway.watsonplatform.net/personality-insights/api/v3/profile?version=2016-10-20&consumption_preferences=true&raw_scores=true"

IBM Watson API's uses standard HTTP response codes to indicate whether a method completed successfully.

  • 200-level response always indicates success.

  • 400-level response indicates some sort of failure.

  • 500-level response typically indicates an internal system error.

Check this documentation from IBM to develop, has all examples how to call and if have errors the reason for that. And this for verify how to work and how to use.

Demo here, you can fork from github if you want.