From f464acdfc21731ccf1cddb5fdc217fd87758a605 Mon Sep 17 00:00:00 2001 From: brenduh Date: Thu, 9 Oct 2025 15:28:42 -0700 Subject: [PATCH 1/4] Create UPS.js --- Integration/RESTMessageV2/UPS Tracking/UPS.js | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Integration/RESTMessageV2/UPS Tracking/UPS.js diff --git a/Integration/RESTMessageV2/UPS Tracking/UPS.js b/Integration/RESTMessageV2/UPS Tracking/UPS.js new file mode 100644 index 0000000000..d6128c1590 --- /dev/null +++ b/Integration/RESTMessageV2/UPS Tracking/UPS.js @@ -0,0 +1,43 @@ +(function executeUPSLookup() { + try { + var trackingNumber = '1Z12345E1512345676'; // replace or pass as a variable + + // Step 1: Get OAuth token from UPS + var tokenRequest = new sn_ws.RESTMessageV2(); + tokenRequest.setEndpoint('https://wwwcie.ups.com/security/v1/oauth/token'); + tokenRequest.setHttpMethod('POST'); + tokenRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); + tokenRequest.setBasicAuth('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET'); + tokenRequest.setRequestBody('grant_type=client_credentials'); + + var tokenResponse = tokenRequest.execute(); + var tokenBody = tokenResponse.getBody(); + var tokenObj = JSON.parse(tokenBody); + var accessToken = tokenObj.access_token; + + gs.info('UPS OAuth token retrieved successfully.'); + + // Step 2: Use token to request tracking info + var trackingRequest = new sn_ws.RESTMessageV2(); + trackingRequest.setEndpoint('https://wwwcie.ups.com/api/track/v1/details/' + trackingNumber); + trackingRequest.setHttpMethod('GET'); + trackingRequest.setRequestHeader('Authorization', 'Bearer ' + accessToken); + trackingRequest.setRequestHeader('transId', gs.generateGUID()); + trackingRequest.setRequestHeader('transactionSrc', 'ServiceNow'); + + var trackingResponse = trackingRequest.execute(); + var trackingBody = trackingResponse.getBody(); + var trackingObj = JSON.parse(trackingBody); + + gs.info('UPS Tracking Info: ' + JSON.stringify(trackingObj, null, 2)); + + // Example: log current status + if (trackingObj.trackResponse && trackingObj.trackResponse.shipment) { + var shipment = trackingObj.trackResponse.shipment[0]; + var status = shipment.package[0].activity[0].status.description; + gs.info('Current Status: ' + status); + } + } catch (ex) { + gs.error('Error pulling UPS tracking info: ' + ex.message); + } +})(); From 10fb379dd5bf58d6cae59130f47da72cbd3a67e6 Mon Sep 17 00:00:00 2001 From: brenduh Date: Thu, 9 Oct 2025 15:29:19 -0700 Subject: [PATCH 2/4] Rename UPS.js to trackUPS.js --- Integration/RESTMessageV2/UPS Tracking/{UPS.js => trackUPS.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Integration/RESTMessageV2/UPS Tracking/{UPS.js => trackUPS.js} (100%) diff --git a/Integration/RESTMessageV2/UPS Tracking/UPS.js b/Integration/RESTMessageV2/UPS Tracking/trackUPS.js similarity index 100% rename from Integration/RESTMessageV2/UPS Tracking/UPS.js rename to Integration/RESTMessageV2/UPS Tracking/trackUPS.js From 62c7b0971e4358520f51dbca98be47cd94543ba7 Mon Sep 17 00:00:00 2001 From: brenduh Date: Thu, 9 Oct 2025 15:32:04 -0700 Subject: [PATCH 3/4] Create README.md --- Integration/RESTMessageV2/UPS Tracking/README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Integration/RESTMessageV2/UPS Tracking/README.md diff --git a/Integration/RESTMessageV2/UPS Tracking/README.md b/Integration/RESTMessageV2/UPS Tracking/README.md new file mode 100644 index 0000000000..207678b90e --- /dev/null +++ b/Integration/RESTMessageV2/UPS Tracking/README.md @@ -0,0 +1,13 @@ +This script calls the UPS tracking API. + +UPS Developer Account: +Sign up at https://developer.ups.com +Create an App to get credentials +1. Client ID +2. Client Secret + +How to use: +Replace YOUR_CLIENT_ID and YOUR_CLIENT_SECRET with your UPS credentials. +Use the sandbox URL (wwwcie.ups.com) for testing and production URL (onlinetools.ups.com) for live data. +You can move this logic into a Script Include and call it from a Flow, Business Rule, or Catalog Client Script. +For security, store credentials in a Connection & Credential Alias and reference them in the script instead of hardcoding. From c32904d4c8d8b962c5ece3d1e37db1a17def79a3 Mon Sep 17 00:00:00 2001 From: brenduh Date: Thu, 9 Oct 2025 15:32:34 -0700 Subject: [PATCH 4/4] Update README.md --- Integration/RESTMessageV2/UPS Tracking/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Integration/RESTMessageV2/UPS Tracking/README.md b/Integration/RESTMessageV2/UPS Tracking/README.md index 207678b90e..371bff9c86 100644 --- a/Integration/RESTMessageV2/UPS Tracking/README.md +++ b/Integration/RESTMessageV2/UPS Tracking/README.md @@ -7,7 +7,7 @@ Create an App to get credentials 2. Client Secret How to use: -Replace YOUR_CLIENT_ID and YOUR_CLIENT_SECRET with your UPS credentials. -Use the sandbox URL (wwwcie.ups.com) for testing and production URL (onlinetools.ups.com) for live data. -You can move this logic into a Script Include and call it from a Flow, Business Rule, or Catalog Client Script. -For security, store credentials in a Connection & Credential Alias and reference them in the script instead of hardcoding. +1. Replace YOUR_CLIENT_ID and YOUR_CLIENT_SECRET with your UPS credentials. +2. Use the sandbox URL (wwwcie.ups.com) for testing and production URL (onlinetools.ups.com) for live data. +3. You can move this logic into a Script Include and call it from a Flow, Business Rule, or Catalog Client Script. +4. For security, store credentials in a Connection & Credential Alias and reference them in the script instead of hardcoding.