Skip to main content

Using the new fetch API in background scripts

Christopher Crockett

The fetch API was added to ServiceNow in the Yokohama release for use in background scripting and, indeed, this is reflected in the official docs:

💬
You can use the Fetch API in a background script and wherever you can make HTTP calls (like a REST endpoint).
- ServiceNow Zurich Documentation, September 2025

Unfortunately, the usage examples for how to use the API are (at time of writing) factually inaccurate. The examples given only work as-is within ES Modules and will fail if attempted under any other background scripting context.

Script execution error: Script Identifier: null.null.script, Error Description: "fetch" is not defined., Script ES Level: 200
Evaluator: com.glide.script.RhinoEcmaError: "fetch" is not defined.
   script : Line(1) column(0)
==>   1: fetch('google.com');
 Stack trace:
	at null.null.script:1 

The result of calling fetch('google.com') in a background script


Instead, the correct way to access fetch and associated APIs is as follows:

const FetchApis = require('servicenow:fetch');
const response = await FetchApis.fetch('google.com');
require is only available in scoped applications! This means you'll be unable to directly use fetch in the global scope.

It is possible to work around this issue by creating a Scoped App and Script Include (w/ Accessible From = "all application scopes") like so:
const MyScriptInclude = require('servicenow:fetch');

As far as we currently know, this is the only such case where APIs are gated behind the servicenow: prefix... though the creation of this new convention certainly implies more to eventually come.


We expect that the documentation will eventually be corrected to reflect the actual usage, since the current incarnation clearly implies an intent to support...

... For the time being, here's an unofficial list of what's in servicenow:fetch:

🤨
Yes, really... this is how we finally got a proper URL manipulation class.
As an undocumented export of an (accidentally) undocumented module.