Never Miss a Comment Again: How to Use Ayrshare’s Comments API Endpoint

Comments can be a big driver of engagement on social networks —whether it’s praise, feedback, or the occasional emoji. With Ayrshare’s Comments API Endpoint, you can manage comments across multiple platforms automatically, making it easier to stay on top of responses, especially when dealing with a large number of posts and comments. If you use Facebook Pages, Instagram, LinkedIn, Reddit, TikTok, X/Twitter, or YouTube, you will find this article useful.

Let’s dive into how to use Ayrshare’s Comments API Endpoint, including a helpful tip on automatically adding a first comment—a strategy that can help boost visibility and jumpstart engagement on your posts.

What is the Ayrshare Comments Endpoint?

The Ayrshare Comments Endpoint is a feature that allows you to manage comments on your social media posts. With it, you can:

  • Retrieve comments from various platforms
  • Add new comments to your posts
  • Delete and hide comments
  • Add a first comment
  • Monitor and respond to audience feedback automatically

Using this endpoint is especially useful for businesses and content creators who want to streamline their social media management, improve response times, and foster more interaction on posts.

How to Use the Ayrshare Comments API

To begin using the Ayrshare Comments API, you’ll first need a paid Ayrshare account and API key. Let’s walk through the primary functions of this endpoint.

Before you add a comment to a post, you first need to have a post to add a comment. Via Ayrshare you can gather all the post for a linked social networks and then use the returned post ID to publish the comment. However, in this tutorial we recommend just publishing a new social post with the /post endpoint. Returned will be a post ID, which we’ll use below. See the quick start guide for details.

Step 1: Publish a Post

Publish a new comment on a social media post that exists on multiple social networks, use the POST /comment endpoint.

Example in cURL:

curl \
-H "Authorization: Bearer API_KEY" \
-H 'Content-Type: application/json' \
-d '{"id": "Ut1fWU6XkqkMayHGnJZ", "platforms": ["facebook", "instagram", "linkedin", "reddit", "tiktok", "twitter", "youtube"], "comment": "An amazing comment!"}' \
-X POST https://api.ayrshare.com/api/comments

Replace YOUR_API_KEY with your actual API key and POST_ID with the ID of the target post, returned from the publish post call – see able. The platform field specifies which social network you’re targeting, in this example facebook, instagram, linkedin, reddit, tiktok, twitter, and youtube.

Returned will be a JSON object of the status social network:

{
    "facebook": {
        "status": "success",
        // Facebook Social Comment ID
        "commentId": "358482752285927_363474831785719", 
        "comment": "The best comment ever!",
        "platform": "facebook"
    },
    "instagram": {
        "status": "success",
        // Instagram Social Comment ID
        "commentId": "17060111860440276",
        "comment": "The best comment ever!",
        "platform": "instagram"
    },
    "linkedin": {
        "status": "success",
        // LinkedIn Social Comment ID
        "commentId": "urn:li:comment:(urn:li:activity:7141202289402236928,7141205176207503360)", 
        "comment": "Someone’s sitting in the shade today because someone planted a tree a long time ago. - Warren Buffett",
        // Social comment Id from LinkedIn
        "commentUrn": "urn:li:comment:(urn:li:activity:7141202289402236928,7141205176207503360)",
        "platform": "linkedin"
    },
    "youtube": {
        "status": "success",
        // YouTube Social Comment ID
        "commentId": "UgzIEZsDQKXgHsEnwTR4AaABAa", 
        "comment": "The best comment ever!",
        "platform": "youtube"
    },
    "tiktok": {
        "status": "success",
        // TikTok Social Comment ID
        "commentId": "7260964914699764524",
        "comment": "The best comment ever!",
        "platform": "tiktok",
        "videoId": "7260964048362310959"
    },
    "twitter": {
        "status": "success",
         // Twitter Social Comment ID
        "commentId": "1525632403262101648",
        "comment": "The best comment ever!",
        "postUrl": "https://twitter.com/ayrshare/status/1525632403262101648"
    },
    "status": "success",
    // Ayrshare Comment ID. Used for replying to a comment.
    "commentID": "IUDSCfdYfFkw_dWhW9PLI",
    // Ayrshare Post ID
    "id": "Ut1fWU6XkqlMayHGnJZ" 
}

