Skip to content

Instantly share code, notes, and snippets.

@rileyrichter
Created November 27, 2023 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rileyrichter/259dc65c396e069dc73a81227278de8e to your computer and use it in GitHub Desktop.
Save rileyrichter/259dc65c396e069dc73a81227278de8e to your computer and use it in GitHub Desktop.
Airtable to Webflow
/*
Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
const config = input.config({
title: "Script Settings",
items: [
input.config.text("webflowAPI", {
label: "Webflow API Key",
}),
input.config.text("collectionID", {
label: "Collection ID",
}),
],
});
let table = base.getTable("All Team");
let query = await table.selectRecordsAsync();
let records = query.records;
for (let record of records) {
let body = {
fields: {
_archived: false,
_draft: false,
"e-mail": record.getCellValue("Email"),
name: record.getCellValue("Name"),
"alt-text": record.getCellValue("Alt Text"),
title: record.getCellValue("Title").name,
photo: record.getCellValue("Image"),
},
};
let updateBody = {
fields: {
name: record.getCellValue("Name"),
slug: record.getCellValue("Slug"),
_archived: false,
_draft: false,
"e-mail": record.getCellValue("Email"),
"alt-text": record.getCellValue("Alt Text"),
title: record.getCellValue("Title").name,
photo: record.getCellValue("Image"),
},
};
if (record.getCellValue("Status").name === "New") {
let response = await remoteFetchAsync(
`https://api.webflow.com/collections/${config.collectionID}/items?live=true`,
{
method: "POST",
body: JSON.stringify(body),
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${config.webflowAPI}`,
"accept-version": "1.0.0",
},
}
);
let webflowResponse = await response.json();
console.log(webflowResponse);
console.log(response);
table.updateRecordAsync(record, {
"Item ID": webflowResponse._id,
"Slug": webflowResponse.slug,
"Status": {name: "Live"}
});
} else if (record.getCellValue("Status").name === "Update") {
let webflowID = record.getCellValue("Item ID");
let response = await remoteFetchAsync(
`https://api.webflow.com/collections/${config.collectionID}/items/${webflowID}?live=true`,
{
method: "PUT",
body: JSON.stringify(updateBody),
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${config.webflowAPI}`,
"accept-version": "1.0.0",
},
}
);
let webflowResponse = await response.json();
console.log(webflowResponse);
console.log(response);
table.updateRecordAsync(record, {
"Status": {name: "Live"}
});
} else if (record.getCellValue("Status").name === "Remove") {
let webflowID = record.getCellValue("Item ID");
let response = await remoteFetchAsync(
`https://api.webflow.com/collections/${config.collectionID}/items/${webflowID}?live=true`,
{
method: "DELETE",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${config.webflowAPI}`,
"accept-version": "1.0.0",
},
}
);
let webflowResponse = await response.json();
console.log(webflowResponse);
console.log(response);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment