watson-developer-cloud / node-red-node-watson

A collection of nodes for the IBM Watson services
Apache License 2.0
82 stars 86 forks source link

Visual Recognition API Key changed? #409

Closed emmajdaws closed 6 years ago

emmajdaws commented 6 years ago

Using the node-red-labs basic flow, an old Visual Recognition service works fine.

If you create a new instance of Visual Recognition and try the flow, you get the error: "Unauthorized: Access is denied due to invalid credentials."

Problem reported via slack, and I have been able to replicate the error. Suspect the API has changed.

chughts commented 6 years ago

This is because you are only allowed one Visual Recognition key. If you try to create a second it will be invalid.

The only way to create a new key is to revoke an existing Visual Recognition service. Wait. Create a new Visual Recognition service. Wait. The waits are important.

mashiah commented 6 years ago

i dont understand. i have the same issue. existing visual recognition apis work. new one (with new service instance) doesnt work.

it seems like the endpoint has changed as well as the credentials json. anyone knows how to make it work?

unfortunately revoking old instances and waiting has nothing to do with it and it does not solve the problem. i also noticed that now visual recognition service are opened under "service" section in the bluemix dashboard and not under "cloud foundry service" like all other services. something has changed and it either a bug or an undocumented major change

mashiah commented 6 years ago

also please look at the image. the new instances dont even have to option to "launch service". any ideas?

screen shot 2018-05-24 at 0 47 52
chughts commented 6 years ago

That endpoint is not the default - gateway-a.watsonplatform.net

The Visual Recognition Node only uses the default. It looks as though the node needs to be updated to allow the endpoint to be overridden. I will see if I can do something this evening.

mashiah commented 6 years ago

i think its a bit deeper than the endpoint.

the service was moved out from cloud foundry and now its impossible to create-service with automatic process. you can only create with the gui. more over, the authentication process has changed and now u need to use this:

https://console.bluemix.net/docs/services/visual-recognition/release-notes.html#release-notes

this is really unclear. i was not able to call the service successfully so far. not even 1 example exists.

chughts commented 6 years ago

The versioning API is not that much different from other services, so not too great an issue.

chughts commented 6 years ago

The node is currently using

version_date: '2018-03-19',

chughts commented 6 years ago

Oh - just read the New API authentication process: section. Looks like a whole load of re-engineering required, but the underlying SDK needs updating also.

seanmtracey commented 6 years ago

Would it be possible to lock off the node to use the older version of the API until such time that the node can be updated?

Do the new Visual Recognition instances still respect a version ID?

chughts commented 6 years ago

The SDK has been updated to expect a token. Reading through the SDK, class BaseService has a initCredentials that generates a token if a username and password are provided, but not if its a key.

The node is currently using the older version of the API, which works if the instance was created before the 22 May.

I will take a look tonight, to see if I can add a generate token etc. code if the url provided / detected is the new one.

chughts commented 6 years ago

This has been fixed. I have a pull request, and I believe that @seanmtracey also has a fix. We will compare the two and go with the most elegant.

In my fix, I detect the endpoint, and if its a new style then the key being passed in is passed in as

    // VR instances created post 22 May 2018, are expecting an iam API Key
    if (iamAPIKey) {
      serviceSettings.iam_apikey = node.apikey;
    } else {
      serviceSettings.api_key = node.apikey;
    }

This with the endpoint url being passed in

    if (endpoint) {
      serviceSettings.url = endpoint;
    }

is enough for both versions of the VR instance to be usable.

chughts commented 6 years ago

Fixed in 0.6.14