Why is the Service Catalog API returning less items than visible in the ui?

Joe Pruitt
Tera Contributor

Hello,

When I request service catalog items via GET /sn_sc/servicecatalog/items, I get only 10 items and they do not always seem consistent. I am not getting the same 10 items every time I make the request. This is much less than the number of items I am able to view through the ui for my instance when navigating to 'Service Catalog' in 'Self-Service.' 

I have already checked any issues with pagination and determined that this is not due oversight with the offset or page limit params. I am using the same credentials for the API request and for accessing the ui, so it is not a content access issue.

What could cause this discrepancy in the items returned by the API and the items I am seeing by accessing my instance through the ui?

1 ACCEPTED SOLUTION

Geoff_T
Mega Sage

Hi,

When I check the Service Catalog API on my instance (via System Web Services => Scripted Web Services => Scripted REST APIs) I see that the 'List of Catalog Items' (/api/sn_sc/v1/servicecatalog/items) API has sysparm_limit set to 10:

find_real_file.png

 

Can you check the same? You may need to update this.

Geoff

View solution in original post

4 REPLIES 4

Geoff_T
Mega Sage

Hi,

When I check the Service Catalog API on my instance (via System Web Services => Scripted Web Services => Scripted REST APIs) I see that the 'List of Catalog Items' (/api/sn_sc/v1/servicecatalog/items) API has sysparm_limit set to 10:

find_real_file.png

 

Can you check the same? You may need to update this.

Geoff

Thank you. When attempting to modify this field, it says "Security prevents writing to this field." How can this value be modified?

 

Hi,

Click on the sysparm_limit link on that row and you can edit the value on that form view. You'll also need to make sure you're in the Service Catalog REST API application (and not Global).

Geoff

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi Joe,

Even though this question has been resolved, a suggestion.

Increasing the number of records that can be fetched by a single GET call may affect performance of an instance. Instead of increasing the sysparm_limit, it is recommended to also use sysparm_offset to loop and page through the records.

sysparm_limit=50&sysparm_offset=0

Example: ServiceNow script 

var user = '<servicenow username>';
var password = '<password>';

var sysparmLimit = 50;  // number of records to fetch at once
var sysparmOffset = 0;
var instanceName = '<instance name>';
var status = 200;
var baseUrl = 'https://' + instanceName + '.service-now.com/api/sn_sc/servicecatalog/items?sysparm_limit=';

var resultArray = [];  // an array containing all records
while (status == 200) {
    var url = baseUrl + sysparmLimit + '&sysparm_offset=' + sysparmOffset;

    var request = new sn_ws.RESTMessageV2();
    request.setEndpoint(url);
	
    request.setHttpMethod('GET');
    request.setBasicAuth(user, password);
    request.setRequestHeader("Accept", "application/json");

    var response = request.execute();
    status = response.getStatusCode();
    if (status == 200) {
        var json = JSON.parse(response.getBody());
        var result = json.result;
		resultArray.push.apply(resultArray, result);
    }
    sysparmOffset += sysparmLimit;
}
gs.info('total:' + resultArray.length);
gs.info(JSON.stringify(resultArray));