> ## Documentation Index
> Fetch the complete documentation index at: https://www.ayrshare.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Airtable

> Manage your users' social media accounts from Airtable

## Overview

[Airtable](https://www.airtable.com) is a versatile cloud-based platform that seamlessly blends the structure of a spreadsheet with the robust capabilities of a database.

By integrating Airtable's automation scripts - written in JavaScript - with Ayrshare's API, you can streamline your social media management directly within Airtable. This integration empowers you to post content, analyze performance metrics, and manage comments on behalf of your users, all from one centralized location.

In this guide, we'll walk you through the steps to set up the integration.

## Set Up

<Warning>
  Running Airtable Automation Scripts requires a [paid](https://airtable.com/pricing) Airtable plan.
  Please be sure your Airtable plan includes automations with scripts.
</Warning>

This guide shows you how to automatically post to linked social media accounts in Airtable via [Ayrshare](https://www.ayrshare.com).
You can post to a single company's social accounts or to your managed client's social media accounts. All the below code can be found at [GitHub](https://github.com/ayrshare/airtable-post-social-media/blob/main/script.js).

<Card horizontal icon="github" href="https://github.com/ayrshare/airtable-post-social-media/blob/main/script.js" title="GitHub: Airtable Post Social Media" />

## Gather Your API Key

Start by getting your free or paid plan API Key in [Ayrshare Dashboard](https://www.ayrshare.com). The key will be used in the script below.

If you are on the Ayrshare [business plan](https://www.ayrshare.com/business-plan-for-multiple-users/) and want to post on behalf of your clients, gather all your client's Profile Keys either via the /user or /create-profile endpoints or in the Ayrshare Dashboard.

<Tip>
  Be sure you have linked a few social accounts in Ayrshare. Please verify in [Ayrshare Social
  Linking page](https://app.ayrshare.com/social-accounts).
</Tip>

## Create an Airtable Workspace

In [Airtable](https://www.airtable.com), create a new workspace with the fields. Please be sure to name cell columns as below:

<ul class="custom-bullets">
  <li>`Post` as Long Text</li>

  <li>
    `Platforms` as Multi Select with types: facebook, instagram, twitter, linkedin, reddit, and
    telegram
  </li>

  <li>`Images` as Attachment</li>
  <li>`Profile Keys` as Single Line Text</li>
  <li>`Status` as Single Line Text.</li>
  <li>`Schedule Date` as Date with Local Format, Include Time Field, and Time Format 24 Hours</li>
</ul>

<img class="center" src="https://mintcdn.com/ayrshare-docs/6mPR4kmwNEz1kMbX/images/packages-guides/airtable-example.webp?fit=max&auto=format&n=6mPR4kmwNEz1kMbX&q=85&s=ac8b91e08f67f7c2432ddfbbf7e65aa0" alt="Airtable Table Example" width="1536" height="161" data-path="images/packages-guides/airtable-example.webp" />

These fields will be used in the Airtable automation script we are about to build.

See a [live Airtable example](https://airtable.com/shrCWY0oA1ghB42tI/tblpnTEiPwyuViqBo).

<Card horizontal icon="book-open" href="https://airtable.com/shrCWY0oA1ghB42tI/tblpnTEiPwyuViqBo" title="Airtable Social Media Example">
  See a live Airtable example
</Card>

## Enter in Test Post Data

We need some sample data to test the post. Here is a suggestion:

<ul class="custom-bullets">
  <li>`Post`: Enter *Happy New Year 2025* </li>

  <li>
    `Platforms`: select one or more networks you have linked. Please be sure the name is lowercase.
  </li>

  <li>
    `Images`: Attach an image. We like this one you can download and attach:
    [https://img.ayrshare.com/012/gb.jpg](https://img.ayrshare.com/012/gb.jpg)
  </li>

  <li>
    `Profile Keys`: If you are on the Business Plan and want to post to a client's profile, enter
    their Profile Key. *Otherwise, leave blank.*
  </li>

  <li>
    `Status`: Enter *pending*. The script only grabs records that are set to pending. Please be
    sure "`pending` is lowercase.
  </li>

  <li>
    `Schedule Date`: Leave blank since we'll just test immediate posting right now. Later you can
    select a future date to schedule the post.
  </li>
</ul>

## Build an Automation Script with the Script Editor

We'll now build the Airtable automation script that reads your data from the table, creates a post, and send it to the social networks via Ayrshare. You will be using the Airtable script editor.

### Add Trigger

* In the workspace, click on *Automation* and then *+New automation.*

<img class="center" src="https://mintcdn.com/ayrshare-docs/6mPR4kmwNEz1kMbX/images/packages-guides/new%20automation.webp?fit=max&auto=format&n=6mPR4kmwNEz1kMbX&q=85&s=d2637323e3e540d6e46cf0d45e2f161a" alt="Go to the Automation section of Airtable" width="932" height="144" data-path="images/packages-guides/new automation.webp" />

<ul class="custom-bullets">
  <li>Name the automation.</li>
  <li>Click *Choose a Trigger*.</li>
  <li>Select When a Record is Created.</li>
  <li>Select the table with the above fields.</li>
  <li>Click Done.</li>
</ul>

## Add Action

<ul class="custom-bullets">
  <li>Start by clicking *Add Action*.</li>
  <li>Select *Run Script*. You will be brought into the script editor.</li>
</ul>

**Delete** the line:

```javascript theme={"system"}
console.log(`Hello, ${base.name}!`);
```

And **copy and paste** into the script editor the following code:

```javascript theme={"system"}
const API_KEY = "Your API Key"; // Get a free key at app.ayrshare.com

console.log(`Starting Post ${base.name}!`);

const sendPost = async (data) => {
  const { post, platforms, imageUrls, profileKeys, scheduleDate, shortenLinks } = data;

  const body = Object.assign(
    {},
    post && { post },
    platforms && { platforms },
    profileKeys && { profileKeys: profileKeys.split(",") },
    Array.isArray(imageUrls) &&
      imageUrls.length > 0 && {
        mediaUrls: imageUrls.map((image) => image.url)
      },
    scheduleDate && { scheduleDate },
    shortenLinks !== undefined && shortenLinks !== null && { shortenLinks }
  );

  console.log("Posting JSON:", JSON.stringify(body, null, 2));

  if (profileKeys) {
    body.profileKeys = profileKeys.split(",");
  }

  const response = await fetch("https://api.ayrshare.com/api/post", {
    method: "POST",
    body: JSON.stringify(body),
    headers: {
      "Content-Type": "application/json",
      Authorization: `Bearer ${API_KEY}`
    }
  }).then((res) => res.json());

  return response;
};

const table = base.getTable("Posts");
const query = await table.selectRecordsAsync();
const filteredRecords = query.records.filter((record) => {
  const status = record.getCellValue("Status");
  return status === "pending";
});

for (let record of filteredRecords) {
  const post = record.getCellValue("Post");
  const images = record.getCellValue("Images");
  const platforms = record.getCellValue("Platforms");
  const profileKeys = record.getCellValue("Profile Keys");
  const scheduleDate = record.getCellValue("Schedule Date");

  const shortenLinks = false;
  const response = await sendPost({
    post,
    platforms: platforms.map((x) => x.name),
    imageUrls: images,
    profileKeys,
    scheduleDate,
    shortenLinks
  });

  console.log(response);

  if (response) {
    let status;
    if (Array.isArray(response)) {
      status = response.map((x) => x.status).every((x) => x === "success") ? "success" : "error";
    } else {
      status = response.status;
    }

    await table.updateRecordAsync(record, {
      Status: status
    });
  }
}
```

This code will read from your table and post to Ayrshare. However, you first need to add in your API Key (gathered from above).

Replace `Your API Key` with your real API key.

## Test the Script

In the script editor, press *>Test*

The script will run and output the response from the API call. If everything worked, you'll see a success message returned, the pending field in your records changed to success, and your post on the selected social network.

Once you create a new record in the table, the script will run and process pending records.

## Airtable Docs

If you want more information, see the [Airtable docs](https://www.airtable.com/developers).
They have details on how to use the Airtable script editor.

## Video Tutorial

Here is a great video tutorial from the team at Automate All The Things. This video walks through how to integrate Ayrshare into a live Airtable project.

<div class="video-container">
  <iframe width="560" height="315" src="https://www.youtube.com/embed/U_jo6f5hsyY" title="Post To Social Media From Airtable" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" />
</div>

Please see more [examples of integrating Airtable with social media](https://www.ayrshare.com/automatically-post-to-social-media-from-airtable/).

## Questions

If you have any questions or comments, please reach out to us via [email](mailto:contact@ayrshare.com) or <a href="javascript:void(0)" onClick={() => window.Intercom && window.Intercom('show')}>chat with us</a>.
