Awesome, thank you for the love and glad you got it working.
If anyone wants to see how this would look via CMS API, here’s a script I have running in an Airtable scripting block, which allows me to create collections as “tabs” in a base, then lookup the corresponding CMS Webflow ID field.
In this example, I am referencing multiple tables in an airbase, and updating (or creating new entries) for agency “services” that have various “category” or similar reference ID’s.
// pick tables from your base here
let table = base.getTable('Services');
// pick a view from your base here
let view = table.getView('Editor View');
// get records in order
let result = await view.selectRecordsAsync();
// define a delay function for a rate limit, ignore red squiggly, if you're using Airtable to manage CMS for Webflow this will prevent any rate limit errors.
function timeout(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
for (let record of result.records) {
await timeout(1000); // 1 sec pause for Webflow's Rate Limit
// check for Webflow IDs (Use any field where you keep webflow IDs)
let originalValue = record.getCellValue('Webflow ID');
// set your Webflow headers
let myHeaders = new Headers();
myHeaders.append('accept-version', '1.0.0');
myHeaders.append('Authorization', 'Bearer [YOUR WEBFLOW API KEY]');
myHeaders.append('Content-Type', 'application/json');
// match your fields to the values you want updated
let webflowRequest = JSON.stringify({
fields: {
name: record.getCellValue('Name of Service'),
slug: record.getCellValue('Slug'),
'service-feature-image': record.getCellValue('Featured Image'), // you can reference images directly from the attachment field of an Airtable record, which is nice.
'main-category': record.getCellValue('Category ID'), // this is a reference field, the value would be a Webflow ID like 5qq439bc083e9a72d6067cd9
'seo-meta-description': record.getCellValue('SEO Description'), // text field
'airtable-id': record.getCellValue('Airtable ID'), // I put Airtable ID's in my Webflow CMS and Webflow ID's in my Airtable base, go figure. Hehe.
'vimeo-preferred': record.getCellValue('Video URL'), // url field
'main-service-article': record.getCellValue('Main Article ID'), // as an example, this references another base that has a Webflow ID for the article, eg, 5ff439bc083e9a054c067cf2
'logo-description': record.getCellValue('Long Description'), // text field
'light-logo': record.getCellValue('SVG Icon') // example of a conditional field, which only runs if the cell called 'SVG Icon' is populated.
? record.getCellValue('SVG Icon')[0].url
: null,
'step-1-image': record.getCellValue('Step 1 Image') // see above
? record.getCellValue('Step 1 Image')[0].url
: null,
'step-2-image': record.getCellValue('Step 2 Image') // see above
? record.getCellValue('Step 2 Image')[0].url
: null,
'step-3-image': record.getCellValue('Step 3 Image') // see above
? record.getCellValue('Step 3 Image')[0].url
: null,
_draft: false, // required for webflow
_archived: false, // required for webflow
},
});
console.log(webflowRequest);
// check if there's no Webflow ID, and set POST as the method
if (!originalValue) {
let postOptions = {
method: 'POST',
headers: myHeaders,
body: webflowRequest,
redirect: 'follow',
};
let postResults = await fetch(
'https://cors-anywhere.herokuapp.com/https://api.webflow.com/collections/{YOUR COLLECTION ID}/items/?live=true', // Note the '?live=true' parameter. This is optional. Also, note the first half of the url. I use CORS Anywhere because this Airtable base has only a few items. If you have over 200 to update within an hour, I recommend running Airtable scripts from Chrome with a CORS disabler Browser Extension.
postOptions,
);
const postJSON = await postResults.json();
console.log(postJSON);
let newID = postJSON._id;
await table.updateRecordAsync(record, {
'Webflow ID': newID,
});
//you don't need this following block, but if you want to output your updated data in as markdown in the console, then use this:
let value = record.getCellValueAsString('Name of Service');
let seodesc = record.getCellValueAsString('SEO Description');
output.markdown(`##### Updated ${value}.`);
output.markdown(`SEO Description: ${seodesc}`);
}
// check if there is a Webflow ID, and set PUT as the method
if (originalValue) {
let putOptions = {
method: 'PUT',
headers: myHeaders,
body: webflowRequest,
redirect: 'follow',
};
let putResults = await fetch(
'https://cors-anywhere.herokuapp.com/https://api.webflow.com/collections/[YOUR COLLECTION ID]/items/' +
originalValue +
'?live=true',
putOptions,
);
const putJSON = await putResults.json();
console.log(putJSON);
//you don't need this, but if you want to output your updated data in markdown, use this:
let value = record.getCellValueAsString('Name of Service');
let seodesc = record.getCellValueAsString('SEO Description');
output.markdown(`##### Updated ${value}.`);
output.markdown(`SEO Description: ${seodesc}`);
}
}
Here’s an example of how that may look: