Hey everyone! I need help creating a JavaScript automation that will grab images stored in Airtable, download them, and then upload them to my WordPress site’s media library. The tricky part is I also want these images to automatically fill in the empty custom image fields I have set up across different post types.
For instance, if I have a user profile for someone like John Smith with an empty avatar field, the script should find the matching image and populate that field automatically. I’m pretty new to programming and learning as I go, so any guidance would be amazing!
Here’s what I’ve got so far for connecting to Airtable:
I’ve done similar migrations before - the key is getting your matching logic right. Search for posts by title or slug to find the correct John Smith profile before updating the avatar field.
Make sure your WordPress site has REST API enabled and proper authentication set up. Application passwords work great for this.
I hit this exact problem migrating client data from Airtable to WordPress. The biggest gotcha? Handling duplicate images properly.
Always check if images already exist in your WordPress media library before uploading. Hash the content or match filenames - you don’t want to flood your library with duplicates:
For custom fields, figure out what plugin creates them first. ACF fields need the field key (field_123abc), not the name. Meta fields work differently.
Build a dry run mode first - I can’t stress this enough. Log everything without actually uploading or updating. Saves you from overwriting good data with garbage.
Airtable attachment URLs are temporary but stay valid for a while. Don’t store them for later - download and upload immediately in the same process.
WordPress REST API docs are solid once you get past authentication. Start with one record and scale up.
Did something similar last year moving from Airtable to WordPress. Here’s what I learned: First, add delays between API calls or you’ll hit rate limits on both sides. Found this out the hard way. For matching records, don’t search individually - it’s way too slow. Pull all your Airtable data first, then grab WordPress posts and build a lookup table. Match by name or unique IDs, whatever’s most reliable. Watch your image formats and sizes. WordPress is picky and you’ll probably need to validate or convert before uploading. I built in error handling for failed uploads and logged everything so I could track what worked. Custom fields are tricky - depends if you’re using ACF or native WordPress fields. ACF uses different meta key formats (usually with underscores). Definitely test with a small batch first. Trust me, debugging bulk operations when they break is a nightmare.
quick heads up - check your airtable attachment urls first since they expire. half my script randomly failed becuz of this. also, wordpress has upload size limits, so keep your images small or the api will silently reject them.
Authentication will be your biggest headache. WordPress REST API needs application passwords or JWT tokens for media uploads - basic auth won’t work (learned this the hard way after weeks of debugging). Enable application passwords in your WordPress admin under user profile settings first.
Your matching logic needs to be solid. I’d create a mapping table that stores Airtable record IDs with WordPress post IDs. This stops duplicate uploads and lets you resume if things break.
WordPress auto-creates multiple image sizes, so you’ll get several URLs back from the media endpoint. You’ll usually want the full size URL for custom fields. Run your script with verbose logging so you can see exactly where it fails during transfers.
Node.js makes this way easier than browser JavaScript. You’ll need the fs module for temp file storage during transfers. Download images from Airtable to local temp files first, then stream them to WordPress. Direct URL-to-URL transfers usually fail because of CORS and auth issues. For custom fields, figure out exactly what field type you’re dealing with. ACF image fields store attachment IDs differently than featured images or regular meta fields. Check your database to see how the empty fields are structured - some store arrays, others just single IDs. Error recovery is huge since transfers can fail halfway through. I built a simple CSV log tracking which records processed successfully so I could restart from failures without duplicating work. The WordPress media endpoint returns different response formats depending on upload success, so parse that carefully before using the attachment ID.