Help

Re: Fetch data json get/post zipcodes

1836 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Ehud_Shamon
4 - Data Explorer
4 - Data Explorer

Hello,
I need help fetching data.
I’m new to airtable and also don’t have much experience in scripting but I do have some code experience.
I’m trying to fetch Zipcodes from https://www.zipcodeapi.com/API
I can use one of the two:

  1. GET, Zip codes by radius.
  2. POST, multi zip codes by radius.
    I did authorize the airtable domain https://www.zipcodeapi.com/ClientKeySetup to get js-key. as zipcodeapi suggested.

This is the code I have that use the GET method (yes I know):
// @ts-nocheck
let response = await fetch(‘https://www.zipcodeapi.com/rest/js-APIKEY/radius.json/59718/30/mile’)
console.log(await radius.json());

I get:
### ERROR
ReferenceError: radius is not defined
at main on line 3

I did tried to add method, headers… all kind of thigs but with no luck. I know I’m doing it wrong.

Any help please?
Thank you very much
Ehud

7 Replies 7

It doesn’t matter how good your code is - if the endpoint doesn’t resolve, the API call will fail.

image

The api key is missing from your code :slightly_smiling_face:
It work when I use it as http get and not as JS code (from integromat and from adalo and from postman). But the zip code api company say it is possible. So I think its a problem with my code.
As I understand in Airtable this is the only way to do that?

I don’t have ANY code - you need to share your code if you want to get precise answers.

I just saw that the APIKEY reference in my code wasn’t show because it was in a
I change that.
But still it wont work without the key in the url.
There are demo option in the link I shared

openside
10 - Mercury
10 - Mercury

the issue is you last line: console.log(await radius.json());

should be: console.log(await response.json());

Thank you, it is working now. I had one more problem that I needed to authorize airtableblocks.com also. not only airtable.com at the other side :slightly_smiling_face:

Ehud_Shamon
4 - Data Explorer
4 - Data Explorer

now I want to make the zipcode and the distance dynamic.
its the 59718
and the 30
I have webhook at Airtable that get those dynamic fields from user input at Adalo.
How do I make my code recive those dynamic parameters from the webhook?

Thanks :blush: