let settings = input.config({ title: "Restriction Checker by Seller Assistant", description: "This script will check all ASINs for their ability to be sold on your Amazon Seller Account. Get your [Seller Assistant API Key here](https://app.sellerassistant.app/settings/api-keys)", items: [ input.config.text("apiKey", { label: "Seller Assistant API key.", description: "The API key will be visible to everyone who can view this base.", }), input.config.table("table", { label: "Table" }), input.config.field("asinField", { parentTable: "table", label: "ASIN", }), input.config.field("restrictionField", { parentTable: "table", label: "Restriction field in which to store your restrictions", }), ], }); async function checkRestrictions(settings) { let table = settings.table; let records = await table.selectRecordsAsync(); let totalRecords = records.records.length; if (totalRecords === 0) { output.text("No records found. Exiting script."); return; } output.text(`Starting restriction check for ${totalRecords} records.`); let startTime = Date.now(); let rowCounter = 0; for (let record of records.records) { rowCounter++; let asin = record.getCellValue(settings.asinField); if (!asin) { output.text(`Skipping record ${rowCounter} (No ASIN found).`); continue; } output.text(`Checking ASIN: ${asin} (${rowCounter}/${totalRecords}) - ${((rowCounter / totalRecords) * 100).toFixed(2)}% done`); try { let response = await remoteFetchAsync(`https://app.sellerassistant.app/api/v1/products/${asin}/restriction-status`, { method: 'GET', redirect: 'follow', headers: { 'X-Api-Key': settings.apiKey, 'X-App-Name': 'airtable', 'Content-Type': 'application/json' } }); if (!response.ok) { throw new Error(`HTTP ${response.status} - ${response.statusText}`); } let data = await response.json(); let restrictionStatus = data?.status || 'No data available'; output.text(`ASIN: ${asin} | Restriction: ${restrictionStatus}`); await table.updateRecordAsync(record.id, { [settings.restrictionField.id]: restrictionStatus }); } catch (error) { output.text(`❌ Error for ASIN ${asin}: ${error.message}`); } } let elapsedTime = ((Date.now() - startTime) / 1000).toFixed(2); output.text(`✅ Completed restriction check for ${totalRecords} records in ${elapsedTime} seconds.`); } await checkRestrictions(settings);