Fetch
Your script can make network requests to external services using the fetch API.
function
async function (url: string | Request, init?: object) => Promise<Response>;
Complete documentation for fetch is available on MDN.
fetch
is an asynchronous function: you must add await
before each call to this function.
Browser Fetch Scripting Extension only
Scripting Extension only
The scripting extension can use the browser-native implementation of fetch
.
Examples
Making a GET request to a JSON API:
Example
let response = await fetch('https://api.github.com/orgs/Airtable');console.log(await response.json());
Making a post request:
Example
let response = await fetch('https://www.example.com/sendMessage', {method: 'POST', body: 'Hi there'});console.log(await response.text());
Making a post request to a JSON API:
Example
let response = await fetch('https://www.example.com/sendJSONMessage', {method: 'POST',body: JSON.stringify('Hi there'),headers: {'Content-Type': 'application/json',},});console.log(await response.json());
fetch Automations only
Automations only
Scripting actions can use fetch
, however since it doesn't run in the browser you should be mindful of the differences listed below.
remoteFetchAsync Scripting Extension only
Scripting Extension only
If using fetch
normally doesn't work, you can try replacing it with remoteFetchAsync
. remoteFetchAsync
makes the request from Airtable's servers instead of your browser. This is useful if the API has CORS restrictions as these don't apply outside of the browser.
function
remoteFetchAsync(url: string | Request, init?: object) => Promise<RemoteResponse>
Differences from fetch in the browser
- The
referrer
andreferrerPolicy
options are not respected. AReferer
header is never set. - The
follow
redirect mode is not supported. Onlyerror
andmanual
are supported. Asmanual
returns an 'opaque' response in order to respect atomic HTTP redirect handling, it's effectively impossible to follow redirects at present. - Streaming responses and requests are not supported. The APIs exist and work as expected, but buffer under the hood.
- Caching is not supported. Cache modes can be set, but always behave like
reload
. - Cookies are not supported. The
credentials
options can be set, but always behaves likeomit
. - Different request modes are not supported. They can be set, but none will quite behave as expected. The closest mode in the standard is
same-origin
, except that requests can be made to any origin. - Subresource integrity is not validated. The integrity metadata property can be set, but is ignored.
- The
FormData
API for request/response bodies is not supported. - The response payload has a size limit of 4.5 MB.