HttpRequestData - Scoped

concept brazil Updated Sep 10, 2026 10 min read HttpRequestDataAPI.md
Raw file servicenow.com

The HttpRequestData API provides methods to build and manipulate a REST request before applying a signature and sending it to an endpoint.

Generate outbound signing requests using these APIs in the following order:

  1. HttpRequestData: Build the API request.
  2. AuthCredential: Create a credential object or update an existing one. Use the credential to sign the request through the RequestAuthAPI class.
  3. RequestAuthAPI: Sign the request and return an HttpRequestAuthedData object.
  4. HttpRequestAuthedData: Get information about the signed request.
  5. GlideHTTPRequest: Send the signed request.

Before using these APIs, you must configure an authentication algorithm to sign the request and associate it with the credential used to authenticate the request.

Use this API in scoped scripts with the sn_auth namespace identifier. You can instantiate this class using the constructor, or you can return an HttpRequestData object from the getHttpRequestData() method in the RequestAuthAPI class.

Parent Topic:Server API reference

HttpRequestData - HttpRequestData()

Instantiates an HttpRequestData object.

Name Type Description
None
JavaScript
var httpRequestData = new sn_auth.HttpRequestData();

HttpRequestData - addHeader(String key String value)

Adds a header to the HttpRequestData object.

Name Type Description
key String Name of the HTTP header.
value String Value of the HTTP Header.
Type Description
void

This example creates a REST request payload.

JavaScript
var endpoint= "https://s3.amazonaws.com";var httpRequestData = new sn_auth.HttpRequestData();httpRequestData.setEndpoint(endpoint);httpRequestData.setService('s3');httpRequestData.setRegion('us-east-1');httpRequestData.setHttpMethod("PUT");var content = "Action=SendMessage&MessageBody=This is a test message";httpRequestData.setContent(content);httpRequestData.addHeader('x-amz-acl', 'public-read' );

HttpRequestData - addQueryParam(String key, String value)

Adds a query parameter to the HttpRequestData object.

