
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jan 21, 2021 09:37 AM
hello everyone, sorry if my english is not very good, i will try to explain my problem to you.
I would like to retrieve the longitude and latitude through a script on airtable using an api but i dont know how to do it, can you help me please i am really stuck.
thank you

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jan 21, 2021 11:50 AM
Hi @Tarik_TALEB, and welcome to the community!
Well, start with a function that makes the API call like this:
//
// post data
//
async function postData(url = '', data = {})
{
const response = await fetch(url, {
method: 'GET'
});
return response.json();
}
Call it with something like this:
await postData(apiEndpoint)
.then(data => {
...
}
.err {
...
});
Make sense?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jan 22, 2021 12:23 AM
my api returns this :
{
“ip”:“109.9.171.148”,
“type”:“ipv4”,
“continent_code”:“EU”,
“continent_name”:“Europe”,
“country_code”:“FR”,
“country_name”:“France”,
“region_code”:“IDF”,
“region_name”:"\u00cele-de-France",
“city”:“Champs-sur-Marne”,
“zip”:“77420”,
“latitude”:48.852149963378906,
“longitude”:2.6002299785614014,
“location”:{
“geoname_id”:3027014,
“capital”:“Paris”,
“languages”:[
{
“code”:“fr”,
“name”:“French”,
“native”:“Fran\u00e7ais”
}
],
“country_flag”:“http://assets.ipapi.com/flags/fr.svg”,
“country_flag_emoji”:"\ud83c\uddeb\ud83c\uddf7",
“country_flag_emoji_unicode”:“U+1F1EB U+1F1F7”,
“calling_code”:“33”,
“is_eu”:true
}
}
if i understood i need to use the api to retrieve the data, then i put it in my form, knowing that i need the latitude and longitude.
example :
url_api : http://api.ipapi.com/109.9.171.148?access_key=76454ca6de838ca36eb63f1c72130&format=1
the code :
//
// post data
//
async function postData(url = url_api , data = {})
{
const response = await fetch(url, {
method: ‘GET’
});
return response.json();
}
afterwards I don’t know what to put in data, what do I put the values I want to retrieve or all the values that the API returns.
Thank you for your reply

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jan 22, 2021 02:47 AM
Recap – the script that calls the API looks like this…
await postData(apiEndpoint)
.then(data => {
...
}
.err {
...
});
The variable “data” will contain the JSON payload returned by the API. So, accessing lat/lng from your sample response payload would look something like this:
await postData(apiEndpoint)
.then(data => {
let lat = data.latitude;
let lng = data.longitude;
}
.err {
...
});

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jan 22, 2021 03:48 AM
I just tested the code, I have an error:
ERROR
TypeError: Failed to fetch
at Failed to fetch
I saw that you have already answered this problem, I have the impression that it is a recurring problem.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jan 22, 2021 04:36 AM
How so? What problem, exactly, are you referring?
A failed fetch means that your code is simply not working. You have a bug somewhere, but unless you can share it, I cannot be of much assistance.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jan 25, 2021 01:27 AM
Hello, excuse me for the delay in responding.
I give you the screens of a very simple code for the recovery of the json from the API.
This is what the API returns to me:
This is what the airtble script returns to me (in the script I only display the json)
thank you

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jan 25, 2021 06:59 AM
And how [exactly] are you able to see that response? Performing a GET from a browser using this URL?
http://api.ipapi.com/109.9.181.118?access_key=76454ca6de838ca36eb4c963f1c72130&format=1
If so, you cannot expect this to run in a script in Airtable (or any system for that matter) because the service level you’ve signed up for at ipapi.com doesn’t provide HTTPS, a key security requirement for anyone engaged in API integration via Airtable.
Until such time as you enable HTTPS on that account, you will spin your wheels attempting to make this work.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jan 26, 2021 12:25 AM
Thank you for your help, i just understood i will try to find a more secure api.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jan 26, 2021 04:08 AM
It’s not a question of finding a more secure API - you have found one. You simply need to upgrade the service.
