REST Table API: Using GET Method when sysparm_fields Makes the Request Exceed the Maximum Length of the URL/URI - HTTP-400 Response is Returned


Description

REST Table API: Using GET Method when sysparm_fields Makes the Request Exceed the Maximum Length of the URL/URI - HTTP-400 Response is Returned

This may happen when using sysparm_fields with a long list of columns. 

This is the definition of sysparm_fields when used with the REST API:

https://docs.servicenow.com/csh?topicname=c_RESTAPI.html&version=latest

"sysparm_fields -> Comma-separated list of fields to return in the response."

The maximum length of a URL/URI in a request is about 2048 characters.  If this is exceeded the instance will return a HTTP-400 response code with a most likely empty response body.

This article describes how to avoid exceeding the maximum URL/URI length when using a large number of columns in sysparm_fields.

Release or Environment

Applies to any release.

Resolution

To resolve this do not use sysparm_fields with the long list of columns, but instead create a database view:

https://docs.servicenow.com/csh?topicname=c_DatabaseViews.html&version=latest

And use this database view as the table name in the REST Table API URI and in the sysparm_view value.

In this example a database view is created for the incident table and it returns three fields: number, active, and sys_updated_on.

The database view:

 

 

The database view table:

This can be returned by specifying the name of the database view as the table name an in the value for sysparm_view as in this example:

 

 

This is the URI:

https://<instance>.service-now.com/api/now/table/int_fields/90685c33db1110108e7a198d13961940?sysparm_view=int_fields

Where /api/now/table/int_fields replaces /api/now/table/incident and sysparm_view=<database view name> replaces sysparm_fields=<long comma separated list of columns to return>.

This is what is returned - the three values defined in the int_fields database view are returned: number, active, sys_updated_on - note these are prefixed by the value of "Variable prefix" as defined in the View Table, in this case "intview_":

{
"result": {
"intview_sys_domain_path": "/",
"intview_sys_updated_on": "2020-06-16 03:51:50",
"intview_number": "INC0010280",
"intview_active": "true",
"intview_sys_domain": {
"link": "https://<instance>.service-now.com/api/now/table/sys_user_group/global",
"value": "global"
},
"intview_sys_id": "90685c33db1110108e7a198d13961940",
"intview_sys_class_name": "incident"
}
}