Name Type Description
key String Name of the query parameter.
value String Value of the query parameter.
Type Description
void
JavaScript
var endpoint= "https://third-party-endpoint";var httpRequestData = new sn_auth.HttpRequestData();httpRequestData.setEndpoint(endpoint);httpRequestData.setService('s3');httpRequestData.setRegion('us-east-1');httpRequestData.setHttpMethod('put');var content = "Action=SendMessage&MessageBody=This is a test message";httpRequestData.setContent(content);httpRequestData.addQueryParam('api_version', 'v2 );​

HttpRequestData - deleteHeader(String key)

Removes a header from the HttpRequestData object.

Name Type Description
key String Name of the HTTP header to remove.
Type Description
void
JavaScript
var endpoint= "https://s3.amazonaws.com";var httpRequestData = new sn_auth.HttpRequestData();httpRequestData.setEndpoint(endpoint);httpRequestData.setService('s3');httpRequestData.setRegion('us-east-1');httpRequestData.setHttpMethod('put');var content = "Action=SendMessage&MessageBody=This is a test message";httpRequestData.setContent(content);httpRequestData.deleteHeader('x-amz-acl');

HttpRequestData - getConnectionAliasID()

Returns the sys_id of the Connection & Credential alias associated with the Integration Hub REST step.

You can pass the sys_id to the ConnectionInfoProvider API to retrieve information about the connection.

Note: You can only use this method in an Integration Hub REST step. For more information, see REST step.

Name Type Description
None
Type Description
String Sys_id of the alias record from the Connection & Credential Aliases [sys_alias] table associated with the request.
JavaScript
var httpRequestData = new sn_auth.HttpRequestData();var id = httpRequestData.getConnectionAliasID(); var credential = new sn_cc.ConnectionInfoProvider().var connectionInfo = credential.getConnectionInfo(id);

HttpRequestData - getConnectionExtendedAttribute(String name)

Returns the value of a connection attribute associated with the Connection & Credential alias associated with Integration Hub REST step.

Note: You can only use this method in an Integration Hub REST step. For more information, see REST step.

For more information about connection attributes, see Create connection attributes for Integration Hub.

Name Type Description
name String Name of the connection attribute.
Type Description
String Value of the connection attribute.

This example returns the value of a connection attribute set on the Connection & Credential alias associated with the REST step.

JavaScript
var httpRequestData = new sn_auth.HttpRequestData();​gs.info("API Version is: " + httpRequestData.getConnectionExtendedAttribute('api_version'));

HttpRequestData - getContent()

Returns the content of the request in the HttpRequestData object.

Name Type Description
None
Type Description
String Content of the request.
JavaScript
var endpoint= "https://s3.amazonaws.com";var httpRequestData = new sn_auth.HttpRequestData();httpRequestData.setEndpoint(endpoint);httpRequestData.setService('s3');httpRequestData.setRegion('us-east-1');httpRequestData.setHttpMethod('put');var content = "Action=SendMessage&MessageBody=This is a test message";httpRequestData.setContent(content);httpRequestData.addHeader('x-amz-acl' , 'public-read' );var ct = httpRequestData.getContent();

Output:

Text
Action=SendMessage&MessageBody=This is a test message

HttpRequestData - getDate()

Returns the date when the request was signed.

Name Type Description
None

Type

Description

Number

The difference between January 1, 1970 UTC and when the request was signed.Unit: Milliseconds

``` var endpoint= "https://s3.amazonaws.com";​ var httpRequestData = new sn_auth.HttpRequestData();​ httpRequestData.setEndpoint(endpoint);​ httpRequestData.addQueryParam("list-type", "2");​ httpRequestData.setService('s3');​ httpRequestData.setHttpMethod('get');​

gs.info( "Date: " + httpRequestData.getDate());

Text
Output:

Date: 1349333576093

Text
## HttpRequestData - getDirective\(\)
Returns whether the signature is applied to the request in the header or as a query parameter.
By default, the system applies the signature to the header. You can apply the signature as a query parameter using the setDirective\(\) API.
|Name|Type|Description||----|----|-----------||None| | |
<table id="table_sjy_btx_sjb" class="returns"><thead><tr><th>
Type
</th><th>
Description
</th></tr></thead><tbody><tr><td>
String
</td><td>
Whether the signature is applied to the header or as a query parameter. Values include:
 -   HEADER: The signature is applied to the request header.-   QUERY: The signature is applied as a query parameter.
</td></tr></tbody></table>```var endpoint= "https://s3.amazonaws.com";​var httpRequestData = new sn_auth.HttpRequestData();​httpRequestData.setEndpoint(endpoint);​httpRequestData.addQueryParam("list-type", "2");​httpRequestData.setService('s3');​httpRequestData.setHttpMethod('get');​
gs.info( "Signature applied to: " + httpRequestData.getDirective() );

Output:

Text
Signature applied to: HEADER

HttpRequestData - getEndpoint()

Returns the endpoint set for the request.

Name Type Description
None
Type Description
String Endpoint set for the request.
JavaScript
var endpoint= "https://s3.amazonaws.com";​var httpRequestData = new sn_auth.HttpRequestData();​httpRequestData.setEndpoint(endpoint);​httpRequestData.addQueryParam("list-type", "2");​httpRequestData.setService('s3');​httpRequestData.setHttpMethod('get');​httpRequestData.setDirective("query");​​gs.info( "Endpoint is: " + httpRequestData.getEndpoint() );

Output:

Text
Endpoint is: https://s3.amazonaws.com

HttpRequestData - getExpiry()

Returns the time in seconds before the signature expires starting when the request was signed using the generateAuth() method in the RequestAuthAPI class.

The expiration is commonly set by the third-party service you are sending the request to, which overrides any value set by the setExpiry() method. For example, if the expiration is set to 900 seconds by the third-party service and you use the setExpiry() method to set the expiration to 300 seconds, the getExpiry() method returns 900 seconds.

Name Type Description
None

Type

Description

Number

Time before the signature expires.Unit: Seconds

``` var endpoint= "https://s3.amazonaws.com";​ var httpRequestData = new sn_auth.HttpRequestData();​ httpRequestData.setEndpoint(endpoint);​ httpRequestData.addQueryParam("list-type", "2");​ httpRequestData.setService('s3');​ httpRequestData.setHttpMethod('get');​ httpRequestData.setDirective("query");​ httpRequestData.setExpiry(300);

gs.info("Signature expires in: " + httpRequestData.getExpiry());

Text
Output:

Signature expires in: 300

Text
## HttpRequestData - getHeader\(String key\)
Returns the value associated with the given HTTP header.
|Name|Type|Description||----|----|-----------||key|String|Name of HTTP header.|
|Type|Description||----|-----------||String|Value of the given HTTP header.|

var endpoint= "https://third-party-endpoint"; var httpRequestData = new sn_auth.HttpRequestData(); httpRequestData.setEndpoint(endpoint); httpRequestData.setService('s3'); httpRequestData.setRegion('us-east-1'); httpRequestData.setHttpMethod('put'); var content = "Action=SendMessage&MessageBody=This is a test message"; httpRequestData.setContent(content); httpRequestData.addHeader('x-amz-acl', 'public-read' ); ​

gs.info( "Header value is: " + httpRequestData.getHeader('x-amz-acl') );

Text
Output:

Header value is: public-read

Text
## HttpRequestData - getHeaderMap\(\)
Returns an object containing the headers included in the request.
|Name|Type|Description||----|----|-----------||None| | |
<table id="table_thk_3tx_sjb" class="returns"><thead><tr><th>
Type
</th><th>
Description
</th></tr></thead><tbody><tr><td>
Object
</td><td>
Key-value pairs that define all of the headers associated with the request. Each key-value pair includes these parts:
 -   Key: String. Name of the header.-   Value: String. Value of the header.
</td></tr></tbody></table>```var endpoint= "https://third-party-endpoint";var httpRequestData = new sn_auth.HttpRequestData();httpRequestData.setEndpoint(endpoint);httpRequestData.setService('s3');httpRequestData.setRegion('us-east-1');httpRequestData.setHttpMethod('put');var content = "Action=SendMessage&MessageBody=This is a test message";httpRequestData.setContent(content);httpRequestData.addHeader('x-amz-acl', 'public-read' );httpRequestData.addHeader('content-type', 'application/json' );
var map = httpRequestData.getHeaderMap();
for(var x in map) {    var y = map[x]
    gs.info(x, y);}

Output:

Text
*** Script: x-amz-acl*** Script: content-type

HttpRequestData - getHost()

Returns the host used in the request.

Name Type Description
None
Type Description
String Host used in the request.
JavaScript
var endpoint= "https://third-party-endpoint";var httpRequestData = new sn_auth.HttpRequestData();httpRequestData.setEndpoint(endpoint);httpRequestData.setHost('myHost')httpRequestData.setService('s3');httpRequestData.setRegion('us-east-1');httpRequestData.setHttpMethod('put');var content = "Action=SendMessage&MessageBody=This is a test message";httpRequestData.setContent(content);httpRequestData.addHeader('x-amz-acl' , 'public-read' );
gs.info("Host is: " + httpRequestData.getHost());

Output:

Text
Host is: myHost

HttpRequestData - getHttpMethod()

Returns the HTTP method used in the request.

Name Type Description
None
Type Description
String HTTP method used in the request.
JavaScript
var endpoint= "https://third-party-endpoint";var httpRequestData = new sn_auth.HttpRequestData();httpRequestData.setEndpoint(endpoint);httpRequestData.setService('s3');httpRequestData.setRegion('us-east-1');httpRequestData.setHttpMethod('put');var content = "Action=SendMessage&MessageBody=This is a test message";httpRequestData.setContent(content);httpRequestData.addHeader('x-amz-acl', 'public-read' );​
gs.info("HTTP method is: " + httpRequestData.getHttpMethod());

Output:

Text
HTTP method is: PUT

HttpRequestData - getQueryParam(String key)

Returns the value of the specified query parameter.

Name Type Description
key String Name of the query parameter to get the value of.
Type Description
String Value of the query parameter.
JavaScript
var endpoint= "https://third-party-endpoint";var httpRequestData = new sn_auth.HttpRequestData();httpRequestData.setEndpoint(endpoint);httpRequestData.setService('s3');httpRequestData.setRegion('us-east-1');httpRequestData.setHttpMethod('put');var content = "Action=SendMessage&MessageBody=This is a test message";httpRequestData.setContent(content);httpRequestData.addQueryParam('api_version', 'v2' );
gs.info("API version is: " + httpRequestData.getQueryParam('api_version'));

Output:

Text
API version is: v2

HttpRequestData - getQueryParamMap()

Returns an object containing the query parameters included in the request.

Name Type Description
None

Type

Description

Object

Key-value pairs that define the query parameters associated with the request. Each key-value pair includes these parts:

  • Key: String. Name of the query parameter.
  • Value: String. Value of the query parameter.
``` var endpoint= "https://third-party-endpoint"; var httpRequestData = new sn_auth.HttpRequestData(); httpRequestData.setEndpoint(endpoint); httpRequestData.setService('s3'); httpRequestData.setRegion('us-east-1'); httpRequestData.setHttpMethod('put'); var content = "Action=SendMessage&MessageBody=This is a test message"; httpRequestData.setContent(content); httpRequestData.addQueryParam('api_version', 'v2' ); httpRequestData.addQueryParam('limit', '1000' ); httpRequestData.addQueryParam('offset', '1' );

var map = httpRequestData.getQueryParamMap(); gs.info("api_version is: " + map['api_version']);

Text
Output:

api_version is: v2

Text
## HttpRequestData - getRegion\(\)
Returns the region for the request that will be used in signing.
|Name|Type|Description||----|----|-----------||None| | |
|Type|Description||----|-----------||String|Name of the region.|

var endpoint= "https://third-party-endpoint"; var httpRequestData = new sn_auth.HttpRequestData(); httpRequestData.setEndpoint(endpoint); httpRequestData.setService('s3'); httpRequestData.setRegion('us-east-1'); httpRequestData.setHttpMethod('put'); var content = "Action=SendMessage&MessageBody=This is a test message"; httpRequestData.setContent(content);

gs.info("Region is: " + httpRequestData.getRegion());

Text
Output:

Region is: us-east-1

Text
## HttpRequestData - getService\(\)
Returns the service defined in the request.
|Name|Type|Description||----|----|-----------||None| | |
|Type|Description||----|-----------||String|Service defined in the request.|

var endpoint= "https://s3.amazonaws.com"; var httpRequestData = new sn_auth.HttpRequestData(); httpRequestData.setEndpoint(endpoint); httpRequestData.setService('s3');

gs.info("Service is: " + httpRequestData.getService());

Text
Output:

Service is: s3

Text
## HttpRequestData - setContent\(String content\)
Defines the content to send in the request.
**Note:** This method is not supported in script includes or MID server scripts.
|Name|Type|Description||----|----|-----------||content|String|Content to send in the request.|
|Type|Description||----|-----------||void| |

var endpoint= "https://s3.amazonaws.com"; var httpRequestData = new sn_auth.HttpRequestData(); httpRequestData.setEndpoint(endpoint); httpRequestData.setService('s3'); httpRequestData.setRegion('us-east-1'); httpRequestData.setHttpMethod('put'); var content = "This is a test message"; httpRequestData.setContent(content);

Text
## HttpRequestData - setDate\(Number date\)
Defines the date of the request used for signing.
Use this method only when testing whether the signature is created correctly based on a time stamp. In production, the signing request uses the time that you generated the signature; manually setting this value may cause the signing request to fail.
<table id="table_xzg_pcy_sjb" class="parameters"><thead><tr><th>
Name
</th><th>
Type
</th><th>
Description
</th></tr></thead><tbody><tr><td>
date
</td><td>
Number
</td><td>
The difference between January 1, 1970 UTC and the date used to sign the request.Unit: Milliseconds
</td></tr></tbody></table>|Type|Description||----|-----------||void| |

var endpoint= "https://s3.amazonaws.com";​ var httpRequestData = new sn_auth.HttpRequestData();​ httpRequestData.setEndpoint(endpoint);​ httpRequestData.addQueryParam("list-type", "2");​ httpRequestData.setService('s3');​ httpRequestData.setHttpMethod('get'); httpRequestData.setDate(1349333576093);

Text
## HttpRequestData - setDirective\(String directive\)
Defines whether to apply the signature to the request in a header or as a query parameter.
<table id="table_nxn_rcy_sjb" class="parameters"><thead><tr><th>
Name
</th><th>
Type
</th><th>
Description
</th></tr></thead><tbody><tr><td>
directive
</td><td>
String
</td><td>
Whether to apply the signature to the header or as a query parameter. Values include:
 -   `query`: Applies signature as a query parameter.-   `header`: Applies signature to the request header.
 Default: header
</td></tr></tbody></table>|Type|Description||----|-----------||void| |

var endpoint= "https://s3.amazonaws.com";​ var httpRequestData = new sn_auth.HttpRequestData();​ httpRequestData.setEndpoint(endpoint);​ httpRequestData.addQueryParam("list-type", "2");​ httpRequestData.setService('s3');​ httpRequestData.setHttpMethod('get');​ httpRequestData.setDirective("query");​

Text
## HttpRequestData - setEndpoint\(String endpoint\)
Defines the endpoint to send the request to.
|Name|Type|Description||----|----|-----------||endpoint|String|Endpoint to send the request to. The endpoint can include query parameters, path, and version.|
|Type|Description||----|-----------||void| |

var endpoint="https://third-party-endpoint/path-parameters/version";

var httpRequestData = new sn_auth.HttpRequestData(); httpRequestData.setEndpoint(endpoint);

Text
## HttpRequestData - setExpiry\(Number expiry\)
Sets the amount of time before the signature expires starting when the request is signed using the generateAuth\(\) method in the RequestAuthAPI class.
The expiration is commonly set by the third-party service you are sending the request to, which overrides any value set by the setExpiry\(\) method. For example, if the expiration is set to 900 seconds by the third-party service and you use the setExpiry\(\) method to set the expiration to 300 seconds, the getExpiry\(\) method returns 900 seconds.
<table id="table_wbj_5cy_sjb" class="parameters"><thead><tr><th>
Name
</th><th>
Type
</th><th>
Description
</th></tr></thead><tbody><tr><td>
expiry
</td><td>
Number
</td><td>
Amount of time before the signature expires.Unit: Seconds
</td></tr></tbody></table>|Type|Description||----|-----------||void| |

var endpoint= "https://s3.amazonaws.com";​ var httpRequestData = new sn_auth.HttpRequestData();​ httpRequestData.setEndpoint(endpoint);​ httpRequestData.addQueryParam("list-type", "2");​ httpRequestData.setService('s3');​ httpRequestData.setHttpMethod('get');​ httpRequestData.setExpiry(300);​

Text
## HttpRequestData - setHost\(String host\)
Defines the host used in the request.
|Name|Type|Description||----|----|-----------||host|String|Name of the HTTP request host.|
|Type|Description||----|-----------||void| |

var endpoint= "https:third-party-endpoint"; var httpRequestData = new sn_auth.HttpRequestData(); httpRequestData.setEndpoint(endpoint); httpRequestData.setHost('myHost') httpRequestData.setService('s3'); httpRequestData.setRegion('us-east-1'); httpRequestData.setHttpMethod('put'); var content = "Action=SendMessage&MessageBody=This is a test message"; httpRequestData.setContent(content); httpRequestData.addHeader('x-amz-acl', 'public-read' );

Text
## HttpRequestData - setHttpMethod\(String httpMethod\)
Sets the HTTP method to use in the request.
|Name|Type|Description||----|----|-----------||httpMethod|String|HTTP method to use in the request.|
|Type|Description||----|-----------||void| |

var endpoint= "https://third-party-endpoint"; var httpRequestData = new sn_auth.HttpRequestData(); httpRequestData.setEndpoint(endpoint); httpRequestData.setService('s3'); httpRequestData.setRegion('us-east-1'); httpRequestData.setHttpMethod('put');

Text
## HttpRequestData - setRegion\(String region\)
Defines the region to use for the request in signing.
|Name|Type|Description||----|----|-----------||region|String|The region to use to sign the request. Available values are determined by the third-party API's requirements.|
|Type|Description||----|-----------||void| |

var endpoint= "https:third-party-endpoint"; var httpRequestData = new sn_auth.HttpRequestData(); httpRequestData.setEndpoint(endpoint); httpRequestData.setService('s3'); httpRequestData.setRegion('us-east-1'); httpRequestData.setHttpMethod('put'); var content = "Action=SendMessage&MessageBody=This is a test message"; httpRequestData.setContent(content);

Text
## HttpRequestData - setService\(String service\)
Defines the service for the request.
|Name|Type|Description||----|----|-----------||service|String|The service for the request.|
|Type|Description||----|-----------||void| |

var endpoint= "https://s3.amazonaws.com"; var httpRequestData = new sn_auth.HttpRequestData(); httpRequestData.setEndpoint(endpoint); httpRequestData.setService('s3');

Text

Search documentation
Search document titles and file paths on the brazil branch