Help

api call

Topic Labels: Data
790 2
cancel
Showing results for 
Search instead for 
Did you mean: 
bleauhaus
5 - Automation Enthusiast
5 - Automation Enthusiast

The following bit of code is intended for a Script block to pull data into airtable it was written by chatgpt 

I cant make this work for the life of me

 

async function updateRDAPData() {
    let table = base.getTable('Wucy'); // Correct table name
    let query = await table.selectRecordsAsync({
        fields: ['Value'] // This field contains the full RDAP URLs
    });

    for (const record of query.records) {
        let url = record.getCellValue('Value'); // Get the RDAP URL from the record
        if (!url) {
            console.log(`Skipping record ${record.id} because no URL is present.`);
            continue;
        }

        console.log(`Fetching RDAP data from URL: ${url}`);
        try {
            let response = await fetch(url);
            if (!response.ok) {
                console.error(`HTTP Error: Failed to fetch RDAP data from URL ${url}: ${response.status} ${response.statusText}`);
                continue;
            }
            let data = await response.json();

            // Extract necessary details from RDAP response
            let networkHandle = data.handle || "No network handle found";
            let networkName = data.name || "No network name found";
            let entityDetails = (data.entities && data.entities.length > 0) ? 
                data.entities.map(entity => `Handle: ${entity.handle}, Roles: ${entity.roles.join(', ')}`).join('\n') : 
                "No entities found";

            // Update Airtable records with the extracted data
            await table.updateRecordAsync(record.id, {
                'Network Handle': networkHandle, // Make sure these field names are correct
                'Name': networkName,             // and exist in your table
                'Entity Details': entityDetails  // Create this field if you need to store entity information
            });

        } catch (error) {
            console.error(`Error processing URL ${url} for record ${record.id}:`, error);
        }
    }

    console.log('RDAP data update completed.');
}

updateRDAPData();

 

2 Replies 2
jsep
7 - App Architect
7 - App Architect

If this is running in a script extension block, then fetch will not work, try to use remoteFetchAsyncBecause Scripting App scripts run directly in the user’s browser, fetch requests will be blocked by the browser if the target server doesn’t support Cross-Origin Resource Sharing (CORS).

 

 

async function updateRDAPData() {
    let table = base.getTable('Wucy'); // Correct table name
    let query = await table.selectRecordsAsync({
        fields: ['Value'] // This field contains the full RDAP URLs
    });

    for (const record of query.records) {
        let url = record.getCellValue('Value'); // Get the RDAP URL from the record
        if (!url) {
            console.log(`Skipping record ${record.id} because no URL is present.`);
            continue;
        }

        console.log(`Fetching RDAP data from URL: ${url}`);
        try {
            let response = await remoteFetchAsync(url); // change from fetch to remoteFetchAsync
            if (!response.ok) {
                console.error(`HTTP Error: Failed to fetch RDAP data from URL ${url}: ${response.status} ${response.statusText}`);
                continue;
            }
            let data = await response.json();

            // Extract necessary details from RDAP response
            let networkHandle = data.handle || "No network handle found";
            let networkName = data.name || "No network name found";
            let entityDetails = (data.entities && data.entities.length > 0) ? 
                data.entities.map(entity => `Handle: ${entity.handle}, Roles: ${entity.roles.join(', ')}`).join('\n') : 
                "No entities found";

            // Update Airtable records with the extracted data
            await table.updateRecordAsync(record.id, {
                'Network Handle': networkHandle, // Make sure these field names are correct
                'Name': networkName,             // and exist in your table
                'Entity Details': entityDetails  // Create this field if you need to store entity information
            });

        } catch (error) {
            console.error(`Error processing URL ${url} for record ${record.id}:`, error);
        }
    }

    console.log('RDAP data update completed.');
}

updateRDAPData();

 

 

If it is running inside an automation script block, then error might be something else.

I hope this helps! If you need assistance implementing this solution, feel free to schedule a free call with me.

- Juan, Code and No-Code Solutions Expert

bleauhaus
5 - Automation Enthusiast
5 - Automation Enthusiast

thanks for the reply ill look into this