2

I'm working on an airtable automation that is putting in an address validation request to the USPS API. For some reason, when I try to fetch it times out. I've validated that the URL I'm testing on works just fine and provides a response, but no matter what I try, I cannot get this to work.

AFAIK, using Fetch is the only way I can access the XML response in airtable automations. I'm open to anything that gets me the data (I know that because it's an XML response I can't parse it immediately.)

Here's an example of a URL (with my ID marked out) that is failing:

let geo2 = await fetch( 'http://secure.shippingapis.com/ShippingAPI.dll?API=Verify&XML=<AddressValidateRequest%20USERID="00000000"><Address><Address1>null</Address1><Address2>7400%20Quebec Pl NW</Address2><City>Brooklyn</City><State>NY</State><Zip5>20202</Zip5><Zip4></Zip4></Address></AddressValidateRequest>').then(response => response.text())

I can't find any similar errors online, and have found code in other places (not airtable) that has worked. Any idea why this isn't working, and if there are alternatives that work in airtable? I can't use XMLhttpRequest as far as I can tell.

j_kathleen
  • 21
  • 1
  • Many APIs are not CORS enabled to let you use `fetch()` from browser? Have you confirmed the API you are using is enabled? – charlietfl Dec 04 '21 at 16:53
  • @charlietfl ohh good question: I assumed it was because I've seen people post google apps script lookups using it and I assume that also require CORS being enabled, but am not actually sure how to check? – j_kathleen Dec 04 '21 at 16:58
  • Do you have any info on what error fetch actually spits out? It might already be telling you about CORS? It usually makes it pretty clear if you are not allowed to. (Also `XMLHttpRequest` is basically the same thing and should be available in your browser as its part of the `window` so I don't see why you couldn't use that. Not that you should, fetch should cover all that and more) – somethinghere Dec 04 '21 at 17:03
  • Google app scripts don't run in browser, they run on a server and thus are not CORS restricted – charlietfl Dec 04 '21 at 17:05
  • ahh! i see ty!! this might indeed be my problem then, some googling makes it seem so. – j_kathleen Dec 04 '21 at 17:09

1 Answers1

0

I had issues when fetch didn't work, but remoteFetchAsync did. You can use remoteFetchAsync only in script, not in automation, but at least you will know what's the problem is.

gusev80
  • 11
  • 2