Post to all of your social accounts with the Ayrshare Postman Collection
This is a guest post written by Boris Markovich, co-founder at Ayrshare.
There are multiple social networks that have crossed over a billion monthly active users—including Facebook, Instagram, YouTube, and TikTok—and their continued growth makes them a great channel for businesses building a brand and finding new customers.
In this article, we’ll show you how to post to all of your social accounts with the Ayrshare Postman Collection. Ayrshare is the leading social media API that allows platforms and businesses to easily post to all ten major social networks from their platforms. This includes Facebook, Instagram, LinkedIn, Google Business Profile, Pinterest, Reddit, Telegram, TikTok, Twitter, and YouTube.
We’ll also explain how Ayrshare leverages the Postman Collection to make it easy for our clients to get up and running quickly.
Fork the Ayrshare collection
Search the Postman Public API Network for the Ayrshare collection. Then, fork this collection so that you have a local copy that you can edit. You will see many endpoints available, but we’ll focus on the /post
endpoint for this article.
Connect your social accounts
Before we can use the API endpoint to send posts, we need to create an Ayrshare account and link our social accounts. To do so, follow these steps:
- First, go to app.ayrshare.com to sign up for an account. You will find your API key in the web dashboard.
- Next, navigate to the Social Accounts page in the Ayrshare dashboard and link each of your social accounts, such as Facebook, Twitter, and LinkedIn. This linking process uses secure OAuth to keep your accounts safe.
Now that our social accounts are connected, we can start posting.
Construct the API call in Postman
In this section, we will use Postman to make a REST API call to the https://app.ayrshare.com/api/post
endpoint, which will publish our social media post.
Set the API key as an environment variable
Postman allows you to set environment variables that can be used by all of the endpoints within a collection. The main advantage of environment variables is decoupling the secret keys from your code and having them located in a single, updatable place. The Ayrshare collection already has the environment variable {{API_KEY}}
set for each endpoint.
You can set your own API_KEY
value in the Globals section of the Environments tab in Postman.
Publish a post with /post
Next, we’ll publish a post to the social networks you previously linked in the Ayrshare dashboard. In the following example, we’ll publish a post to Twitter, Instagram, LinkedIn, and Facebook. If you choose to link other social networks, you can replace the value with the appropriate name, such as “pinterest.”
Select the POST /post
endpoint in the left-hand panel, and then click on the Body tab and the raw radio button.
Postman Collections allow API producers to add examples to help users get started. You can see an example such as the one below in the collection nested under the /post
call.
In this sample post, we added post text, selected four social networks to publish to, and added an image from Unsplash (credit: photo of sailor.js by Kir Simakov on Unsplash).
json { "post": "The beauty parlor is filled with sailors The circus is in town", "platforms": [ "twitter", "facebook", "instagram", "linkedin" ], "mediaUrls": ["https://img.ayrshare.com/012/sailor.jpg" ] }
Copy and paste the above JSON into Postman and click Send.
The result returns an array of postIDs, one for each of the social networks. You also get four URLs for the posts, so you can click through to each of the URLs (remember to CMD-click).
Congratulations, your post is now live on all four social networks!
Bonus: Generate code in Postman
Typically, the next step would be to make these REST endpoint calls in your code, with languages such as Python, PHP, or JavaScript.
One amazing feature of Postman is the ability to generate code in over a dozen programming languages. Simply click the </> icon in the context bar in Postman, choose your programming language, and your code will be generated. Here is the /post
call with code generated by Postman in JavaScript-Fetch:
javascript var myHeaders = new Headers(); myHeaders.append("Authorization", "Bearer API_KEY"); myHeaders.append("Accept-Encoding", "gzip"); var raw = JSON.stringify({ "post": "The beauty parlor is filled with sailors The circus is in town", "platforms": [ "twitter", "facebook", "instagram", "linkedin" ], "mediaUrls": [ "https://img.ayrshare.com/012/sailor.jpg" ] }); var requestOptions = { method: 'POST', headers: myHeaders, body: raw, redirect: 'follow' }; fetch("http://localhost:5001/ayrshare/us-central1/api/post", requestOptions) .then(response => response.text()) .then(result => console.log(result)) .catch(error => console.log('error', error));
Learn more about how to generate code for Ayrshare in Postman.
Get started with Ayrshare and Postman
As an API-first company, Ayrshare focuses on ensuring that our users can implement our APIs as quickly and easily as possible. That’s why we send the Ayrshare collection to each client as the first step in the onboarding process to ensure that they can test all their calls immediately. The Postman Collection is also used together with our detailed documentation in many of our technical support responses.
The full Ayrshare collection includes many more endpoints that you can explore. For instance, you can get post analytics, see all the comments, get an array of historical posts, and much more. We recommend trying each of the endpoints and reading the documentation for each one. This combination of features lets you build your own social media management system within your platform.
If you have a platform or a business with content to post to social media, try the Ayrshare Postman Collection as the first step in creating your own social media integrations.
What do you think about this topic? Tell us in a comment below.