简体   繁体   中英

How to find api-key and password for ibm-watson for Watson Assistant API working with nodejs

I'm trying to access my assistant but I'm getting a 404 Not Found error when inserting the iam_api_key and the url provided in the dahsboard. And I can't find the password in the dahsboard.

I'm working with Node.js. I've tried to create other service credentials but nothing worked

{
    username: '{api-key}',
    password: '{password}', // I can't find this
    // OR even
    iam_apikey: '{api-key}'
    url: '{url}',
    version:  '{version}',
    disable_ssl_verification: true,
}

{ Not Found: Resource not found

{ ... }

at at process._tickCallback (internal/process/next_tick.js:188:7) name: 'Not Found', code: 404, message: 'Resource not found',
body: '{"error":"Resource not found","code":404}', headers: { 'x-backside-transport': 'FAIL FAIL', 'content-type': 'application/json; charset=utf-8', 'access-control-allow-origin': '*', 'access-control-allow-methods': 'GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS', 'access-control-allow-headers': 'Content-Type, Content-Length, Authorization, X-Watson-Authorization-Token, X-WDC-PL-OPT-OUT, X-Watson-UserInfo, X-Watson-Learning-Opt-Out, X-Watson-Metadata', 'access-control-max-age': '3600', 'content-security-policy': 'default-src \\'none\\'', 'x-dns-prefetch-control': 'off', 'x-frame-options': 'SAMEORIGIN', 'strict-transport-security': 'max-age=31536000;', 'x-download-options': 'noopen', 'x-content-type-options': 'nosniff', 'x-xss-protection': '1; mode=block', 'x-global-transaction-id': '{x-global-transaction-id}', 'x-dp-watson-tran-id': '{x-dp-watson-tran-id}', 'x-dp-transit-id': '{x-dp-transit-id}', 'content-length': '41', 'x-edgeconnect-midmile-rtt': '124', 'x-edgeconnect-origin-mex-latency': '142', date: 'Wed, 19 Jun 2019 20:38:08 GMT', connection: 'close' } }

You have to use either the api key OR the username / password combination. The API docs for IBM Watson Assistant have code samples for Node.js :

const AssistantV2 = require('ibm-watson/assistant/v2');

const assistant = new AssistantV2({
  version: '{version}',
  iam_apikey: '{apikey}',
  url: '{url}'
});

Use this code as well. It's working on me. I added serviceUrl and headers. Make sure to add the correct service URL according to the assistant URL.

const assistant = new AssistantV2({
  version: "2019-02-28",
  authenticator: authenticator,
  url: process.env.WATSON_ASSISTANT_URL,
  serviceUrl: "https://api.us-south.assistant.watson.cloud.ibm.com",
  headers: {
    "X-Watson-Learning-Opt-Out": "true",
  },
});

Refer more - https://cloud.ibm.com/apidocs/assistant-v2?code=node#endpoint-cloud

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM