Dec 14, 2022 08:42 AM
i will be as spesific as i can with the intention and infomation i'm gathering:
At a scheduled time, every day at 8am, i will run a script.
This script below here fetches the JSON i need. (example: https://data.brreg.no/enhetsregisteret/api/enheter?)
This is the output of the console.log so i know it works:
As you see, each object under the "enheter" array represents a company.
I want the automation to create records based on each object and fill it with the infomation given there.
Anyone willing to help me here? 😅
Solved! Go to Solution.
Dec 15, 2022 12:27 AM
Fixed it, looking through some documentation i figured out that each record field is declared as a item. All then that remained was to make a for loop counting the number of objects that arrived and push the looped value to the field value declared by Airtable in the background.
// ABOVE is the code for the API source and filters
// BELOW creates a dynamic API request based on a number of happenings within publicly released company data.
let = opportunityGenerator = apiSourceLink + apiFilterTroendelag + apiFilterEtablertIgaar + apiFilterOrganisasjonsform
//console.log(opportunityGenerator)
// AIRTABLE FETCH This one fetches the infomation from the dynamic API and declares "brregJson" as Json so i don't have to do it for every value in the ForLoop.
let brregRawData = await fetch(opportunityGenerator);
let brregJson = await brregRawData.json()
// For Loop that pushes the counted values from Airtable Fetch into the declared field values.
for (let i = 0; i < brregJson._embedded.enheter.length; i++) {
let organizationName = brregJson._embedded.enheter[i].navn
let organizationNumber = brregJson._embedded.enheter[i].organisasjonsnummer
let organizationType = brregJson._embedded.enheter[i].organisasjonsform.kode
console.log(brregJson._embedded.enheter[i]);
let createOpportunity = await opportunities.createRecordAsync({
'Opportunity Name': organizationName,
'Organization number': organizationNumber,
'Company Type': organizationType,
});
}
// AIRTABLE create record
I'm just a hobby JS user so there's probably much better ways to solve this issue but it works so i'm happy 😅
Dec 14, 2022 09:37 AM
After some digging in the documentation pages of Airtable i have managed to go one step further.
let createOpportunity = await opportunities.createRecordAsync({
'Opportunity Name': 'name',
'Organization number': 123456789,
'Company Type': "AS",
'Company Code': "01.001",
'Company Description': "Company Description",
'Foretaksregistret': "JA",
'Website': "test.no",
});
I only now need to be able to input the correct values from the JSON into the values i have created above...
Dec 15, 2022 12:27 AM
Fixed it, looking through some documentation i figured out that each record field is declared as a item. All then that remained was to make a for loop counting the number of objects that arrived and push the looped value to the field value declared by Airtable in the background.
// ABOVE is the code for the API source and filters
// BELOW creates a dynamic API request based on a number of happenings within publicly released company data.
let = opportunityGenerator = apiSourceLink + apiFilterTroendelag + apiFilterEtablertIgaar + apiFilterOrganisasjonsform
//console.log(opportunityGenerator)
// AIRTABLE FETCH This one fetches the infomation from the dynamic API and declares "brregJson" as Json so i don't have to do it for every value in the ForLoop.
let brregRawData = await fetch(opportunityGenerator);
let brregJson = await brregRawData.json()
// For Loop that pushes the counted values from Airtable Fetch into the declared field values.
for (let i = 0; i < brregJson._embedded.enheter.length; i++) {
let organizationName = brregJson._embedded.enheter[i].navn
let organizationNumber = brregJson._embedded.enheter[i].organisasjonsnummer
let organizationType = brregJson._embedded.enheter[i].organisasjonsform.kode
console.log(brregJson._embedded.enheter[i]);
let createOpportunity = await opportunities.createRecordAsync({
'Opportunity Name': organizationName,
'Organization number': organizationNumber,
'Company Type': organizationType,
});
}
// AIRTABLE create record
I'm just a hobby JS user so there's probably much better ways to solve this issue but it works so i'm happy 😅
Jun 05, 2023 08:32 PM
What I was looking for! How would you do a search on the data from the fetch before you send the data to the table, For example I already have the initial incident in the table. I only want to send new incidents to the table (every fetch grabs everything and new incidents each time). Nice work!