Notion

Integrate Ayrshare with Notion

Post to you social media (and get analytics) directly from Notion via Ayrshare's social media API.

Github code of Notion social posting integration:

Create a Notion Database

In Notion, create a database in table view with the following column names and column types:

  • Post as Title column type (you don’t have a choice here with the column type)

  • Platforms as Multi Select column type with values: facebook, instagram, twitter, linkedin, tiktok, and/or telegram.

  • Images as Files & Media column type .

  • Profile Keys as Text column type.

  • Status as Text column type.

  • Schedule Date as Date column type with Date Format Month/Day/Year, Time Format 24 Hours, and include time

These fields will be used in the script specified later in this page. Please note, some social networks "platforms" require images or videos. For example, Instagram requires and image or video and TikTok requires a video. Please see the endpoints for the different networks.

See a live Notion example

Enter in Test Post Data

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

  • Post: Enter "Happy New Year!"

  • Platforms: select one or more networks you have linked. Please be sure the name is lowercase.

  • Images: Attach an image or a video.

You must upload an image to Notion. You can not use an image URL.

  • 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.

  • Status: Enter "pending". The script only grabs records that are set to "pending". Please be sure "pending” is lowercase.

  • Schedule Date: Leave blank since we'll just test immediate posting right now. Later you can select a future date to schedule the post.

Create Internal Integration in Notion

Go to the My Integrations page in Notion and click on New Integration.

>> Learn more about Notion Integrations.

You can name the integration "Ayrshare" to identify it easily and choose the appropriate workspace that will have the post data.

Finally, the default capabilities that have been selected for you will do. Submit to create the integration.

If successful, an internal integration token will be available to you. Note this for future steps in this page.

And gather your Notion integration token.

Connect Notion Database to the Internal Integration

Open the Notion database that you created earlier. Click on the ellipsis on the top right corner of the page and go to Add Connection.

Here you can search for the internal integration you created in the previous step by the name you chose for it.

Once you click on the internal integration, you have now connected this Notion database to the integration.

Run script to Send Posts from Notion

You can now run a script in your local environment that will read data from the Notion database and make a post through the Ayrshare API for each row in it with status of "pending".

Make sure to set the following environment variables used in the script:

  • API_KEY: this is API Key you get from Ayrshare. This is the primary API Key for your Ayrshare primary profile.

  • NOTION_DATABASE_ID: Open the database you created earlier in this page and get the database ID from the URL.

The database ID will be the value before the ?v= in the database page URL.

https://www.notion.so/company/<NOTION_DATABASE_ID>?v=aaee9f
  • NOTION_KEY: internal integration token from earlier.

Run the following JavaScript in a Node.js environment:

  • Clone the repository:

git clone https://github.com/ayrshare/notion
  • cd into the notion directory and run npm install.

  • Update the .env file with your Ayrshare API_KEY, Notion NOTION_KEY and NOTION_DATABASE_ID.

  • Run node index.js

You can run it at Heroku, Digital Ocean, or Vercel in production.

If successful, all "pending’" status columns will be changed to "success’" and the posts will have been made to the appropriate social networks.

Last updated