Save the date! Join us on October 16 for our Product Ops launch event. Register here.
Jan 20, 2021 02:28 PM
Hi Guys,
Wondering if anyone can help me out with this one.
I want to create a script that incorporates an API to weather.com. The script will draw the information from the field and the field in Airtable and the result will be the weather forecast for that location on that day into a field called in Airtable.
Im pretty new to all this, so the most descriptive information would be really appreciated!
Thanks guys!
JH.
Jan 25, 2021 09:13 PM
Hello James,
Not sure about weather.com but if you are familiar with openweathermap.org, I have a script that can get their data.
First, head here to to get an api key.
let table = base.getTable('weather_data');
// NAME YOUR TABLE YOU WANT THE DATA TO GO TO WITH WHAT IS IN THE SINGLE QUOTES
let url = await fetch('https://api.openweathermap.org/data/2.5/weather?id=5392323&appid=YOURAPICODEHERE&units=imperial');
let json = await url.json();
//Name your columns 'weather.id', 'main.temp', the strings in the double quotes
//Loop over the json object (key/value pairs)
recordId = await table.createRecordAsync({
"weather.id": json.weather[0].id,
"weather.main": json.weather[0].main,
"weather.description": json.weather[0].description,
"weather.icon": json.weather[0].icon,
"main.temp": json.main.temp,
"main.feels_like": json.main.feels_like,
"main.pressure": json.main.pressure,
"main.humidity": json.main.humidity,
"main.temp_min": json.main.temp_min,
"main.temp_max": json.main.temp_max,
"wind.speed": json.wind.speed,
"wind.deg": json.wind.deg,
"wind.gust": json.wind.gust,
"visibility": json.visibility,
"clouds.all":json.clouds.all,
"dt": json.dt,
"sys.sunset": json.sys.sunset,
"sys.sunrise": json.sys.sunrise,
"timezone": json.timezone,
"id":json.id
})
A few things to note…
Good luck, If you run into problems let me know. I could share my base that you could copy if needed as well.
Aug 19, 2022 02:55 AM
Hi Garret,
I know this thread is sleeping since a year. But. I’m trying to pull weather data from openweather, somehow keep running in to problems.
You think you could share your base so I could copy it?
cheers and regards,
Jan
Aug 19, 2022 03:56 AM
Hi Jan.
Peter from Feature Power is my Airtable integrator. We have the weather input working smoothly with our base. I’ve cced in Peter. I’ll leave it to you guys to discuss some options. Thabks.
Aug 19, 2022 04:15 AM
Make.com supports pulling in OpenWeatherMap’s weather data very easily, with no coding & no scripts necessary:
Alternatively, if you want to avoid scripting but keep everything in Airtable, you could also use DataFetcher.com, but that requires technical knowledge of making API calls.
If you have a budget to hire an expert Airtable consultant to help you with any of this, please feel free to contact me through my website: Airtable consulting — ScottWorld
Aug 21, 2022 10:15 PM
Hi there Jan, here is the script that James and I are using. It uses weathereapi from weather.com, and is driven by a formula and script automation in Airtable. The script writes the formatted weather forecast back into the triggering record in Airtable and decrements a countdown in that same record. The countdown supports our particular needs for triggering the app/script and might not be relevant to you.
Formula for APIcall:
IF(
AND(Location,Day),
'https://api.weatherapi.com/v1/forecast.json?key=ae7ea9e2aeda4d2b9e405129212201&q='&{Location} & '&dt=' & DATETIME_FORMAT(SET_TIMEZONE(Day,'Australia/Melbourne'),'YYYY-MM-DD')
)
Script:
let trigger = input.config();
let forecastAPIcall = trigger.APIcall;
let recordid = trigger.id;
let counter = trigger.countdown;
let table = base.getTable('Hire Days');
let apiResponse = await fetch(forecastAPIcall);
let jsonResponse = await apiResponse.json();
counter -= 1;
let forecast = new String (
`forecast for date: `+jsonResponse.forecast.forecastday[0].date+
`\nmax temp: `+jsonResponse.forecast.forecastday[0].day.maxtemp_c+
`\nmin temp: `+jsonResponse.forecast.forecastday[0].day.mintemp_c+
`\nchance of rain%: `+jsonResponse.forecast.forecastday[0].day.daily_chance_of_rain+
`\nconditions: `+jsonResponse.forecast.forecastday[0].day.condition.text+
`\nmax wind (kmph): `+jsonResponse.forecast.forecastday[0].day.maxwind_kph
)
await table.updateRecordAsync(recordid, {
"Forecast": forecast.substr(0,forecast.length),
".ping counter": counter
})
Oct 25, 2022 03:01 AM
To add to Scott’s Data Fetcher recommendation, there is now an easy no-code way to look up the weather forecast in Airtable using Data Fetcher.
Oct 25, 2022 03:28 AM
Very cool, @Andy_Cloke! :cowboy_hat_face: :raised_hands:
May 15, 2023 08:11 AM - edited May 15, 2023 08:11 AM
Sure thing, mate! So you want to pull in a weather API using a script? No worries, I got you covered, even if this thread is 2 years old! First things first, check out this awesome link I found for you: https://www.worldweatheronline.com/weather-api/. It's a great resource to get started with incorporating weather data into your script. Now, let's break it down. You mentioned using Airtable, right? Well, you'll need to use the field in Airtable to grab the location you want the weather forecast for. Then, you'll make a call to the weather.com API to fetch the forecast data for that specific location on that day.
May 15, 2023 08:54 AM
Sure thing, mate! So you want to pull in a weather API using a script? No worries, I got you covered, even if this thread is 2 years old! First things first, check out this awesome link I found for you: https://www.worldweatheronline.com/weather-api/. It's a great resource to get started with incorporating weather data into your script. Now, let's break it down. You mentioned using Airtable, right? Well, you'll need to use the field in Airtable to grab the location you want the weather forecast for. Then, you'll make a call to the weather.com API to fetch the forecast data for that specific location on that day.