I have a script that makes a request to a GIS API and fetches the response. When the script is in an app, it works at expected. As an automation, it does not work. The fetch returns a response with 403 status. This is strange because this means access is forbidden, however it was not forbidden when this script was an app.
Here is what I have in the automation script:
const geocode_data = { "SingleLine": addressText,
"f": "json",
"outSR": {"wkid":102100,"latestWkid":3857},
"outFields":"*",
"distance": 50000,
"location" : {"x": -8396932.14535, "y": 4854564.864250004, "spatialReference":{"wkid":102100}},
"maxLocations": 2};
const geocode_req = new Request(
"https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates",
{
method: "POST",
body: geocode_data,
},
)
// This returns 403 forbidden
const geocode_res = await fetch(geocode_req);
I know there are differences between fetch() in apps vs automations, but from the documentation it seems like I can use fetch() like this. Is my geocode_data incorrectly formatted? In the app version, I use a FormData object for geocode_data, but I know that is not supported in automations. I referenced this page Airtable Scripting, which is a little unclear so I’m looking for more help!
Thanks!