Step 2: Retrieve Comments

Retrieving comments is useful if you want to analyze feedback or display social proof on other platforms. Here’s how to get comments from a post:

  1. Send a GET request to the comments endpoint with your API key and the specific post ID.
  2. This request will return all comments associated with that post.

Example in JavaScript:

const API_KEY = "API_KEY";

fetch("https://app.ayrshare.com/api/comments/Ut1fWU6XkqkMayHGnJZ", {
      method: "GET",
      headers: {
        "Authorization": `Bearer ${API_KEY}`
      }
    })
      .then((res) => res.json())
      .then((json) => console.log(json))
      .catch(console.error);

You will send in the post ID – Ut1fWU6XkqkMayHGnJZ – to get all the comments for this post. This request will then return a list of comments with analytics, such as like count, for the specified post on the all the platforms the post was published. Also included will be replies to the comment, so you can vie the entire thread.

The response will contain an array of comments, including details such as comment content, the author, timestamp, and other relevant metadata including comment ID.

{
    "facebook": [
        {
            "comment": "What a great comment",
            // Facebook Social Comment ID
            "commentId": "806720068141593_1849585385469876",
            "commentCount": 3,
            "created": "2024-02-27T19:55:28Z",
            // If available. Facebook determines availability based on the user's security profile and settings.
            "from": {
                "name": "John Smith",
                "id": "5075334022535844"
            },
            "likeCount": 342,
            "platform": "facebook",
            // If available. Facebook determines availability based on the user's security profile and settings.
            "userName": "WondrousTimes",
            "userLikes": false,
            // Facebook replies to replies have the same parent id regardless of nesting.
            "replies": [
                {
                    "comment": "Nice Comment 2",
                    "commentId": "806720068141593_320599703877348",
                    "commentCount": 0,
                    "company": true,
                    "created": "2024-02-27T19:55:40Z",
                    "from": {
                        "name": "Sue Me",
                        "id": "5075334022535800"
                    },
                    "likeCount": 3,
                    "parent": {
                        "createdTime": "2024-02-27T19:55:28+0000",
                        "from": {
                            "name": "John Smith",
                            "id": "5075334022535844"
                        },
                        "message": "What a great comment",
                        "id": "806720068141593_1849585385469876"
                    },
                    "platform": "facebook",
                    "userLikes": false
                }
            ]
        }
    ],
    "instagram": [
        {
            "comment": "Love this post.",
            // Instagram Social Comment ID
            "commentId": "18030599567251077",
            "created": "2022-10-13T00:52:47Z",
            // If available. Instagram determines availability based on the user's security profile and settings.
            "from": {
                "name": "WondrousTimes",
                "id": "112775157855689"
            },
            // Is the comment hidden
            "hidden": false,
            "likeCount": 1,
            // The Instagram Social ID of the parent post. Only returned when using get by ID on a reply.
            "parentId": "17999860012861",
            "platform": "instagram",
            "replies": [
                {
                    "created": "2024-04-04T22:37:39Z",
                    "from": {
                        "id": "178414522127073334",
                        "username": "ayrshare"
                    },
                    "hidden": false,
                    // Instagram Social Comment Id
                    "id": "18023114651100610",
                    "likeCount": 2,
                    "parentId": "178438334431963234",
                    "text": "@ayrshare Thanks",
                    "user": {
                        "id": "17841452212702234"
                    },
                    "username": "ayrshare"
                }
            ],
            // ID of Instagram user who created the comment.
            "user": {
                "id": "17841452212707498"
            },
            // Instagram determines availability based on the user's security profile and settings.
            "userName": "ayrshare"
        }
    ],
    "status": "success",
    "id": "Ut2fWU6XkqkMayHGnJZ7",
    "lastUpdated": "2023-03-26T22:30:13.035Z",
    "nextUpdate": "2023-03-26T22:41:13.035Z"
}

Step 3: Reply to a Comment

