Fetch - Scoped, Global

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

The Fetch API provides methods for fetching resources using request and response objects.

You can use the Fetch API in a background script and wherever you can make HTTP calls (like a REST endpoint). The Fetch API allows you to make both simple and more complicated fetch requests by setting headers, body options, and so on.

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:

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.

Parent Topic:Server API reference

Fetch - fetch(String resource, Object options)

Starts the process of fetching a resource from the network and returns a promise that is fulfilled once the response is available.

Name

Type

Description

resource

String or Object

Required. The resource to fetch. Accepted values:

  • A string or an object with a stringifier, including a URL object, that provides the URL of the resource you want to fetch. The URL may be relative to the base URL which is the document's baseURI.
  • A Fetch Request - Request() object.

options

Object

Optional. A Fetch RequestInit - Scoped, Global object containing custom settings to apply to the request.Default: The request is passed without any customization settings.

Type

Description

Object

A promise that resolves to a response object.A fetch() promise only rejects when the request fails, for example, because of a badly-formed request URL or a network error.

Note: A fetch() promise is not considered as rejected if the server responds with HTTP status codes that indicate errors like 404 or 504. In this instance, use a then() handler to check the ok and status Fetch Response - Scoped,Globalproperties.

The following example demonstrates how to form a new Request object using [Fetch Request - Request\(\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/brazil/markdown/api-reference/server-api-reference/Fetch.RequestAPI.md) and then fetch\(\) to retrieve its data. Here is a simple explanation of how each part of the code is used:
JavaScript
async function fetchIncidents() {    const url = 'https://your-instance.service-now.com/api/now/table/incident';    const username = 'your_username';    const password = 'your_password';
    // Create a Request object    const request = new Request(url, {        method: 'GET',        headers: {            'Content-Type': 'application/json',            Authorization: 'Basic ' + btoa(`${username}:${password}`)        }    });
    // Fetch data and use response.json() to process it    const response = await fetch(request);    const data = await response.json(); // Parse the response to JSON    console.log(data.result); // Log the incidents data to system logs}
fetchIncidents();

Output:

JSON
[    { "number": "INC0001", "short_description": "System outage" },    { "number": "INC0002", "short_description": "Password reset request" }]
Search documentation
Search document titles and file paths on the brazil branch