How to Set Up Instagram Comment to DM Automation With an API in 2026
"Comment LINK and I'll send it to you" is one of the most reliable plays on Instagram. The catch is the follow-up. Doing it by hand means watching a post, reading every comment, and DMing people one by one before they lose interest.
Comment to DM automation does that for you. Someone comments a keyword, they get a DM seconds later, and you never touch it. Building this yourself against Meta's API is real work though: App Review for the comment and messaging permissions, a webhook server to catch new comments, keyword matching, and DM delivery with retries.
PostPeer wraps all of that into one Comment to DM automation API. You create an automation with a keyword and a DM, and PostPeer handles the webhooks, matching, and delivery. Here's how to set it up on Instagram.
What you need
- A PostPeer account (free tier works)
- Your access key from the dashboard
- An Instagram Business or Creator account (personal accounts can't automate comments or DMs, that's Meta's limit)
Step 1: Get your API key
Sign up at PostPeer, open the dashboard, and grab your access key from the Access Keys page. Every request uses the x-access-key header:
-H "x-access-key: YOUR_API_KEY"Step 2: Connect Instagram and grant the permissions
PostPeer runs the OAuth flow. Connect the Instagram account from the dashboard, or hit the connect endpoint for an authorization URL:
curl https://api.postpeer.dev/v1/connect/instagram \
-H "x-access-key: YOUR_API_KEY"Comment to DM needs two permissions: instagram_business_manage_comments to read comments and post public replies, and instagram_business_manage_messages to send the DM. PostPeer requests both during connect, so there's no App Review on your side. If you connected the account before comment automation shipped, reconnect it once so those scopes are granted.
Grab the account ID from the integrations endpoint. That's your accountId for every call below:
curl https://api.postpeer.dev/v1/connect/integrations \
-H "x-access-key: YOUR_API_KEY"Step 3: Find the post to automate
You can run an automation on one specific post or reel, or across every post on the account. To target a specific one, list eligible posts and grab its ID:
curl "https://api.postpeer.dev/v1/comment-automations/posts?accountId=your-ig-id" \
-H "x-access-key: YOUR_API_KEY"Response:
{
"success": true,
"posts": [
{
"id": "17901234567890123",
"caption": "New drop is live",
"mediaType": "IMAGE",
"permalink": "https://instagram.com/p/ABC123/",
"previewUrl": "https://scontent.cdninstagram.com/...",
"timestamp": "2026-09-10T15:30:00Z"
}
],
"nextCursor": "QVFIUl9..."
}That id is the platformPostId you'll bind the automation to.
Step 4: Create the automation
POST to /v1/comment-automations with your trigger and your message. This one fires when a comment on that post contains link or guide, sends a DM, and drops a public reply under the comment:
curl -X POST https://api.postpeer.dev/v1/comment-automations \
-H "x-access-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"accountId": "your-ig-id",
"name": "Link in DM",
"postScope": "specific",
"platformPostId": "17901234567890123",
"keywords": ["link", "guide"],
"matchMode": "word",
"publicReplies": ["Sent you a DM!"],
"dmMessage": "Here is the link you asked for: https://example.com"
}'Response:
{
"success": true,
"automation": {
"id": "AUTOMATION_ID",
"platform": "instagram",
"name": "Link in DM",
"status": "active",
"trigger": {
"postScope": "specific",
"platformPostId": "17901234567890123",
"keywords": ["link", "guide"],
"matchMode": "word",
"excludeKeywords": []
},
"actions": {
"publicReplies": ["Sent you a DM!"],
"dmMessage": "Here is the link you asked for: https://example.com"
},
"stats": { "triggered": 0, "succeeded": 0, "failed": 0 }
}
}The automation is live the moment it's created. PostPeer subscribes the account to Instagram's comment webhooks, so the next matching comment triggers the DM in real time.
A few fields worth knowing:
matchModecontrols how keywords match.wordmatches a whole word (socutematches "so cute!" but not "acutely"),containsmatches anywhere in the text, andexactmatches the entire comment.- Leave
keywordsempty to trigger on every new comment on the post. publicRepliesis optional. Add up to five alternatives on separate entries and PostPeer rotates one per comment so the replies don't read like a bot. Omit it to send the DM only.- Add
excludeKeywordsto skip comments you never want to trigger on.
Step 5: Check what fired
Every trigger is logged with the comment, the commenter, and whether the DM and public reply went out:
curl "https://api.postpeer.dev/v1/comment-automations/AUTOMATION_ID/logs?limit=10" \
-H "x-access-key: YOUR_API_KEY"Response:
{
"success": true,
"logs": [
{
"commentId": "17987654321098765",
"commenterName": "jane_doe",
"commentText": "Send me the link!",
"status": "succeeded",
"privateReplySent": true,
"publicReplyStatus": "sent",
"createdAt": "2026-09-15T11:45:22Z"
}
],
"pagination": { "total": 128, "limit": 10, "skip": 0, "hasMore": true }
}The automation object also carries running stats (triggered, succeeded, failed) so you can surface performance in your own dashboard.
Step 6: Pause, update, or delete
Pause or edit an automation with a PATCH. Everything except the account is updatable, so you can swap the DM copy or flip it off without recreating it:
curl -X PATCH https://api.postpeer.dev/v1/comment-automations/AUTOMATION_ID \
-H "x-access-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "status": "paused" }'Delete it when you're done:
curl -X DELETE "https://api.postpeer.dev/v1/comment-automations/AUTOMATION_ID" \
-H "x-access-key: YOUR_API_KEY"Automate every post on the account
Instead of binding to one post, set postScope to any and drop platformPostId. Now the automation runs on comments across every post on the account, which is useful for an always-on workflow like a keyword that always sends your link:
curl -X POST https://api.postpeer.dev/v1/comment-automations \
-H "x-access-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"accountId": "your-ig-id",
"name": "Always send the link",
"postScope": "any",
"keywords": ["link"],
"matchMode": "word",
"dmMessage": "Here you go: https://example.com"
}'If several automations could match the same comment, only the most specific one runs, so a post-specific automation wins over an account-wide one.
What it costs
Each triggered DM spends 1 credit. The optional public reply spends 1 more, and only when it actually sends. So a DM plus a public reply is 2 credits per matched comment, and a DM-only automation is 1. Creating, listing, updating, and deleting automations follow standard API usage. The free tier includes credits to test the whole flow.
What's next
That's the full loop: connect the account, pick a post, create a keyword-triggered automation, and watch the DMs go out on their own. It's enough to build "comment to unlock" campaigns, lead capture, or a support workflow straight into your product.
Full reference is on the Instagram Comment to DM API page. If you want to handle the conversation after the first DM, pair it with the Instagram Messaging API, and to moderate the threads see how to manage Instagram comments with an API.