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

 Release :

    - australia

ft:locale :

    - en-US

ft:publication_title :

    - Australia API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# Fetch Headers - Scoped, Global

# Fetch Headers - Scoped, Global {#ariaid-title1}

Release version: Australia  
Updated March 12, 2026  
![](https://www.servicenow.com/docs/portal-asset/ico-clock) 8 minutes to read  
The Fetch Headers API allows you to retrieve, set, add to, and remove headers from a list of request or response headers.  
This API is part of a set of Fetch APIs, which provide various actions for fetching resources from external websites. The full Fetch API collection includes:

* [Fetch - fetch(String resource, Object options)](https://servicenow-prod.fluidtopics.net/BjgPgdTN~sDlsIbr8dv_gg#fetch.fetch_S_O "Starts the process of fetching a resource from the network and returns a promise that is fulfilled once the response is available."): Starts the process of fetching a resource from the network.
* [Fetch Headers - Scoped, Global](https://servicenow-prod.fluidtopics.net/QpYPN4iIPDFYc0lpxGykDQ#Fetch.HeadersAPI "The Fetch Headers API allows you to retrieve, set, add to, and remove headers from a list of request or response headers."): Retrieve and modify request and response headers.
* [Fetch Request - Scoped, Global](https://servicenow-prod.fluidtopics.net/W0gJkwIJSZxt9ZBuK47pfg#Fetch.RequestAPI "The Fetch Request API contains methods for creating or retrieving a Request object to allow applications to asynchronously request resources, such as JSON, text, or binary data, from a server, and handle the response. This API supports various HTTP methods like GET, POST, PUT, DELETE, and so on."): Create a new request object.
* [Fetch RequestInit - Scoped, Global](https://servicenow-prod.fluidtopics.net/u~mCRUkZ0_odSqZr~o5F4A#Fetch.RequestInitAPI "The RequestInit API provides options to configure a Fetch request."): Set options to configure a fetch request.
* [Fetch Response - Scoped,Global](https://servicenow-prod.fluidtopics.net/dRaKslSlaxFBm4A0S5Hneg#Fetch.ResponseAPI "The Fetch Response API provides methods for creating a new Response object and for handling the response body created by a Fetch Request API method."): Create a new response object.
{#Fetch.HeadersAPI__ul_akb_fsf_pdc}

To support fetch actions, the system property, `glide.hosts.allowlist`, allows controls over what hosts a fetch method can access. It applies to HTTP APIs like RestMessageV2 and those mentioned
above. For more information about `glide.hosts.allowlist`, see [Available system properties](https://www.servicenow.com/docs/access?context=r_AvailableSystemProperties&version=australia&pubname=australia-platform-administration&ft:locale=en-US).

## Fetch Headers - Headers(init) {#ariaid-title2}

The Headers() constructor creates a new, empty Headers object. You can also create and pre-populate a new Headers object with list of HTTP headers using the init parameter.
Note:  
To add headers to an existing Headers object, use [Fetch Headers - append(String name, String value)](https://servicenow-prod.fluidtopics.net/QpYPN4iIPDFYc0lpxGykDQ#fetch.headers-append_S_S "Adds a new value to an existing header inside a Headers object, or adds the header if it does not already exist.").
{#fetch.headers-constructor__table_nzn_3rv_gdc__entry__3}

| Name | Type | Description |
|-|-|-|
| init | Object | Optional. An object literal containing HTTP headers to pre-populate the new Headers object with. Valid values: * An object literal with string values, * An array of name-value pairs, * An existing Headers object (where the new object copies data from the existing object). Default: Creates an empty Headers object |
[Table 1. Parameters]

{#fetch.headers-constructor__table_nzn_3rv_gdc}  
The following example shows how to use the Headers() constructor to create a new Headers object with and without headers.

    //Intializes an empty Headers object.
    var headers = new Headers();

    //Sets the new Headers object with a list of headers.
    var httpHeaders = {
      "Content-Type": "application/json", 
      "X-My-Custom-Header": "XYZ", 
    }; 

    var myHeaders = new Headers(httpHeaders);

## Fetch Headers - append(String name, String value) {#ariaid-title3}

Adds a new value to an existing header inside a Headers object, or adds the header if it does not already exist.
If the specified header already exists, `append()` changes its existing value to the specified value. If the specified header already exists and accepts multiple values, `append()` appends the new
value to the end of the value set. To overwrite the old value with a new one, use [Fetch Headers - set(String name, String value)](https://servicenow-prod.fluidtopics.net/QpYPN4iIPDFYc0lpxGykDQ#fetch.headers-set_S_S "Updates a value of an existing header inside the Headers object, or creates a new header with the given value if the header does not already exist.").
{#fetch.headers-append_S_S__table_kpj_czp_jdc__entry__3}

| Name | Type | Description |
|-|-|-|
| name | String | Required. The name of the HTTP header to add to the Headers object. |
| value | String | Required. The value of the HTTP header to add. |
[Table 2. Parameters]

{#fetch.headers-append_S_S__table_kpj_czp_jdc} {#fetch.headers-append_S_S__table_lpj_czp_jdc__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 3. Returns]

{#fetch.headers-append_S_S__table_lpj_czp_jdc}  
The following example shows how to add a header using append():

    var myHeaders = new Headers(); // Currently empty
    myHeaders.append("Content-Type", "image/jpeg");
    myHeaders.get("Content-Type"); // Returns 'image/jpeg'

Output:

    "image/jpeg"

The following example shows how to append a new header that accepts multiple values:

    var myHeaders = new Headers(); // Currently empty
    myHeaders.append("Accept-Encoding", "deflate");
    myHeaders.append("Accept-Encoding", "gzip");
    myHeaders.get("Accept-Encoding"); // Returns 'deflate, gzip'

Output:

    {"deflate", "gzip"} 

## Fetch Headers - delete(String name) {#ariaid-title4}

Deletes a header from the current Headers object.
{#fetch.headers-delete_S__table_zpr_f1q_jdc__entry__3}

| Name | Type | Description |
|-|-|-|
| name | String | The name of the HTTP header to delete from the Headers object. |
[Table 4. Parameters]

{#fetch.headers-delete_S__table_zpr_f1q_jdc} {#fetch.headers-delete_S__table_aqr_f1q_jdc__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 5. Returns]

{#fetch.headers-delete_S__table_aqr_f1q_jdc}  
The following example shows how to first add a header to the Headers object using append(), and then delete the same header using delete().

    var myHeaders =newHeaders();// Currently empty
    myHeaders.append("Content-Type","image/jpeg");
    myHeaders.get("Content-Type");// Returns 'image/jpeg'

The following example shows that the endpoint returns a value of null if the Headers object is already deleted:

    myHeaders.delete("Content-Type");
    myHeaders.get("Content-Type");// Returns null, as it has been deleted

Output:

    null

## Fetch Headers - entries() {#ariaid-title5}

Returns an iterator allowing you to cycle through all key-value pairs (represented with strings) contained in the Headers object.
{#fetch.headers-entries__table_es2_fbq_jdc__entry__3}

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

{#fetch.headers-entries__table_es2_fbq_jdc} {#fetch.headers-entries__table_fs2_fbq_jdc__entry__2}

| Type | Description |
|-|-|
| Iterator | Returns an iterator object, where both the key and value pairs are String objects. |
[Table 7. Returns]

{#fetch.headers-entries__table_fs2_fbq_jdc}  
The following example shows how to create a test Headers object and then use the entries() method to return an iterator of all values in the Headers object.

    // Create a test Headers object
    var myHeaders = new Headers();
    myHeaders.append("Content-Type", "text/xml");
    myHeaders.append("Vary", "Accept-Language");

    // Display the key/value pairs
    for (var pair of myHeaders.entries()) {
      console.log(`${pair[0]}: ${pair[1]}`);
    }

Output:

    content-type: text/xml
    vary: Accept-Language

## Fetch Headers - forEach(Function callbackFn, Object thisArg) {#ariaid-title6}

Executes a callback function once per each key/value pair in the Headers object.
The callback function does not execute for deleted keys but does for existing keys even if the value is undefined.
{#fetch.headers-forEach_O_S__table_pjv_xcq_jdc__entry__3}

| Name | Type | Description |
|-|-|-|
| callbackFn | Function | Function to execute for each key/value pair in the Headers object. Conforms to the format: `callbackFn(string key, string value)`. |
| callbackFn.value | String | Value of the header entry. |
| callbackFn.key | String | Name of the header entry. |
| callBackFn.object | Header | The Headers object to iterate. |
| thisArg | Object | Value to use as `this` when executing `callback`. |
[Table 8. Parameters]

{#fetch.headers-forEach_O_S__table_pjv_xcq_jdc} {#fetch.headers-forEach_O_S__table_qjv_xcq_jdc__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 9. Returns]

{#fetch.headers-forEach_O_S__table_qjv_xcq_jdc}  
The following example logs a line for each key/value pair in the Headers object:

    // Create a new test Headers object
    var myHeaders = new Headers();
    myHeaders.append("Content-Type", "application/json");
    myHeaders.append("Cookie", "This is a demo cookie");
    myHeaders.append("compression", "gzip");

    // Display the key/value pairs
    myHeaders.forEach((value, key) => {
      console.log(`${key} ==> ${value}`);
    });

Output:

    compression ==> gzip
    content-type ==> application/json
    cookie ==> This is a demo cookie

## Fetch Headers - get(String name) {#ariaid-title7}

Returns a string of all header values of a specified Headers object, or returns null if the header does not exist.
{#fetch.headers-get_S__table_lg2_kfq_jdc__entry__3}

| Name | Type | Description |
|-|-|-|
| name | String | The name of the HTTP header whose headers values you want to retrieve (case-insensitive). |
[Table 10. Parameters]

{#fetch.headers-get_S__table_lg2_kfq_jdc} {#fetch.headers-get_S__table_mg2_kfq_jdc__entry__2}

| Type | Description |
|-|-|
| String | The value of the retrieved header (represented as a string), or null if the header is not set. Returns an error if the header does not exist. Returns a type error if the given name is not that of an HTTP header. |
[Table 11. Returns]

{#fetch.headers-get_S__table_mg2_kfq_jdc}  
The following shows how to create a headers object with multiple headers using append(), and then return the header's values using the get() method.

    var myHeaders = new Headers(); // Currently empty
    myHeaders.append("Accept-Encoding", "deflate");
    myHeaders.append("Accept-Encoding", "gzip");
    myHeaders.get("Accept-Encoding"); // Returns "deflate, gzip"
    myHeaders
      .get("Accept-Encoding")
      .split(",")
      .map((v) => v.trimStart()); // Returns [ "deflate", "gzip"

Output:

    [ "deflate", "gzip" ]

## Fetch Headers - getSetCookie() {#ariaid-title8}

Returns all Set-Cookie headers associated with a response.
{#fetch.headers-getSetCookie__table_spp_hgq_jdc__entry__3}

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

{#fetch.headers-getSetCookie__table_spp_hgq_jdc} {#fetch.headers-getSetCookie__table_tpp_hgq_jdc__entry__2}

| Type | Description |
|-|-|
| Array of strings | An array of strings containing the values of all Set-Cookie headers associated with a response. The method returns an empty array if no Set-Cookie headers are set. |
[Table 13. Returns]

{#fetch.headers-getSetCookie__table_tpp_hgq_jdc}  
The following script example shows how to use getSetCookie() to return the header values associated with the response:

    var headers = new Headers({
      "Set-Cookie": "name1=value1",
    });

    headers.append("Set-Cookie", "name2=value2");

    headers.getSetCookie();

Output:

    ["name1=value1", "name2=value2"]

## Fetch Headers - has(String name) {#ariaid-title9}

Returns a Boolean indicating whether a Headers object contains the given header.
{#fetch.headers-has_S__table_bvr_r3q_jdc__entry__3}

| Name | Type | Description |
|-|-|-|
| name | String | The name of the HTTP header to check whether it exists on the Headers object or not. |
[Table 14. Parameters]

{#fetch.headers-has_S__table_bvr_r3q_jdc} {#fetch.headers-has_S__table_cvr_r3q_jdc__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates whether the specified header exists in the Headers object. A TypeError is returned if the given header is not a valid HTTP header name. Possible values: * true: The header exists on the object. * false: The header doesn't exist on the object. {#fetch.headers-has_S__ul_om2_lkq_jdc} |
[Table 15. Returns]

{#fetch.headers-has_S__table_cvr_r3q_jdc}  
The following example uses the Headers() and append() methods to create and set a Headers object with the Content-Type header. The example then uses the has() method to show
that the Content-Type header exists on the Headers object but a Accept-Coding header does not.

    var myHeaders = new Headers(); // Currently empty
    myHeaders.append("Content-Type", "image/jpeg");
    myHeaders.has("Content-Type"); // Returns true
    myHeaders.has("Accept-Encoding"); // Returns false

Output:

    true
    false

## Fetch Headers - keys() {#ariaid-title10}

Returns an iterator allowing you to cycle through all keys contained in a Headers object.
Use the [Fetch Headers - values()](https://servicenow-prod.fluidtopics.net/QpYPN4iIPDFYc0lpxGykDQ#fetch.headers-values "Returns an iterator allowing you to cycle through all header values contained in the Headers object.") method to return all header keys.
{#fetch.headers-keys__table_hql_jmq_jdc__entry__3}

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

{#fetch.headers-keys__table_hql_jmq_jdc} {#fetch.headers-keys__table_iql_jmq_jdc__entry__2}

| Type | Description |
|-|-|
| Iterator | Returns an iterator, where header keys are represented as Strings. |
[Table 17. Returns]

{#fetch.headers-keys__table_iql_jmq_jdc}  
The following example shows how to create a Headers object with keys, and then use the keys() method to return a list of available headers.

    // Create a test Headers object
    var myHeaders = new Headers();
    myHeaders.append("Content-Type", "text/xml");
    myHeaders.append("Vary", "Accept-Language");

    // Display the keys
    for (var key of myHeaders.keys()) {
      console.log(key);
    }

Output:

    content-type
    vary

## Fetch Headers - set(String name, String value) {#ariaid-title11}

Updates a value of an existing header inside the Headers object, or creates a new header with the given value if the header does not already exist.
To simply append a new value to an existing header without overwriting any data, use the [Fetch Headers - append(String name, String value)](https://servicenow-prod.fluidtopics.net/QpYPN4iIPDFYc0lpxGykDQ#fetch.headers-append_S_S "Adds a new value to an existing header inside a Headers object, or adds the header if it does not already exist.") method.
{#fetch.headers-set_S_S__table_q1b_1nq_jdc__entry__3}

| Name | Type | Description |
|-|-|-|
| name | String | The name of the HTTP header in which to set a new value. Throws TypeError if the given name is not the name of an HTTP header. |
| value | String | The new value to set for the given header. |
[Table 18. Parameters]

{#fetch.headers-set_S_S__table_q1b_1nq_jdc} {#fetch.headers-set_S_S__table_r1b_1nq_jdc__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 19. Returns]

{#fetch.headers-set_S_S__table_r1b_1nq_jdc}  
The following example shows how to set a header in new Headers object using append(), and then reset the value using set().

    var myHeaders = new Headers(); // Currently empty
    myHeaders.append("Content-Type", "image/jpeg");
    myHeaders.set("Content-Type", "text/html");

Output:

    text/html

The following example shows how to set a value in a Headers object when it accepts multiple values:

    myHeaders.set("Accept-Encoding", "deflate");
    myHeaders.set("Accept-Encoding", "gzip");
    myHeaders.get("Accept-Encoding");

Output:

    gzip

## Fetch Headers - values() {#ariaid-title12}

Returns an iterator allowing you to cycle through all header values contained in the Headers object.
Use the [Fetch Headers - keys()](https://servicenow-prod.fluidtopics.net/QpYPN4iIPDFYc0lpxGykDQ#fetch.headers-keys "Returns an iterator allowing you to cycle through all keys contained in a Headers object.") method to return all header values.
{#fetch.headers-values__table_s1w_r4q_jdc__entry__3}

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

{#fetch.headers-values__table_s1w_r4q_jdc} {#fetch.headers-values__table_t1w_r4q_jdc__entry__2}

| Type | Description |
|-|-|
| String | Returns an iterator, where the header values are represented as strings. |
[Table 21. Returns]

{#fetch.headers-values__table_t1w_r4q_jdc}  
The following example shows how to fist create and set a new Headers object with multiple headers using the append() method, and then return a list of all header values in the new object by calling the
values() method. Console.log() logs the line to system logs.

    // Create a test Headers object
    var myHeaders = new Headers();
    myHeaders.append("Content-Type", "text/xml");
    myHeaders.append("Vary", "Accept-Language");

    // Display the values
    for (var value of myHeaders.values()) {
      console.log(value);
    }

Output:

    text/xml
    Accept-Language


