Rest API limiting to 500 records
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2023 02:30 PM
Prefacing with
Someone else wrote this, I am new to Rest APIs
We have a scheduled script that connects to Airwatch to get information on Apple and Android devices.
For whatever reason when this runs it is only bringing in 500 records to the import set. I have tried increasing the Page < number and increasing the devices.length but it's not changing anything - still only returns 500 records (there are about 8000 in airwatch)
Can anyone point me in the right direction of what i need to do to get all the 8000 records in to the import set from this script (i tried creating a second script and then got 1000 records.. but created a 3rd and it still stayed at 1000)
var pageNumber = 0;
airWatchDevice(pageNumber);
function airWatchDevice(pageNumber) {
try {
var r = new sn_ws.RESTMessageV2('Airwatch PROD', 'Device Information');
r.setStringParameter('pageNumber', pageNumber);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
if (httpStatus == 200) {
var assetArray = JSON.parse(responseBody);
var devices = assetArray.Devices;
var restGR = new GlideRecord('u_airwatch_integration_import');
//Query extended import set rows table
//Loop through the json chucks until 0 remain creating import set rows to be transformed
for (var i = 0; i < devices.length; i++) {
restGR.initialize();
restGR.u_serial_number = devices[i].SerialNumber;
restGR.u_mac_address = devices[i].MacAddress;
//restGR.u_username = devices[i].UserName;
// Getting and referencing username
var user_id = devices[i].UserName;
var user = new GlideRecord('sys_user');
user.addQuery('user_name', user_id);
user.query();
if (user.next())
restGR.u_username = user.sys_id;
// Getting the location info
var location_id = devices[i].LocationGroupId.Id.Value;
//gs.info(location_id + ' airwatch location id');
var location = new GlideRecord('cmn_location');
location.addQuery('u_location_group_id', location_id);
location.query();
if (location.next())
restGR.u_location = location.sys_id;
// Getting os version;model description; name; lastseen
restGR.u_os_version = devices[i].OperatingSystem;
restGR.u_name = devices[i].DeviceFriendlyName;
restGR.u_lastseen = devices[i].LastSeen;
restGR.u_model = devices[i].Model;
// Getting and transforming Operating system
var platform = devices[i].Platform;
if (platform == 'Android')
restGR.u_operating_system = 'Android';
if (platform == 'Apple')
restGR.u_operating_system = 'ios';
if (platform == 'AppleOsX')
restGR.u_operating_system = 'Mac OS/X';
if (platform == 'Apple iOS')
restGR.u_operating_system = 'ios';
if (platform == 'Apple macOS')
restGR.u_operating_system = 'Mac OS/X';
restGR.insert();
}
if (devices.length >= 1000 && pageNumber < 6) {
pageNumber++;
airWatchDevice(pageNumber);
}
} else
gs.info('airwatch error :::>>> ' + responseBody);
} catch (ex) {
var message = ex.message;
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2023 07:24 PM - edited 03-08-2023 07:25 PM
Hi,
My apologies if none of my replies are Helpful, but I feel that may have been and we've gotten more information from you each time you've replied based on my questions 🙂
In the end, it sounds like a limit imposed by the endpoint and not a ServiceNow issue, perhaps. You may be able to find out more from your Apple integration team members to see if there's specifics to the limit, such as what is documented as an example here: https://developer.apple.com/documentation/appstoreconnectapi/identifying_rate_limits
It could be something with the API key being used in your rest message and how often all of this is happening.
Anyways, there isn't much else we can do as it doesn't seem to be an actual ServiceNow issue at this point.
If any reply of mine was Helpful, please take a moment and mark it as Helpful.
If my reply helped guide you towards a solution, please mark it as "Accept Solution".
Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!