I am executing the code below.. I have supplied the correct API but keep getting an authentication error (provided below)
Here's the code snippet
// Example 1: sets up service wrapper, sends initial message, and
// receives response.
const AssistantV2 = require('ibm-watson/assistant/v2');
// Set up Assistant service wrapper.
const service = new AssistantV2({
iam_apikey: 'xxx', // replace with API key
version: '2019-02-28',
});
const assistantId = 'xxx'; // replace with assistant ID
let sessionId;
Here's the error message
C:\Users\User\Desktop\Insurancebot\test>node sample.js
{ Unauthorized: Access is denied due to invalid credentials.
at RequestWrapper.formatError (C:\Users\User\node_modules\ibm-cloud-sdk-core\lib\requestwrapper.js:219:21)
at C:\Users\User\node_modules\ibm-cloud-sdk-core\lib\requestwrapper.js:207:29
at process._tickCallback (internal/process/next_tick.js:68:7)
name: 'Unauthorized',
code: 401,
message: 'Access is denied due to invalid credentials.',
body: '{"code":401,"error":"Unauthorized"}',
headers:
{ 'x-backside-transport': 'FAIL FAIL',
'content-type': 'application/json',
'x-dp-transit-id': 'gateway02-3627341245',
'x-global-transaction-id': 'ffea405d5d0083b9d834d5bd',
'strict-transport-security': 'max-age=31536000;',
'x-dp-watson-tran-id': 'gateway02-3627341245',
'content-length': '37',
'x-edgeconnect-midmile-rtt': '110',
'x-edgeconnect-origin-mex-latency': '132',
date: 'Wed, 12 Jun 2019 04:46:49 GMT',
connection: 'close' } }
Outside of the wrong IAM key, the most common cause is the wrong service endpoint being used.
It defaults to US, so if you have set up your assistant in UK for example, you would set: url: 'https://gateway-lon.watsonplatform.net/assistant/api'
The full list is here:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.