I need help creating a JavaScript script that can automatically move images from my Airtable database to WordPress. The goal is to download pictures from Airtable records and upload them to WordPress media library, then connect these images to the right posts that have empty image fields.
For instance, if I have a user profile for “Sarah Johnson” with an empty photo field, the script should grab her image from Airtable and populate that field in WordPress. I’m pretty new to programming and learning as I go, so any guidance would be awesome.
Here’s what I have so far for connecting to Airtable:
const airTable = new Airtable({ apiKey: 'YOUR_API_KEY' }).base('YOUR_BASE_ID');
const profileTable = airTable('PROFILES');
const fetchAllRecords = async() => {
const data = await profileTable.select({
maxRecords: 50,
view: "Export View"
}).firstPage();
console.log(data);
};
fetchAllRecords();
const fetchSingleRecord = async(recordId) => {
try {
const singleRecord = await profileTable.find(recordId);
console.log(singleRecord);
} catch (error) {
console.error(error);
}
};
fetchSingleRecord('rec123456');