---
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


---

# RESTResponseV2 - Scoped, Global

# RESTResponseV2 - Scoped, Global {#ariaid-title1}

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

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() {#ariaid-title2}

Returns all headers contained in the response, including any duplicate
headers.
{#RRV2-getAllHeaders__table_hyh_l1l_gz__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 1. Parameters]

{#RRV2-getAllHeaders__table_hyh_l1l_gz} {#RRV2-getAllHeaders__table_iyh_l1l_gz__entry__2}

| Type | Description |
|-|-|
| List\<GlideHTTPHeader\> | List of headers contained in the response. Each header is represented as a GlideHTTPHeader object which contains the header <var class="keyword varname">name</var> and <var class="keyword varname">value</var>. |
[Table 2. Returns]

{#RRV2-getAllHeaders__table_iyh_l1l_gz}  
The follow code example shows how to call the REST Table API and then lists out all of the
headers found in the response.

    var request = new sn_ws.RESTMessageV2();
    request.setEndpoint('http://<SN_Instance_host>/api/now/table/incident');
    request.setHttpMethod('GET');

    request.setBasicAuth('username', 'password');
    request.setRequestHeader("Accept", "application/json");
    var res = request.execute();
    if (res.getStatusCode() != 200) {
      gs.info('Bad Request');
    }

    var headers = res.getAllHeaders();
    for(var i in headers){
      gs.info(headers[i].name + ': ' + headers[i].value);
    }

Response headers

    X-Is-Logged-In: true
    X-Transaction-ID: e3003cb2db8c
    X-Total-Count: 66
    X-Content-Type-Options: nosniff
    Pragma: no-store,no-cache
    Cache-Control: no-cache,no-store,must-revalidate,max-age=-1
    Expires: 0
    Content-Type: application/json;charset=UTF-8
    Date: Fri, 14 May 2021 16:05:10 GMT
    Connection: close
    Server: ServiceNow
    JSESSIONID=5041870726ADADFAB2EE2BF8E7E01596; Path=/; HttpOnly; SameSite=None; Secure
    Set-Cookie: glide_user=; Max-Age=0; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; HttpOnly; SameSite=None; Secure
    Set-Cookie: glide_user_session=; Max-Age=0; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; HttpOnly; SameSite=None; Secure
    Set-Cookie: glide_user_route=glide.f1aa2015b3fa5fa8dfe567386cde8fd5; Max-Age=2147483647; Expires=Wed, 01-Jun-2089 19:19:17 GMT; Path=/; HttpOnly; SameSite=None; Secure
    Set-Cookie: glide_session_store=AF003CB2DB8CF8103DD9C39D139619C7; Max-Age=1800; Expires=Fri, 14-May-2021 16:35:10 GMT; Path=/; HttpOnly; SameSite=None; Secure
    Set-Cookie: BIGipServerpool_ddershem=2643023626.45630.0000; path=/; Httponly; Secure; SameSite=None; Secure
    Strict-Transport-Security: max-age=63072000; includeSubDomains

## RESTResponseV2 - getBody() {#ariaid-title3}

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.
{#r_RESTResponseV2-getBody__table_vy2_525_jqg__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 3. Parameters]

{#r_RESTResponseV2-getBody__table_vy2_525_jqg} {#r_RESTResponseV2-getBody__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| String | REST response body. |
[Table 4. Returns]

{#r_RESTResponseV2-getBody__table_qpt_3f5_jq}  

    var sm = new sn_ws.RESTMessageV2("Yahoo Finance","get"); //Might throw exception if message doesn't exist or not visible due to scope.
    var response = sm.execute();
    var responseBody = response.getBody();

## RESTResponseV2 - getCookies() {#ariaid-title4}

Returns all cookies included in the response.
{#r_RESTResponseV2-getCookies__table_wcc_nbw_ns__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 5. Parameters]

{#r_RESTResponseV2-getCookies__table_wcc_nbw_ns} {#r_RESTResponseV2-getCookies__table_xcc_nbw_ns__entry__2}

| Type | Description |
|-|-|
| Object | Array of strings representing cookies. Iterate through the array to perform operations on each cookie. |
[Table 6. Returns]

{#r_RESTResponseV2-getCookies__table_xcc_nbw_ns}  
Display individual cookies from the response.

    var cookies = response.getCookies();
    for (var i = 0; i < cookies.length; i++) {
      gs.info('cookie: ' + cookies.get(i));
    }

Output:

    cookie: JSESSIONID=4135AA97A5D12DA22EF614AA2B0CAFD8.node20; Path=/; Secure; HttpOnly
    cookie: SABASESSIONID=370152970.36895.0000; path=/

## RESTResponseV2 - getErrorCode() {#ariaid-title5}

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.  
Note:  
To retrieve the contents of the actual error message, use the [getBody()](https://servicenow-prod.fluidtopics.net/HDcUIkSJvvQB1V5Oamz~vQ#r_RESTResponseV2-getBody "Gets the content of the REST response body.") method.
{#r_RESTResponseV2-getErrorCode__table_vy2_525_jqh__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 7. Parameters]

{#r_RESTResponseV2-getErrorCode__table_vy2_525_jqh} {#r_RESTResponseV2-getErrorCode__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| Number | Numeric error code, such as 1 for socket timeout. |
[Table 8. Returns]

{#r_RESTResponseV2-getErrorCode__table_qpt_3f5_jq}  

    var sm = new sn_ws.RESTMessageV2("Yahoo Finance","get"); //Might throw exception if message doesn't exist or not visible due to scope.
    var response = sm.execute();
    var errorCode = response.getErrorCode();

## RESTResponseV2 - getErrorMessage() {#ariaid-title6}

Gets the error message if there was an error during the REST transaction.
{#r_RESTResponseV2-getErrorMessage__table_vy2_525_jqi__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 9. Parameters]

{#r_RESTResponseV2-getErrorMessage__table_vy2_525_jqi} {#r_RESTResponseV2-getErrorMessage__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| String | Error message. |
[Table 10. Returns]

{#r_RESTResponseV2-getErrorMessage__table_qpt_3f5_jq}  

    var sm = new sn_ws.RESTMessageV2("Yahoo Finance","get"); //Might throw exception if message doesn't exist or not visible due to scope.
    var response = sm.execute();
    var errorMsg = response.getErrorMessage();

## RESTResponseV2 - getHeader(String name) {#ariaid-title7}

Gets the value for a specified header.
{#r_RESTResponseV2-getHeader_S__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| name | String | Name of the header that you want the value for, such as Set-Cookie. |
[Table 11. Parameters]

{#r_RESTResponseV2-getHeader_S__table_vy2_525_jq} {#r_RESTResponseV2-getHeader_S__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| String | Value of the specified header. |
[Table 12. Returns]

{#r_RESTResponseV2-getHeader_S__table_qpt_3f5_jq}  

    var sm = new sn_ws.RESTMessageV2("Yahoo Finance","get"); //Might throw exception if message doesn't exist or not visible due to scope.
    var response = sm.execute();
    var headerVal = response.getHeader("Content-Type");

## RESTResponseV2 - getHeaders() {#ariaid-title8}

Gets all headers returned in the REST response and the associated values.
Note:  
If a header is present more than once in the response, such as a Set-Cookie header, this function returns only the last of the duplicate headers. To return all headers including duplicates, use the getAllHeaders() function.
{#r_RESTResponseV2-getHeaders__table_vy2_525_jqj__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 13. Parameters]

{#r_RESTResponseV2-getHeaders__table_vy2_525_jqj} {#r_RESTResponseV2-getHeaders__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| Object | Object that maps the name of each header to the associated value. |
[Table 14. Returns]

{#r_RESTResponseV2-getHeaders__table_qpt_3f5_jq}  

    var sm = new sn_ws.RESTMessageV2("Yahoo Finance","get"); //Might throw exception if message doesn't exist or not visible due to scope.
    var response = sm.execute();
    var headers = response.getHeaders();

## RESTResponseV2 - getQueryString() {#ariaid-title9}

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.
{#r_RESTResponseV2-getQueryString__table_vy2_525_jqk__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 15. Parameters]

{#r_RESTResponseV2-getQueryString__table_vy2_525_jqk} {#r_RESTResponseV2-getQueryString__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| String | Fully-resolved query. |
[Table 16. Returns]

{#r_RESTResponseV2-getQueryString__table_qpt_3f5_jq}  

    var sm = new sn_ws.RESTMessageV2("Yahoo Finance","get"); //Might throw exception if message doesn't exist or not visible due to scope.
    var response = sm.execute();
    var queryString = response.getQueryString();

## RESTResponseV2 - getResponseAttachmentSysid() {#ariaid-title10}

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.
{#r_RRV2-getResponseAttachmentSysid__table_kzq_vd2_vs__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 17. Parameters]

{#r_RRV2-getResponseAttachmentSysid__table_kzq_vd2_vs} {#r_RRV2-getResponseAttachmentSysid__table_lzq_vd2_vs__entry__2}

| Type | Description |
|-|-|
| String | Sys_id of the new attachment record. |
[Table 18. Returns]

{#r_RRV2-getResponseAttachmentSysid__table_lzq_vd2_vs}

## RESTResponseV2 - getStatusCode() {#ariaid-title11}

Gets the numeric HTTP status code returned by the REST provider.
{#r_RESTResponseV2-getStatusCode__table_vy2_525_jql__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 19. Parameters]

{#r_RESTResponseV2-getStatusCode__table_vy2_525_jql} {#r_RESTResponseV2-getStatusCode__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| Number | Numeric status code returned by the REST provider, such as 200 for a successful response. |
[Table 20. Returns]

{#r_RESTResponseV2-getStatusCode__table_qpt_3f5_jq}  

    var sm = new sn_ws.RESTMessageV2("Yahoo Finance","get"); //Might throw exception if message doesn't exist or not visible due to scope.
    var response = sm.execute();
    var statusCode = response.getStatusCode();

## RESTResponseV2 - haveError() {#ariaid-title12}

Indicates if there was an error during the REST transaction.
{#r_RESTResponseV2-haveError__table_vy2_525_jqm__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 21. Parameters]

{#r_RESTResponseV2-haveError__table_vy2_525_jqm} {#r_RESTResponseV2-haveError__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| boolean | Returns true if there was an error, false if there was no error. |
[Table 22. Returns]

{#r_RESTResponseV2-haveError__table_qpt_3f5_jq}  

    var sm = new sn_ws.RESTMessageV2("Yahoo Finance","get"); //Might throw exception if message doesn't exist or not visible due to scope.
    var response = sm.execute();
    var error = response.haveError();

## RESTResponseV2 - waitForResponse(Number timeoutSecs) {#ariaid-title13}

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.
{#r_RESTResponseV2-waitForResponse_N__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| timeoutSecs | Number | The amount of time, in seconds, to wait for this response. |
[Table 23. Parameters]

{#r_RESTResponseV2-waitForResponse_N__table_vy2_525_jq} {#r_RESTResponseV2-waitForResponse_N__table_nxp_dmh_dr__entry__2}

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

{#r_RESTResponseV2-waitForResponse_N__table_nxp_dmh_dr}  

    var sm = new sn_ws.RESTMessageV2("Yahoo Finance","get"); //Might throw exception if message doesn't exist or not visible due to scope.
    var response = sm.executeAsync();
    response.waitForResponse(60);