Adding a comment to an existing post allows you to engage with users directly from the Ayrshare API. This can be particularly helpful if you have an automated process for responding to frequently asked questions or engaging with users who mention your brand.

  1. Send a POST request to the reply comments endpoint with your comment ID and the comment text.
  2. Ayrshare will automatically add the comment to the post on the respective social media platform.
  3. You can also get all the comments of a post you didn’t publish.

Example in Python:

import requests

payload = {'commentId': 'Ut1fWU6XkqkMayHGnJZ', 
        'platforms': ['facebook', 'instagram', 'linkedin', 'twitter', 'youtube'],
        'comment': 'An amaxing comment!'}
headers = {'Content-Type': 'application/json', 
        'Authorization': 'Bearer API_KEY'}

r = requests.post('https://app.ayrshare.com/api/comments/reply', 
    json=payload, 
    headers=headers)
    
print(r.json())

The commentId field – Ut1fWU6XkqkMayHGnJZ – contains the ID of the comment you’re replying to, ensuring your response is threaded correctly.

Once the reply comment is posted, Ayrshare will confirm with a success message and return details about the comment.

Step 4: Delete a Comment

To remove a comment, use the DELETE /comment endpoint.

Example in PHP:

<?php

$apiUrl = 'https://app.ayrshare.com/api/comments/Ut1fWU6XkqkMayHGnJZ'; // Replace with your post ID
$apiKey = 'API_KEY';  // Replace 'API_KEY' with your actual API key

$headers = [
    'Content-Type: application/json',
    'Authorization: Bearer ' . $apiKey,
];

$curl = curl_init($apiUrl);
curl_setopt_array($curl, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'DELETE',
    CURLOPT_HTTPHEADER => $headers
]);

$response = curl_exec($curl);

if ($response === false) {
    echo 'Curl error: ' . curl_error($curl);
} else {
    echo json_encode(json_decode($response), JSON_PRETTY_PRINT);
}

curl_close($curl);

Include the comment ID – Ut1fWU6XkqkMayHGnJZ – of the comment you want to delete as a path parameter with the ID of the comment you want to delete. Use this feature judiciously as part of your content moderation strategy.

Disabling Comments on Social Media Posts

A nifty feature is being able to disable commenting on posts. For example, you might not want to moderate the comments on a particular post. To disable comments on a post just add the field disableComments when creating the original post or update an existing post.

Example in cURL:

curl \
-H "Authorization: Bearer API_KEY" \
-H 'Content-Type: application/json' \
-d '{"post": "Today is a great day!", "platforms": ["instagram", "linkedin"], "disableComments": true, "mediaUrls": ["https://img.ayrshare.com/012/gb.jpg"]}' \
-X POST https://app.ayrshare.com/api/post

Set disableComments to true to disable comments, or false to enable them. This feature’s is available for Instagram, LinkedIn, and TikTok.

How to Automatically Add a First Comment

Adding a first comment immediately after posting is a clever technique to boost engagement. This first comment often provides additional context, adds a call-to-action, or includes relevant hashtags that don’t clutter the main post.

Ayrshare makes this incredibly simple since you can send the first comment directly at the same time that you create the post.

Example Code Workflow:

POST /api/post

Headers:

  - Authorization: Bearer YOUR_API_KEY

Body:

{
  post: "Today is a great day!", // required
  platforms: ["twitter", "facebook"], // required
  firstComment: {
    "comment": "My first comment" // required
  }
}

Best Practices for Using the Comments API Endpoint

  1. Be Timely: Timely responses enhance relevance and shows attentiveness, making them more impactful.
  2. Use a CTA (Call-to-Action): Comments that ask questions or prompt a response are more likely to receive engagement. This could be as simple as “Let us know your thoughts below!” or “Have you tried this?”
  3. Monitor for Spam: If you’re automating comment posting, make sure to monitor for any spam or irrelevant content. Regularly check retrieved comments to ensure a healthy interaction space.
  4. Experiment with Hashtags: Use the comment section to add additional hashtags relevant to the post topic. This keeps your main post clean while still boosting discoverability.

Go Further

The Ayrshare Comments API Endpoints are a powerful set of tool to enhance your social media engagement strategy by allowing you to manage comments in your platform, including posting, retrieving, replying to, and deleting comments, as well as disabling commenting. For more advanced comment options, make sure you check out the full documentation on the comments endpoint.