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


---

# SOAPResponseV2 - Scoped, Global

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

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

The SOAPResponseV2 API provides methods that use the data returned by an outbound SOAP message in JavaScript code.

A SOAPResponseV2 object is returned by the SOAPMessageV2 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.  
See also:

* [Direct SOAPMessageV2 example](https://servicenow-prod.fluidtopics.net/Q0oC78mmlaS0VIM_o4HTZw "You can send an outbound SOAP message directly to the endpoint.")
* [Recordless SOAPMessageV2
  example](https://servicenow-prod.fluidtopics.net/NNAaS_T1LCv2SqDVr6oyaQ "You can use the SOAPMessageV2() constructor with no parameters to define a SOAP message entirely in the script.")
* [Asynchronous SOAPMessageV2
  example](https://servicenow-prod.fluidtopics.net/v0q1hWnHjzDy5mH~yx8NjA "You can send an outbound SOAP message asynchronously.")
* [SOAPMessageV2 MID server
  example](https://servicenow-prod.fluidtopics.net/7aPfnb7IRscgj1OX6Q0Rlg "You can send an outbound SOAP message through a MID Server.")
{#c_SOAPResponseV2API__ul_kh3_zx1_w4b}

## SOAPResponseV2 - getAllHeaders() {#ariaid-title2}

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

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

{#SRV2-getAllHeaders__table_u2p_3bl_gz} {#SRV2-getAllHeaders__table_v2p_3bl_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]

{#SRV2-getAllHeaders__table_v2p_3bl_gz}  

    var r = new sn_ws.SOAPMessageV2('<A SOAP message>', 'get');
    var response = r.execute();
    var headers = response.getAllHeaders();
    for(var i in headers){
      gs.info(headers[i].name + ': ' + headers[i].value);
    }

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

Gets the content of the SOAP response body.
{#r_SOAPResponseV2-getBody__table_vy2_525_jqy__entry__3}

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

{#r_SOAPResponseV2-getBody__table_vy2_525_jqy} {#r_SOAPResponseV2-getBody__table_qpt_3f5_jq__entry__2}

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

{#r_SOAPResponseV2-getBody__table_qpt_3f5_jq}  

    var body = response.getBody();

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

Returns all cookies included in the response.
{#r_SOAPResponseV2-getCookies__table_m1h_bcw_ns__entry__3}

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

{#r_SOAPResponseV2-getCookies__table_m1h_bcw_ns} {#r_SOAPResponseV2-getCookies__table_n1h_bcw_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_SOAPResponseV2-getCookies__table_n1h_bcw_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=/

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

Gets the numeric error code if there was an error during the SOAP
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 Customer Service and Support.
{#r_SOAPResponseV2-getErrorCode__table_vy2_525_jqx__entry__3}

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

{#r_SOAPResponseV2-getErrorCode__table_vy2_525_jqx} {#r_SOAPResponseV2-getErrorCode__table_qpt_3f5_jq__entry__2}

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

{#r_SOAPResponseV2-getErrorCode__table_qpt_3f5_jq}  

    var errorCode = response.getErrorCode();

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

Gets the error message if there was an error during the SOAP transaction.
{#r_SOAPResponseV2-getErrorMessage__table_vy2_525_jqw__entry__3}

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

{#r_SOAPResponseV2-getErrorMessage__table_vy2_525_jqw} {#r_SOAPResponseV2-getErrorMessage__table_qpt_3f5_jq__entry__2}

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

{#r_SOAPResponseV2-getErrorMessage__table_qpt_3f5_jq}  

    var errorMsg = response.getErrorMessage();

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

Gets the value for a specified HTTP header.
{#r_SOAPResponseV2-getHeader_S__table_vy2_525_jq13__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_SOAPResponseV2-getHeader_S__table_vy2_525_jq13} {#r_SOAPResponseV2-getHeader_S__table_qpt_3f5_jq__entry__2}

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

{#r_SOAPResponseV2-getHeader_S__table_qpt_3f5_jq}  

    var headerVal = response.getHeader("Accept");

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

Gets all HTTP headers returned in the SOAP 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_SOAPResponseV2-getHeaders__table_vy2_525_jqaa__entry__3}

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

{#r_SOAPResponseV2-getHeaders__table_vy2_525_jqaa} {#r_SOAPResponseV2-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_SOAPResponseV2-getHeaders__table_qpt_3f5_jq}  

    var headers = response.getHeaders();

## SOAPResponseV2 - getStatusCode() {#ariaid-title9}

Gets the numeric HTTP status code returned by the SOAP provider.
{#r_SOAPResponseV2-getStatusCode__table_vy2_525_jqab__entry__3}

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

{#r_SOAPResponseV2-getStatusCode__table_vy2_525_jqab} {#r_SOAPResponseV2-getStatusCode__table_qpt_3f5_jq__entry__2}

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

{#r_SOAPResponseV2-getStatusCode__table_qpt_3f5_jq}  

    var statusCode = response.getStatusCode();

## SOAPResponseV2 - haveError() {#ariaid-title10}

Indicates if there was an error during the SOAP transaction.
{#r_SOAPResponseV2-haveError__table_vy2_525_jqac__entry__3}

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

{#r_SOAPResponseV2-haveError__table_vy2_525_jqac} {#r_SOAPResponseV2-haveError__table_qpt_3f5_jq__entry__2}

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

{#r_SOAPResponseV2-haveError__table_qpt_3f5_jq}  

    var error = response.haveError();

## SOAPResponseV2 - waitForResponse(Number timeoutSecs) {#ariaid-title11}

Sets the amount of time the instance waits for a response from the web service
provider.
This method overrides the property glide.soap.outbound.ecc_response.timeout for this SOAP
response.
{#r_SOAPResponseV2-waitForResponse_N__table_vy2_525_jq14__entry__3}

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

{#r_SOAPResponseV2-waitForResponse_N__table_vy2_525_jq14} {#r_SOAPResponseV2-waitForResponse_N__table_jzp_hmh_dr__entry__2}

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

{#r_SOAPResponseV2-waitForResponse_N__table_jzp_hmh_dr}  

    response.waitForResponse(60);


