watson-developer-cloud / java-sdk

:1st_place_medal: Java SDK to use the IBM Watson services.
http://watson-developer-cloud.github.io/java-sdk/
Apache License 2.0
593 stars 532 forks source link

[assistant] Endpoint is set to visual-recognition/api if not specified explicitely #1003

Closed l2fprod closed 6 years ago

l2fprod commented 6 years ago

Take this code:

import com.ibm.watson.developer_cloud.assistant.v2.Assistant;

Assistant service = new Assistant("2018-11-08");
service.setApiKey("an api key");
System.out.println("assistant endpoint: " + service.getEndPoint());

This output:

assistant endpoint: https://gateway-a.watsonplatform.net/visual-recognition/api

Yes visual-recognition!!!

This is using com.ibm.watson.developer_cloud:assistant:6.9.1 on Android

Looks like the issue comes from this code: https://github.com/watson-developer-cloud/java-sdk/blob/master/core/src/main/java/com/ibm/watson/developer_cloud/service/WatsonService.java#L342 and side effect of https://github.com/watson-developer-cloud/java-sdk/blob/master/core/src/main/java/com/ibm/watson/developer_cloud/service/WatsonService.java#L379

germanattanasio commented 6 years ago

If the user specifies the setApiKey() we update the URL to be

https://gateway-a.watsonplatform.net/visual-recognition/api

I think what you want to use is set the IAM apikey using setIamCredentials()

IamOptions options = new IamOptions.Builder()
  .apiKey("<iam_api_key>")
  .build();
service.setIamCredentials(options);

I'm going to close this since it's not an issue. Once all our VR users move to IAM we will deprecate/remove setApiKey()