- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2019 10:12 PM
I am trying to integrate our Incident Management system with another application used by a vendor. My task is to pull service-tickets created in vendor's application, based on date-time range (start, end); and create corresponding records in our Incident table. For this I have created a scheduled Job that runs periodically. The scheduled job uses REST 'GET' request.
My code is as follows -
//Initiate new web-service GET request
var request = new sn_ws.RESTMessageV2();
request.setEndpoint('https://something.com/rest/Ticket');
request.setHttpMethod('GET');
//Set authentication user/password
var user = 'xyz';
var password = 'abcd';
request.setBasicAuth(user,password);
//Set request Headers
request.setRequestHeader('Content-Type','application/json');
request.setRequestHeader("Accept","application/json");
request.setRequestHeader('Cache-Control','no-cache');
//Set request Parameters
request.includeTicketsWithoutDevices = true;
request.lastModifiedOnRange("(start, 2019-12-16T00:00:00Z)(end, 2019-12-16T23:59:59Z)");
//Execute the request
var response = request.execute();
//
NOTE: 'includeTicketsWithoutDevices' and 'lastModifiedOnRange' are valid properties in the vendor's application API.
When the scheduled job runs, it returns response with 'httpStatus=200' and returns 2 records in JSON format, as shown below -
//Response Body
{
"items" : [ {
"id" : "SOC9229",
"customerName" : "ACME CORP",
"partnerId" : "PID704571",
"partnerName" : "EMCA Outsourcing",
"lastModifiedOn" : "2019-11-23T05:50:13.000Z",
"issueDescription" : "TEST Issue Description",
"priority" : "LOW",
"ticketStatus" : "Assigned",
},
{
"id" : "SOC8982",
"customerName" : "ACME CORP",
"partnerId" : "PID704571",
"partnerName" : "EMCA Outsourcing",
"lastModifiedOn" : "2019-12-03T02:20:55.000Z",
"issueDescription" : "TEST Issue Description",
"priority" : "LOW",
"ticketStatus" : "Assigned",
} ],
"start" : 0,
"limit" : 100,
"totalCount" : 2
The problem is, no matter what date-time range I specify, it always pulls the same two records. In those records, too, you may notice that 'lastModifiedOn' values does not correspond to request.lastModifiedOnRange("(start, 2019-12-16T00:00:00Z)(end, 2019-12-16T23:59:59Z)");
However, the same GET request works fine in POSTMAN, where I specify 'lastModifiedOnRange' under Parameters. (see the screen shot in attachments). It fetches the correct set of records that belong to the date-time range I provide.
Is there something wrong with my statement -
request.lastModifiedOnRange("(start, 2019-12-16T00:00:00Z)(end, 2019-12-16T23:59:59Z)"); ?
Is there another way of specifying the date-time range in 'GET' request?
Please help.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2019 11:39 PM
Hi,
I think you will have to include those in query parameters
can you try this as below and check once
request.setQueryParameter("includeTicketsWithoutDevices", "true");
request.setQueryParameter("lastModifiedOnRange", "(start, 2019-12-16T00:00:00Z)(end, 2019-12-16T23:59:59Z)");
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2019 10:27 PM
Hi,
Did you check with 3rd party how they are expecting the values for the date range?
Any sample request and response should help you
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2019 08:11 AM
I have checked with the 3rd party vendor and the documentation for their application's API. It recommends using date-time range in the format -
request.lastModifiedOnRange("(start, yyyy-mm-ddThh:mm:ssZ)(end, yyyy-mm-ddThh:mm:ssZ)");
This format works with no issues, when I test it in POSTMAN tool. In POSTMAN it correctly pulls those records that fit within the date-time range (start, ...)(end, ...).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2019 08:21 AM
//Try single quotes around
request.lastModifiedOnRange("(start, '2019-12-16T00:00:00Z')(end, '2019-12-16T23:59:59Z')");
or
request.setStringParameter("lastModifiedOnRange","(start, 2019-12-16T00:00:00Z)(end, 2019-12-16T23:59:59Z)");
Vinod Kumar Kachineni
Community Rising Star 2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2019 09:19 PM
Thanks vkachineni. I tried your suggestions, but with no success.
1) includeTicketsWithoutDevices = true ;
2) lastModifiedOnRange("(start, 2019-12-18T00:00:00Z)(end, 2019-12-18T23:59:59Z)") ;
The above two properties are sent as parameters in POSTMAN. (See the screen-shot.)
In POSTMAN it fetches 1, records which is correct.
Response:
{
"items" : [ {
"id" : "SOC9238",
"customerName" : "ACME CORP",
"partnerId" : "PID704571",
"partnerName" : "EMCA Outsourcing",
"lastModifiedOn" : "2019-12-18T05:50:13.000Z",
"issueDescription" : "TEST Issue Description",
"priority" : "LOW",
"ticketStatus" : "Assigned"
}]