Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Get device42 customers for Orchestrator action
// Requires the following variables set as input on the action.
// - dev_user [string]
// - dev_pass [SecureString]
// - dev_server [string]
var baseUrl = "https://" + dev42_server + "/api/1.0/customers/"
var queryString = ""
var httpMethod = "GET"
var content = ""
var contentType = ""
var restHost = RESTHostManager.createHost("DynamicRequest");
var transientHost = RESTHostManager.createTransientHostFrom(restHost);
transientHost.url = baseUrl;
if (dev42_user != null && dev42_user != "") {
var authParams = ["Per User Session", dev42_user, dev42_pass];
var authenticationObject = RESTAuthenticationManager.createAuthentication("Basic", authParams);
transientHost.authentication = authenticationObject;
}
var requestUrl = baseUrl + queryString;
System.log("Request full URL: " + requestUrl);
var request = transientHost.createRequest(httpMethod, queryString, content);
//request.contentType = contentType;
var response;
if (dev42_user != null && dev42_user != "") {
System.log("Executing REST request with dynamic credentials: " + dev42_user);
System.log("Query string: " + request.url);
System.log("Base URL: " + request.host.url);
response = request.executeWithCredentials(dev42_user, dev42_pass);
} else {
response = request.execute();
}
System.log("Content as string: " + response.contentAsString);
var cust_names = new Array();
var o_cust = JSON.parse(response.contentAsString);
for ( i in o_cust.Customers) {
var cust = o_cust.Customers[i];
System.log(cust.id);
cust_names.push(cust.name);
}
System.log(cust_names);
return cust_names;
@mccbryan3

This comment has been minimized.

Copy link
Owner Author

@mccbryan3 mccbryan3 commented Oct 23, 2019

Create getDev42Customers vRo Action using script with the required inputs

image

image

Configure the input form with External value and the getDev42Customers with its input

image

The action setup will result in the list array being populated by the Customer Names

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment