Help

Calendarific and airtable

Topic Labels: Scripting extentions
109 0
cancel
Showing results for 
Search instead for 
Did you mean: 

Hi all, i am trying to build a table for holidays via caledarific API.

this is the part of response from json

{
“meta”: {
“code”: 200
},
“response”: {
“holidays”: [
{
“name”: “New Year’s Day”,
“description”: “New Year’s Day is the first day of the year, or January 1, in the Gregorian calendar.”,
“country”: {
“id”: “es”,
“name”: “Spain”
},
“date”: {
“iso”: “2022-01-01”,
“datetime”: {
“year”: 2022,
“month”: 1,
“day”: 1
}
},
“type”: [
“National holiday”
],
“urlid”: “spain/new-year-day”,
“locations”: “All”,
“states”: “All”
},
{
“name”: “Reconquest Day”,
“description”: “Reconquest Day is a provincial holiday in Spain”,
“country”: {
“id”: “es”,
“name”: “Spain”
},
“date”: {
“iso”: “2022-01-02”,
“datetime”: {
“year”: 2022,
“month”: 1,
“day”: 2
}
},
“type”: [
“Local holiday”
],
“urlid”: “spain/reconquest-day”,
“locations”: “GR”,
“states”: [
{
“id”: 324,
“abbrev”: “GR”,
“name”: “Granada”,
“exception”: null,
“iso”: “es-gr”
}
]
},

So , i am trying to fetch data in a “Vaciones table” without success.

This is my script

let apiResponse = await fetch(‘https://calendarific.com/api/v2/holidays?&api_key=XXXXXXXx&country=ES&year=2022’);
let data = await apiResponse.json();
console.log(data)
let vacacionesT = base.getTable(‘Vacaciones’);

for (let post of data) {
output.text(Creando registro vacaciones ${post.name})
await vacacionesT.createRecordAsync({
‘name’: post.name,
‘descripcion’: post.description,
‘country name’: post.country.name,
‘date iso’: post.date.iso,
‘estado’: post.states.name
})
}
but it says

“TypeError: data is not iterable
at main on line 6”

i am not very familiar with JS, I build this following REST APIs and Airtable (APIs Part 1) | Airscript

but it is obvious that something is not ok.

May anybody help me with this script?

Thanks,

0 Replies 0