Hi everyone;
forgive my ignorance but I am new to the vRO World and a bit lost at the moment. I want to make some restful requests using username and password instead of tokens! Iat the moment the code i have is using a configuration element named authorization which stores the token. my Question is, what should I change to achieve my quest.. thanks very much in advance!
System.log("****STARTING WORKFLOW****");
//Getting the header parameters for Authentication
headerParam_0 = HomeAutomationAttributes.getAttributeWithKey("Authorization").name;
headerParam_1 = HomeAutomationAttributes.getAttributeWithKey("Authorization").value;
//The parameters of the action to be executed (e.g.: the entity_id of the light/switch you want to turn off/on).
var request = restOperation.createRequest(null,content);
//Set the headers based on the attributes in the vRO configuration element
request.setHeader(headerParam_0,headerParam_1);
//set the request content type to application/json (set as attribute in Workflow)
if (System.getModule("com.vmware.library.http-rest.configuration").hasHttpMethodHasBodyPayload(request.getMethod())) {
System.log("Setting defaut content type to: " + defaultContentType );
request.contentType = defaultContentType;
}
//Log the Request Details
System.log("Request: " + request);
System.log("Request URL: " + request.fullUrl);
//Execute the request
var response = request.execute();
//Log the response, useful for troubleshooting
System.log("Response: " + response);
statusCode = response.statusCode;
statusCodeAttribute = statusCode;
System.log("Status code: " + statusCode);
contentLength = response.contentLength;
headers = response.getAllHeaders();
contentAsString = response.contentAsString;
System.log("Content as string: " + contentAsString);
System.log("****COMPLETED****");
Hi,
This code executes the request by calling request.execute() method. You can replace it with another method call - request.executeWithCredentials(username, password)
However, replacing the execution call may not be enough. There are some other things to check:
So, in general, changing the scripting code alone might, or might not work, depending on the REST endpoint specifics.
Hi,
This code executes the request by calling request.execute() method. You can replace it with another method call - request.executeWithCredentials(username, password)
However, replacing the execution call may not be enough. There are some other things to check:
So, in general, changing the scripting code alone might, or might not work, depending on the REST endpoint specifics.
Thanks very very much! It works like a charm