Comment Moderation

This guide shows you how to get comments, reply to comments, delete comments, hide/unhide comments, and disable/enable comments on Instagram Media owned by your app users.

Starting August 27, 2024, the instagram_business_manage_comments will be required to access the username field of an Instagram user who commented on media of an app user's Instagram professional account.

Visit our Private Replies guide documentation to learn how send private replies (direct messages) to users who have commented on your app users' Instagram Media.

Requirements

This guide assumes you have read the Instagram API Overview and implemented the needed components for using this API, such as Instagram Login for Business to receive Instagram User access tokens and a webhooks server to receive notifications.

You will need the following:

Access Level

  • Advanced Access if your app serves Instagram professional accounts you don't own or manage
  • Standard Access if your app serves Instagram professional accounts you own or manage and have added to your app in the App Dashboard

Access tokens

  • An Instagram User access token requested from a person who can manage comments on the Instagram professional account

Base URL

All endpoints can be accessed via the graph.instagram.com host.

Endpoints

IDs

  • The ID for the Instagram professional account (<IG_ID>) that owns the media that was commented on

Permissions

  • instagram_business_basic
  • instagram_business_manage_comments

Webhook event subscriptions

  • comments
  • live_comments

Get comments

There are two ways to get comments on published Instagram media, an API query or a webhook notification.

API Request

To get all the comments on a published Instagram media object, send a GET request to the /<IG_MEDIA_ID>/comments endpoint.

curl -X GET "https://graph.instagram.com/v20.0/<IG_MEDIA_ID>/comments"

On success your app receives a JSON response with an array of objects containing the comment ID, the comment text, and the time the comment was published.


{
  "data": [
    {
      "timestamp": "2017-08-31T19:16:02+0000",
      "text": "This is awesome!",
      "id": "17870913679156914"
    },
    {
      "timestamp": "2017-08-31T19:16:02+0000",
      "text": "Amazing!",
      "id": "17870913679156914"
    },
		... // results truncated for brevity
  ]
}

Webhooks

When the comments or live_comments event is triggered your webhooks server will receive a notification that include the ID for your published media, the ID for the comments on that media, and the Instagram-scoped ID for the person who published the comment.

{
  "object": "instagram",
  "entry": [
    {
      "id": "<IG_ID>",
      "time": 1502905976963,
      "field": "comments",  //will be "live_comments" for comments on live media
      "value": {
          "from": {"id": "<IGSID>","username": "<USERNAME>"},
          "media": {"id": "<MEDIA_ID>","media_product_type": "FEED"},
          "id": "<IG_COMMENT_ID>",
          "text": "<COMMENT_TEXT>"
      }
    }
  ]
}

You can parse the API or webhook notification for comments that match your criteria then use the comment's ID to reply to that comment.

Reply to a comment

To reply to a comment, send a POST request to the /<IG_COMMENT_ID>/replies endpoint, where <IG_COMMENT_ID> is the ID for the comment which you want to reply, with the message parameter set to your message text.

Sample Request

curl -X POST "https://graph.instagram.com/v20.0/<IG_COMMENT_ID>/replies"
   -H "Content-Type: application/json" 
   -d '{
         "message":"Thanks for sharing!"
       }'

On success, your app receives a JSON response with the comment ID for your comment.

{
  "id": "17873440459141029"
}

If you have a lot of comments that you want to reply to, you could batch the replies into a single request.

Next steps

Learn how to send a message to the person who commented on your media post using Private Replies.