RESTResponseV2 - Scoped, Global
-
- UpdatedJan 30, 2025
- 5 minutes to read
- Yokohama
- API reference
The RESTResponseV2 API provides methods that allow you to use the data returned by an outbound REST message in JavaScript code.
A RESTResponseV2 object is returned by the RESTMessageV2 methods execute() and executeAsync().
You can use this API in scoped applications or within the global scope.
This API runs in the sn_ws
namespace.
RESTResponseV2 - getAllHeaders()
Returns all headers contained in the response, including any duplicate headers.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
List<GlideHTTPHeader> | List of headers contained in the response. Each header is represented as a GlideHTTPHeader object which contains the header name and value. |
Example
The follow code example shows how to call the REST Table API and then lists out all of the headers found in the response.
Response headers
RESTResponseV2 - getBody()
Gets the content of the REST response body.
Use this function when you want to get the request body as text content. Do not use this method when saving the response as a binary attachment. If a RESTMessageV2 object called the saveResponseBodyAsAttachment(...) function, using getBody() on the associated RESTResponseV2 object will cause an error. When saving the response as an attachment, if the outbound REST message fails, call getErrorMessage() on the response to retrieve the body content.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | REST response body. |
Example
RESTResponseV2 - getCookies()
Returns all cookies included in the response.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Object | Array of strings representing cookies. Iterate through the array to perform operations on each cookie. |
Example
Display individual cookies from the response.
RESTResponseV2 - getErrorCode()
Gets the numeric error code if there was an error during the REST transaction.
This error code is specific to the ServiceNow AI Platform, it is not an HTTP error code. Provide this error code if you require assistance from ServiceNow Customer Support.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Number | Numeric error code, such as 1 for socket timeout. |
Example
RESTResponseV2 - getErrorMessage()
Gets the error message if there was an error during the REST transaction.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | Error message. |
Example
RESTResponseV2 - getHeader(String name)
Gets the value for a specified header.
Name | Type | Description |
---|---|---|
name | String | Name of the header that you want the value for, such as Set-Cookie. |
Type | Description |
---|---|
String | Value of the specified header. |
Example
RESTResponseV2 - getHeaders()
Gets all headers returned in the REST response and the associated values.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Object | Object that maps the name of each header to the associated value. |
Example
RESTResponseV2 - getQueryString()
Gets the fully-resolved query sent to the REST endpoint..
This query contains the endpoint URL as well as any values assigned to variables in the REST message. Use this method only with responses to direct requests. This method is not supported for requests sent asynchronously, or requests sent using a MID server.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | Fully-resolved query. |
Example
RESTResponseV2 - getResponseAttachmentSysid()
Gets the sys_id value of the attachment created from the response body content.
If the RESTMessageV2 object associated with this response called the saveResponseBodyAsAttachment(...) function, use getResponseAttachmentSysid() to get the sys_id of the created attachment record. Use this function when you want to perform additional operations with the new attachment record.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | Sys_id of the new attachment record. |
RESTResponseV2 - getStatusCode()
Gets the numeric HTTP status code returned by the REST provider.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Number | Numeric status code returned by the REST provider, such as 200 for a successful response. |
Example
RESTResponseV2 - haveError()
Indicates if there was an error during the REST transaction.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
boolean | Returns true if there was an error, false if there was no error. |
Example
RESTResponseV2 - waitForResponse(Number timeoutSecs)
Set the amount of time the instance waits for a response from the web service provider.
This method overrides the property glide.rest.outbound.ecc_response.timeout for this REST response.
Name | Type | Description |
---|---|---|
timeoutSecs | Number | The amount of time, in seconds, to wait for this response. |
Type | Description |
---|---|
void |
Example
On this page
- RESTResponseV2 - getAllHeaders()
- RESTResponseV2 - getBody()
- RESTResponseV2 - getCookies()
- RESTResponseV2 - getErrorCode()
- RESTResponseV2 - getErrorMessage()
- RESTResponseV2 - getHeader(String name)
- RESTResponseV2 - getHeaders()
- RESTResponseV2 - getQueryString()
- RESTResponseV2 - getResponseAttachmentSysid()
- RESTResponseV2 - getStatusCode()
- RESTResponseV2 - haveError()
- RESTResponseV2 - waitForResponse(Number timeoutSecs)