REST Integration with Dell Tech Direct
I wanted to put together a brief article around integrating ServiceNow with Dell's TechDirect warranty API to collect an asset's Warranty Expiration date. In this article, I will detail the Outbound REST message setup, scripting the business rules and UI action I used. This will be some basic REST work, but I thought I would share. Please feel free to comment if you see errors or improvements I can make.
Obtain your Dell API key from Dell TechDirect. Once you are approved for a key, Dell will provide the key along with some code samples (see the attached PDF). Currently I have a key only for their Warranty API.
Setting up the Outbound REST message and GET method:
- Create a new Outbound REST message with endpoint https://sandbox.api.dell.com/support/assetinfo/v4 (Dell will initially setup you up within their sandbox environment and then migrate your work to their prod endpoint)
- Add HTTP headers for Accept and Content-Type, both with a value of application/json
- Save the new record, which will create your default GET method.
- Obtaining the warranty end date requires endpoint: https://sandbox.api.dell.com/support/assetinfo/v4/getassetwarranty/{id}?apikey={apikey}
- Setup your GET method for some test runs with the following attributes:
- * Endpoint: https://sandbox.api.dell.com/support/assetinfo/v4/geassetwarranty/${id}
- HTTP headers for Accept and Content-Type, both with a value of application/json
- HTTP Query Parameter for apikey where the value is your key (We'll remove this parameter later and store the key as a property).
- Variable substitutions for id with a value of a valid service tag
- HTTP headers for Accept and Content-Type, both with a value of application/json
You want to grab the EndDate value from AssetEntitlementData[0] array.
Setting up a Business Rule to update Warranty Expiration
I decided to setup an On Before Insert and Update business rule to run when the Warranty Expiration field is empty and the Serial Number is not empty and the workstation is not a Mac.
(function executeRule(current, previous /*null when async*/) {
var st = current.serial_number;
try {
var r = new sn_ws.RESTMessageV2('DellTechDirect', 'GET');
r.setStringParameterNoEscape('id', st);
r.setQueryParameter('apikey', gs.getProperty('DellTechDirectKey'));
r.setHttpTimeout(10000);
r.setEccParameter('skip_sensor', true);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.info("Status = " + httpStatus);
gs.info("Response Body = " + responseBody);
if (httpStatus == '200'){
var responseObj = JSON.parse(responseBody);
var edate = responseObj.AssetWarrantyResponse[0].AssetEntitlementData[0].EndDate.substring(0, 10);
current.warranty_expiration = edate;
}else{
gs.addErrorMessage('Looks like we ran into a problem. HTTP status: ' + httpStatus);
}
}
catch(ex) {
var message = ex.getMessage();
}
})(current, previous);
Setting up the UI Action to check warranty expiration:
I setup a Form Button UI action to only display if the Serial Number is not empty and the workstation is not a Mac. This gives our Service Desk a method to validate the Warranty Expiration.
var st = current.serial_number;
var curdate = current.warranty_expiration;
try {
var r = new sn_ws.RESTMessageV2('DellTechDirect', 'GET');
r.setStringParameterNoEscape('service_tag', st);
//r.setQueryParameter(gs.getProperty('DellTechDirectKey'));
r.setQueryParameter('apikey', gs.getProperty('DellTechDirectKey'));
r.setHttpTimeout(10000);
r.setEccParameter('skip_sensor', true);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.info("Status = " + httpStatus);
gs.info("Response Body = " + responseBody);
if(httpStatus == '200'){
var responseObj = JSON.parse(responseBody);
var edate = responseObj.AssetWarrantyResponse[0].AssetEntitlementData[0].EndDate.substring(0, 10);
if(curdate == edate){
gs.addInfoMessage('The Warranty Expiration date is correct');
action.setRedirectURL(current);
current.update();
}
if(curdate != edate){
gs.addInfoMessage('The Warranty Expiration date changed from ' + curdate + ' to ' + edate);
current.warranty_expiration = edate;
action.setRedirectURL(current);
current.update();
}
}
else{
gs.addErrorMessage('Could not retrieve Warranty Expiration information: ' + httpStatus);
action.setRedirectURL(current);
current.update();
}
}
catch(ex) {
var message = ex.getMessage();
}
I hope this is helpful and please let me know if you have any feedback.
https://www.servicenow.com/community/developer-articles/rest-integration-with-dell-tech-direct/ta-p/2312098