---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# GlideHTTPRequest - Global

# GlideHTTPRequest - Global {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 5 minutes to read

The GlideHTTPRequest API provides utility methods to perform common
functions with Glide HTTP requests.

You can use this API in global server-side scripts. To use this class, instantiate a
GlideHTTPRequest object using the constructor. The constructor requires an endpoint URL as an
input parameter.

## GlideHTTPRequest - addHeader(String name, String value) {#ariaid-title2}

Adds a header to your HTTP request.
{#GlideHTTPRequest-addHeader__table_ib1_31z_cfb__entry__3}

| Name | Type | Description |
|-|-|-|
| name | String | Header name, such as `Accept` or `Content-Type`. |
| value | String | Header value, such as `application/json`. |
[Table 1. Parameters]

{#GlideHTTPRequest-addHeader__table_ib1_31z_cfb} {#GlideHTTPRequest-addHeader__table_jb1_31z_cfb__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 2. Returns]

{#GlideHTTPRequest-addHeader__table_jb1_31z_cfb}  
This example adds the request header "Accept" and returns the number of the incidents from
a ServiceNow Instance, parsing the JSON or XML responses.

    var instance = 'dev12345';
    var username = 'admin';
    var password = 'yourpassword';

    // Instantiate request with ServiceNow API incidents table endpoint
    var request = new GlideHTTPRequest('https://'+instance+'.service-now.com/api/now/table/incident');

    // Add authentication data
    request.setBasicAuth(username, password);

    // Add the Accept header to get JSON response
    request.addHeader('Accept', 'application/json');

    // Execute the GET request
    var response = request.get();

    // Print the results: status code and number of records returned
    gs.print(response.getStatusCode());
    gs.print('(JSON) Incidents returned: ' + JSON.parse(response.getBody()).result.length);

    // Replace the Accept header to get XML response
    request.addHeader('Accept', 'application/xml');

    // Execute the GET request
    var response = request.get();

    // Print the results: status code and number of records returned
    gs.print(response.getStatusCode());
    gs.print('(XML) Incidents returned: ' + gs.xmlToJSON(response.getBody()).response.result.length);

Output

    200
    (JSON) Incidents returned: 66
    200
    (XML) Incidents returned: 66

## GlideHTTPRequest - addParameter(String name, String value) {#ariaid-title3}

Adds a parameter to your HTTP request.
{#GlideHTTPRequest-addParameter__table_zk5_4dz_cfb__entry__3}

| Name | Type | Description |
|-|-|-|
| name | String | Parameter to add, such as sysparm_limit. |
| value | String | Value for the parameter. |
[Table 3. Parameters]

{#GlideHTTPRequest-addParameter__table_zk5_4dz_cfb} {#GlideHTTPRequest-addParameter__entry__11}

| Type | Description |
|-|-|
| void |   |
[Table 4. Returns]

This example shows how to add the sysparm_limit parameter to the REST
endpoint call to limit the number of returned responses.

    var instance = 'dev12345';
    var username = 'admin';
    var password = 'yourpassword';

    // Instantiate request with ServiceNow API incidents table endpoint
    var request = new GlideHTTPRequest('https://'+instance+'.service-now.com/api/now/table/incident');

    // Add authentication data
    request.setBasicAuth(username, password);

    // Add the 'sysparm_limit' parameter to limit the number of records returned
    request.addParameter('sysparm_limit', 1);

    // Execute the GET request
    var response = request.get();

    // Print the results: status code and number of records returned
    gs.print(response.getStatusCode());
    gs.print('Incidents returned: ' + JSON.parse(response.getBody()).result.length);

Output:

    200
    Incidents returned: 1

## GlideHTTPRequest - setBasicAuth(String userName, String password) {#ariaid-title4}

Sets a user name and password for basic authentication.
{#GlideHTTPRequest-setBasicAuth__table_xtx_5qy_cfb__entry__3}

| Name | Type | Description |
|-|-|-|
| userName | String | User name to use for authentication. |
| password | String | User's password to use for authentication. |
[Table 5. Parameters]

{#GlideHTTPRequest-setBasicAuth__table_xtx_5qy_cfb} {#GlideHTTPRequest-setBasicAuth__table_ytx_5qy_cfb__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 6. Returns]

{#GlideHTTPRequest-setBasicAuth__table_ytx_5qy_cfb}  
This example shows how to use the setBasicAuth() method to set the user
name and password for the associated REST endpoint call.

    var instance = 'dev12345';
    var username = 'admin';
    var password = 'yourpassword';

    // Instantiate request with ServiceNow API incidents table endpoint
    var request = new GlideHTTPRequest('https://'+instance+'.service-now.com/api/now/table/incident');

    // Add authentication data
    request.setBasicAuth(username, password);

    // Add the Accept header to get JSON response
    request.addHeader('Accept', 'application/json');

    // Execute the GET request
    var response = request.get();

    // Print the results: status code and number of records returned
    gs.print(response.getStatusCode());
    gs.print('(JSON) Incidents returned: ' + JSON.parse(response.getBody()).result.length);

    // Replace the Accept header to get XML response
    request.addHeader('Accept', 'application/xml');

    // Execute the GET request
    var response = request.get();

    // Print the results: status code and number of records returned
    gs.print(response.getStatusCode());
    gs.print('(XML) Incidents returned: ' + gs.xmlToJSON(response.getBody()).response.result.length);

Output

    200
    (JSON) Incidents returned: 66
    200
    (XML) Incidents returned: 66

## GlideHTTPRequest - setContentType(String type) {#ariaid-title5}

Sets the Content-Type header for your HTTP request to the specified value.
{#GlideHTTPRequest-setContentType__table_lhw_vdz_cfb__entry__3}

| Name | Type | Description |
|-|-|-|
| type | String | Content type to set, such as `application/json` or `multipart/form-data`. For additional information on Content-Type, see <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type>. |
[Table 7. Parameters]

{#GlideHTTPRequest-setContentType__table_lhw_vdz_cfb} {#GlideHTTPRequest-setContentType__table_mhw_vdz_cfb__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 8. Returns]

{#GlideHTTPRequest-setContentType__table_mhw_vdz_cfb}  
This example shows how to set the `Content-Type` request header for a REST
endpoint call using the setContentType() method.

    var instance = 'dev12345';
    var username = 'admin';
    var password = 'yourpassword';

    // Instantiate request with ServiceNow API incidents table endpoint
    var request = new GlideHTTPRequest('https://'+instance+'.service-now.com/api/now/table/incident');

    // Add authentication data
    request.setBasicAuth(username, password);

    // Set up incident record to post

    // Set the Content-Type of the POST
    request.setContentType('application/json');

    // Execute the POST request
    var response = request.post();

    // Print the results: status code and number of records returned
    gs.print(response.getStatusCode());

Output

    200

## GlideHTTPRequest - setFollowRedirect(boolean followRedirect) {#ariaid-title6}

Enables or disables the follow redirect option for a REST endpoint call.
For additional information on HTTP redirects, see <https://developer.mozilla.org/en-US/docs/Web/HTTP/Redirections>.
{#GlideHTTPRequest-setFollowRedirect__table_kzt_pwy_cfb__entry__3}

| Name | Type | Description |
|-|-|-|
| followRedirect | Boolean | Flag that indicates whether the endpoint should follow any URL redirect returned by the endpoint. Valid values: * true: Following any returned redirect. * false: Ignore any returned redirect. Default: true |
[Table 9. Parameters]

{#GlideHTTPRequest-setFollowRedirect__table_kzt_pwy_cfb} {#GlideHTTPRequest-setFollowRedirect__table_lzt_pwy_cfb__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 10. Returns]

{#GlideHTTPRequest-setFollowRedirect__table_lzt_pwy_cfb}  
This example shows how to turn off redirects for an endpoint call using the
setFollowRedirect() method.

    var instance = 'dev12345';
    var username = 'admin';
    var password = 'yourpassword';

    // Instantiate request with ServiceNow API incidents table endpoint
    var request = new GlideHTTPRequest('https://'+instance+'.service-now.com/api/now/table/incident');

    // Add authentication data
    request.setBasicAuth(username, password);

    // Add the Accept header to get JSON response
    request.addHeader('Accept', 'application/json');

    // Turn off follow redirect - default is on (true)
    request.setFollowRedirect(false);

    // Execute the GET request
    var response = request.get();

    // Print the results: status code and number of records returned
    gs.print(response.getStatusCode());

Output

    200

## GlideHTTPRequest - setHttpTimeout(int timeout) {#ariaid-title7}

Sets the HTTP timeout value in milliseconds.
{#GlideHTTPRequest-setHttpTimeout__table_rjp_1ly_cfb__entry__3}

| Name | Type | Description |
|-|-|-|
| timeout | Integer | Timeout value to set. Unit: Milliseconds |
[Table 11. Parameters]

{#GlideHTTPRequest-setHttpTimeout__table_rjp_1ly_cfb} {#GlideHTTPRequest-setHttpTimeout__table_sjp_1ly_cfb__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 12. Returns]

{#GlideHTTPRequest-setHttpTimeout__table_sjp_1ly_cfb}  
This example shows how to set the time out value for an endpoint call using the
setTimeout() method.

    var instance = 'dev12345';
    var username = 'admin';
    var password = 'yourpassword';

    // Instantiate request with ServiceNow API incidents table endpoint
    var request = new GlideHTTPRequest('https://'+instance+'.service-now.com/api/now/table/incident');

    // Add authentication data
    request.setBasicAuth(username, password);

    // Add the Accept header to get JSON response
    request.addHeader('Accept', 'application/json');

    // Set the time out value
    request.setHttpTimeOut(1000);

    // Execute the GET request
    var response = request.get();

    // Print the results: status code and number of records returned
    gs.print(response.getStatusCode());

Output

    200

## GlideHTTPRequest - setLogLevel(String logLevel) {#ariaid-title8}

Sets the log level for an HTTP request.
{#GlideHTTPRequest-setLogLevel__table_ijx_myy_cfb__entry__3}

| Name | Type | Description |
|-|-|-|
| logLevel | String | The level of logging available. Note: For performance reasons, in production it is advisable to leave HTTP request logging at basic. Valid values: * basic: Covers many of the attributes of the HTTP transaction including host, path, response status, and so on. * elevated: Includes all of basic, as well as all request headers, the query string, and all response headers. * all: Includes all of elevated, as well as the request body and the response body. Default: basic |
[Table 13. Parameters]

{#GlideHTTPRequest-setLogLevel__table_ijx_myy_cfb} {#GlideHTTPRequest-setLogLevel__table_jjx_myy_cfb__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 14. Returns]

{#GlideHTTPRequest-setLogLevel__table_jjx_myy_cfb}  
This example shows how to set the log level for an endpoint call using the
setLogLevel() method.

    var instance = 'dev12345';
    var username = 'admin';
    var password = 'yourpassword';

    // Instantiate request with ServiceNow API incidents table endpoint
    var request = new GlideHTTPRequest('https://'+instance+'.service-now.com/api/now/table/incident');

    // Add authentication data
    request.setBasicAuth(username, password);

    // Add the Accept header to get JSON response
    request.addHeader('Accept', 'application/json');

    // Set the time out value
    request.setLogLevel(elevated);

    // Execute the GET request
    var response = request.get();

    // Print the results: status code and number of records returned
    gs.print(response.getStatusCode());

Output

    200

## GlideHTTPRequest - setupProxy(String host, String port) {#ariaid-title9}

Sets the proxy host and port for the associated REST call.
{#GlideHTTPRequest-setupProxy__table_aww_sry_cfb__entry__3}

| Name | Type | Description |
|-|-|-|
| host | String | Proxy host |
| port | String | Proxy port |
[Table 15. Parameters]

{#GlideHTTPRequest-setupProxy__table_aww_sry_cfb} {#GlideHTTPRequest-setupProxy__table_bww_sry_cfb__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 16. Returns]

{#GlideHTTPRequest-setupProxy__table_bww_sry_cfb}

