Can't access IBM Tone Analyzer API?

IBM Watson Services uses HTTP Header Authentication in Basic format. Therefore, using curl in the terminal, you should pass the-u or --user flag in the format user:password, or you can also send the Authentication Http Header in pattern: Basic user:password.

By adjusting your code for this second form, you can do it as follows:

$response = Curl::to('https://gateway-wdc.watsonplatform.net/tone-analyzer/api/v3/tone?version=2017-09-21&sentences=false')
        ->withHeader('Content-Type: application/json')
        ->withHeader('Authorization: Basic apikey:YOUR_TOKEN_HERE')
        ->withData(array('text' => $text))
        ->asJson()
        ->post();

Replace YOUR_TOKEN_HERE by your Tone Analyzer API access token.

https://developer.mozilla.org/docs/Web/HTTP/Authentication https://www.ibm.com/support/knowledgecenter/en/SSGMCP_5.3.0/com.ibm.cics.ts.internet.doc/topics/dfhtl2a.html

Hope this helps!


It's 401 status code which uses for unauthorized access, you need to login first before accessing the API.

I check the docs for this and here is the link, for login to the api before using it tone-analyzer#authentication

With some service instances, you authenticate to the API by using 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.