Help

How do i make records based on fetched json?

Topic Labels: automation json
Solved
Jump to Solution
3561 3
cancel
Showing results for 
Search instead for 
Did you mean: 
Ruben_Rossvold
6 - Interface Innovator
6 - Interface Innovator

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.

Ruben_Rossvold_0-1671035519527.png

This script below here fetches the JSON i need. (example: https://data.brreg.no/enhetsregisteret/api/enheter?)

Ruben_Rossvold_1-1671035600685.png

This is the output of the console.log so i know it works:

Ruben_Rossvold_2-1671035646110.png

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? 😅

1 Solution

Accepted Solutions

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 😅

See Solution in Thread

3 Replies 3
Ruben_Rossvold
6 - Interface Innovator
6 - Interface Innovator

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...

Ruben_Rossvold_0-1671039262584.png

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 😅

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!