Airtable script for posting to twitter and linkedin with ayrshare
const API_KEY = "Your API KEy";
// Change this name to use a different table
let table = base.getTable("Content");
// Prompt the user to pick a record
// If this script is run from a button field, this will use the button's record instead.
let record = await input.recordAsync('Select a record to use', table);
if (record) {
await fetch("<https://app.ayrshare.com/api/post>", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${API_KEY}`
},
body: JSON.stringify({
post: record.getCellValue("Post Content") + " " + record.getCellValue("Link"), // required
platforms: ["twitter", "linkedin"], // required
mediaUrls: [record.getCellValue("image url")], //optional
}),
})
.then((res) => res.json())
.then((json) => {
const id = record?.id
function updatePost (id){
table.updateRecordAsync(id, {
Posted: true,
})
}
if (json.status === "success"){
updatePost(id);
}
console.log(json)})
.catch(console.error);
} else {
output.text('No record was selected');
}