Advanced Guide
While running your first Hello World on Scriptable can already be pretty exciting, you'll likely want to allow scripts to do a bit more advanced, like talking to another service via HTTP(S).
By default, your script will only have access to the standard JavaScript functionality, without any access to any Web or Node.JS specific APIs.
In this brief guide, you'll quickly learn how to extend what your scripts can do, including how to:
- Make Outbound HTTP requests using our custom, configurable fetch() implementation
- Add your own client and more to the script's global context
- Allow pre-authenticated HTTP calls without having to expose your access tokens directly to scripts of course
Outbound HTTP requests via fetch()
By default, your script will only have access to the standard JavaScript functionality, without access to any Web or Node.JS-specific APIs.
The only non-standard JavaScript object your script will have access to is our custom fetch() implementation, which generally follows the Fetch API specification but allows for a little more control regarding domain allow-listing and domain -> credential mapping.
By default, scripts can use fetch() to talk to any HTTP endpoints.
Extending your script's global context
To make it easier for users to access your own or other product's APIs, you'll likely want to inject a pre-configured client into the global scope of your script's global context.
As you might have noticed, you can also provide some static data to your script's global context, simply by setting the property global on your request options.
Configure pre-authenticated HTTP calls for specific domains
On top of providing your own custom client or helper functions to your script's global context, you can also make requests to be "magically" authenticated without risking the authentication token being extracted by a malicious script.
Here's the above example, but with extra fetchCredentials configured for api.jsonbin.io.