The guide is for setting up a single company. For Business and Enterprise Plan subscriptions with multiple users, a personalized integration guide is provided.

Connect Your Social Media Accounts

Log in or sign up for an Ayrshare account. On the Social Account page, click the social networks you want to connect. Please be sure to grant all permissions.

Get Your API Key

Include your API Key to authorize access to the API endpoints. This key is used in the header of your requests, and should be preceded by the Bearer keyword.

Your API Key is located within the Ayrshare Dashboard, on the API Key page. If necessary, switch to your ‘Primary Profile’ via the User Profiles page. From there, you can find the API Key page in the left-hand side panel.

Every API call must include the API Key in the Header using a Bearer Token. Also include the Content-Type of application/json.

Header
"Authorization": "Bearer API_KEY",
"Content-Type": "application/json"

See the Authorization for more information.

Send Your First Post via the API

The cURL example is listed below, but you can use any language. On the endpoint pages we have examples in multiple languages, and we also offer SDK packages and guides to help.

Include a post body, the platform destinations, and a media URL if you are posting an image or video. The HTTP POST endpoint is /post.

Here is the sample code. Remember to only include the platforms you have linked.

Publish a Post
curl --request POST \
  --url https://api.ayrshare.com/api/post \
  --header 'Authorization: Bearer API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "post": "Today is a great day!",
  "platforms": ["twitter", "facebook",
    "instagram", "linkedin"],
  "mediaUrls": ["https://img.ayrshare.com/012/gb.jpg"]
}'

Congrats! You just sent your first post.

A response of status of “success” will be received. Check your social media pages to ensure that the post was successfully processed and is live.

See more code examples of calling the social media api in Node.js, Python, PHP, Golang, C#, and Ruby:

Post

Diving a Little Deeper

Let’s look at what happened.

1

Set the Header

We set the Header Authorization bearer token (API Key) and content type of json.

2

Create a Body Object

Next, we created a body object:

  • Post containing the text “Today is a great day!”.
  • Social network platforms of Twitter, Facebook, Instagram, and LinkedIn. You should only include the platforms you linked in the Social Linkage Page.

  • Added an image in the mediaUrls.
3

Call the /post Endpoint

Sent everything as an HTTP POST to the /post endpoint.

Before You Go, Some Best Practices

Read the Docs

We maintain extensive and up-to-date documentation. Since you are already here, take some time to check out the sections of the docs in the left navigation.

Error Codes Are Important

You need to handle them so your users have a great experience.

Errors

Keep Your API Key Secure

We take security very seriously, and so should you. You have full control over the connection between Ayrshare and your social media accounts. Once the accounts are connected, the Ayrshare API key becomes the way you authenticate. Please keep this key secret and secure.

Publish Test Posts

You can publish test posts with a random quote, image, or video using the randomPost, randomMediaUrl, and isLandscapeVideo or isPortraitVideo parameters in the /post endpoint. If you use the randomPost, the post parameter is not required.

These posts are live on your social media pages, so if appropriate, delete them after testing.

Random Quote

"randomPost": true

Random Image

Send a random image by adding randomMediaUrl: true.

"randomMediaUrl": true

Random Video

Send a random landscape video by adding isVideo: true and isLandscapeVideo: true. The video will be standard landscape size.

"randomMediaUrl": true,
"isLandscapeVideo": true

Send a random portrait video, required for TikTok or Facebook/Instagram Reels, by adding isVideo: true and isPortraitVideo: true.

"randomMediaUrl": true,
"isPortraitVideo": true

Example cURL Call

Send a random quote and portrait video.

curl \
-H "Authorization: Bearer API_KEY" \
-H "Content-Type: application/json" \
-X POST \
-d '{
    "randomPost": true,
    "platforms": ["twitter", "facebook", "instagram"],
    "randomMediaUrl": true,
    "isPortraitVideo": true
}' \
https://api.ayrshare.com/api/post

Use Postman to Test Your API Calls

Postman is an amazing tool for testing API calls. You can even generate code in over a dozen languages.

Demo Code

If you are looking for sample demo project in React and NodeJS, please see this GitHub repository:

Github Social Posting Demo App

Common Troubleshooting

Sometimes things don’t go right, so here is a little help in our help center.

Troubleshooting

Reach Out To Us for Help

We are here to help, so please use the chat in the bottom right corner or email us.