VMware Cloud Community
daphnissov
Immortal
Immortal
Jump to solution

executeWithCredentials method for RESTHost failing with "This operation is not supported for NONE"

/cc iiliev

I'm sort of at an impasse here and learning as I go about the REST plug-in within vRO (with which I have no prior experience). We have here some basic code very kindly provided by a colleague which creates a transient REST session and performs auth via username and password. It fails with "This operation is not supported for NONE".

var restBaseUrl = "https://server.domain.com";

var requestUrlString = "/api/v1/XXX/YYY/" ;

var authUsername = "service-account-name";

var authPassword = "service-account-password";

var returnArray;

var restHost = RESTHostManager.createHost("MyRequest");

var transientHost = RESTHostManager.createTransientHostFrom(restHost);

transientHost.url = restBaseUrl;

var request = transientHost.createRequest("GET", requestUrlString, "");

request.setHeader("Accept", "application/json");

var response;

response = request.executeWithCredentials(authUsername, authPassword);

var statusCode = response.statusCode;

Everything before line 12 runs just fine, however after enabling debugging in vRO I can see the trace where it fails calling the executeWithCredentials method and I'm just not sure why. I've run some tests and have written out the attributes of the RESTRequest to ensure it's properly formatted, and it is. I'm not sure how I can continue troubleshooting this, however. Is it possible that executeWithCredentials only works for secure string type as input parameters? Any pointers would be appreciated.

vRO 7.3

HTTP-REST plug-in 2.2.2

Reply
0 Kudos
1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

This error message is shown when the request cannot determine the supported authentication type.

To fix it, insert the following lines between lines 6 and 7 of the provided code (this tells the request to use Basic Authentication)

var authParams = ['Shared Session', authUsername, authPassword];

var authObject = RESTAuthenticationManager.createAuthentication('Basic', authParams);

restHost.authentication = authObject;

View solution in original post

Reply
0 Kudos
9 Replies
bluefirestorm
Champion
Champion
Jump to solution

Don't know anything about VRO and REST programming so this is a shot in the dark

Is this line incorrect and thus causing executeWithCredentials to fail?

var request = transientHost.createRequest("GET", requestUrlString, ""); 

and as the requestUrlString value does not seem to contain a full URL going by the redacted values

  1. var restBaseUrl = "https://server.domain.com"; 
  2. var requestUrlString = "/api/v1/XXX/YYY/" ; 

Maybe the intent was

var request = transientHost.createRequest("GET", restBaseURL + requestUrlString, ""); 

Since the executeWithCredentials failed, it would have returned "NONE" and non does not have the statusCode attribute so it gives the error "This operation is not supported for NONE"

Reply
0 Kudos
daphnissov
Immortal
Immortal
Jump to solution

No, that information is correct because the URL attribute is being set earlier.

Reply
0 Kudos
bluefirestorm
Champion
Champion
Jump to solution

But if the GET HTTP request expects a full URL, it won't be able successfully process

it as the parameter variable would have contained only "/api/v1/XXX/YYY/"

instead of full URL such as "https://server.domain.com/api/v1/XXX/YYY"

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

This error message is shown when the request cannot determine the supported authentication type.

To fix it, insert the following lines between lines 6 and 7 of the provided code (this tells the request to use Basic Authentication)

var authParams = ['Shared Session', authUsername, authPassword];

var authObject = RESTAuthenticationManager.createAuthentication('Basic', authParams);

restHost.authentication = authObject;

Reply
0 Kudos
daphnissov
Immortal
Immortal
Jump to solution

Thank you, Ilian. Because I'm still learning this, how do you know to do this? I saw nothing in the API Explorer that mentioned creating an auth session was required for a transient REST host. Wanting to use this as a learning opportunity later and so any education is most helpful.

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

Well, I checked the source code of the REST plug-in to see where this error is thrown, and it was at a piece of code that checks whether host authentication type is set to 'Basic'.

'for NONE' at the end of the error message meant that the host authentication type is not configured, so it looked likely that the fix could be as simple as configuring Basic Authentication for the host, for which I had a code snippet from another workflow.

Reply
0 Kudos
daphnissov
Immortal
Immortal
Jump to solution

Thanks for that. But I'm just wondering if I missed something in the API Explorer documentation that told me this was required. As I can see now, there's nothing in the definition for that method (executeWithCredentials) that said this object was a requirement, so I'm asking myself how I could have fixed this myself had I not been able to see the raw Java of the plug-in.

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

Agreed, plug-in documentation leaves a lot to be desired. The error message could have also been clearer; there is enough of context available at the point where it is thrown.

Reply
0 Kudos
daphnissov
Immortal
Immortal
Jump to solution

Thank you very much, iiliev​ for your help here and support of this community. You're a great resource to have!

Reply
0 Kudos