CommentKeyword API Reference
Endpoint-level reference for Personal Access Token (PAT) integrations.
OpenAPI specification
Use the OpenAPI 3.1 JSON document with API clients, code generators, testing tools, or AI integrations.
View OpenAPI JSONAuthentication
All requests require:
Authorization: Bearer YOUR_TOKENTokens are workspace-scoped and do not expire automatically.
Base URL
https://commentkeyword.com/apiPermissions
keywords:readkeywords:writekeywords:deleteagents:read(optional;keywords:readcan also read agents)conversations:read(list AI agent conversations and read their collected data and transcripts; see Webhooks)
Public IDs
PAT responses expose public IDs (UUID-like strings) for keywords and agents. Use these IDs in API paths and payloads.
{
"id": "5f9619c5-daa7-4f2f-ad6f-971f71f8d7f2",
"aiAgentId": "a6be1900-8f4f-4ae6-8f4e-48f8b28f0f17"
}Keyword scopes and message limits
globalmatches comments on any post.post_specificmatches only assigned posts - listed inmediaIds, added later via a PATCH, and/or caught whileincludeNextPostis enabled.includeNextPost(post_specific only) turns waiting on or off. It automatically becomes false after the next publication is found; enable it again whenever you want to catch another future post.- Changing a keyword to
globalremoves all assigned posts (manual and auto-added) and stops waiting for the next post. - Keyword triggers are normalized before saving: leading and trailing spaces are removed, repeated spaces are collapsed to one, and the text is Unicode NFC-normalized. Only the space character is affected; tabs and line breaks are kept. The result is limited to 100 Unicode characters.
- Comment replies may render to at most 500 characters. The limit applies only while
publicReplyEnabledis true. - Each DM plus an assigned agent's conversation hook may render to at most 1,000 characters. The hook is added after a blank line (2 characters) unless the DM already contains it.
- Placeholders count at their maximum rendered size:
{{handle}}31 characters,{{name}}and{{namefirst}}64 characters each.
Response format
Single-object responses (GET, POST and PATCH on a keyword), GET /api/agents and GET /api/account wrap the result in data with a meta object:
{
"data": { ... },
"meta": { "authType": "pat", "workspaceId": 42 }
}GET /api/keywords adds pagination:
{
"data": [ ... ],
"pagination": { "total": 7, "limit": 20, "offset": 0, "hasMore": false },
"meta": { "authType": "pat", "workspaceId": 42 }
}POST /api/keywords also returns meta.trackFirstKeywordCreated and meta.trackFirstAutomationActivated; PATCH returns meta.trackFirstAutomationActivated.
Keyword object
Every keyword response includes all of these fields.
{
"id": "5f9619c5-daa7-4f2f-ad6f-971f71f8d7f2",
"publicId": "5f9619c5-daa7-4f2f-ad6f-971f71f8d7f2",
"keyword": "pricing",
"matchMode": "contains",
"matchWithoutAccents": false,
"scope": "post_specific",
"includeNextPost": false,
"nextPostStatus": "attached",
"nextPostArmedAt": "2026-03-07T12:00:00.000Z",
"nextPostMediaId": "17900000000000002",
"nextPostClaimedAt": "2026-03-08T09:15:00.000Z",
"nextPostLastAttemptAt": "2026-03-08T09:15:00.000Z",
"nextPostLastError": null,
"nextPostRevision": 2,
"mediaIds": ["17900000000000001", "17900000000000002"],
"autoAddedMediaIds": ["17900000000000002"],
"commentReplies": ["Sent it to you, {{namefirst}}!"],
"publicReplyEnabled": true,
"dmMessages": ["Hey {{namefirst}}, here are the pricing details."],
"trackLinks": false,
"delaySec": 30,
"aiAgentId": "a6be1900-8f4f-4ae6-8f4e-48f8b28f0f17",
"aiAgent": {
"id": "a6be1900-8f4f-4ae6-8f4e-48f8b28f0f17",
"publicId": "a6be1900-8f4f-4ae6-8f4e-48f8b28f0f17",
"name": "Sales Agent",
"status": "live",
"isActive": true
},
"isActive": true,
"createdAt": "2026-03-07T12:00:00.000Z",
"updatedAt": "2026-03-08T09:15:00.000Z"
}aiAgentandaiAgentIdarenullwhen no agent is assigned.autoAddedMediaIdsis the subset ofmediaIdscaught whileincludeNextPostwas enabled.nextPostStatus:null(never started, or stopped),waiting,attached(a post was caught, seenextPostMediaId),disabled(the keyword is inactive),reconnect_required(Instagram is disconnected or its token expired), orfailed(seenextPostLastError).nextPostRevisionincreases whenever the wait is started, stopped or cleared, and when the keyword is activated or paused while waiting.
GET /api/account
Required permission: keywords:read or agents:read.
Returns the Instagram account connected to the token's workspace, for example to show its handle and avatar in a video's call to action.profilePictureUrl is an Instagram CDN link that expires after a few days: download the image when you need it rather than storing the URL.
{
"data": {
"instagram": {
"connected": true,
"username": "youraccount",
"profilePictureUrl": "https://scontent.cdninstagram.com/..."
}
},
"meta": { "authType": "pat", "workspaceId": 42 }
}When no Instagram account is connected, connected is false and the other two fields are null.
curl -H "Authorization: Bearer YOUR_TOKEN" https://commentkeyword.com/api/accountGET /api/agents
Required permission: agents:read or keywords:read.
Parameters
| Field | Type | Required | Accepted Values | Notes |
|---|---|---|---|---|
| (none) | - | No | - | No path, query, or body parameters. |
curl -H "Authorization: Bearer YOUR_TOKEN" https://commentkeyword.com/api/agentsWebhooks
CommentKeyword sends a POST with a JSON body to your URL each time an AI agent collects data in a conversation, and when it completes the objective. Data reaches you as it is collected, even if the contact never finishes the conversation.
Where to set it up
- Settings → Webhooks: the workspace webhook. Every agent without a webhook of its own sends there.
- An agent's page → Data delivery: a URL just for that agent, used instead of the workspace webhook.
- Each destination has an optional authorization token and chooses which events it receives. The URL must be public HTTPS on port 443.
Events
| Field | Type | Required | Accepted Values | Notes |
|---|---|---|---|---|
| ai_conversation_data_captured | event | - | - | The agent collected a new or corrected value for one of its fields. capturedFields lists which ones. |
| ai_conversation_completed | event | - | - | The agent marked the objective as met. Sent once per conversation, with everything collected. |
Request headers
| Field | Type | Required | Accepted Values | Notes |
|---|---|---|---|---|
| Content-Type | string | Yes | application/json | - |
| X-Event-Id | string | Yes | - | Unique per event and the same on every retry. Store it to skip duplicates. |
| Authorization | string | Only with a token | Bearer YOUR_TOKEN | Sent when the destination has a token. Compare it with yours to know the request is from CommentKeyword. |
Payload
{
"event": "ai_conversation_data_captured",
"timestamp": "2026-03-01T10:29:05.000Z",
"data": {
"conversationId": "8b0c2d1e-5f6a-4b7c-9d8e-1f2a3b4c5d6e",
"instagramUsername": "user123",
"instagramUserId": "17841400000000000",
"workspaceId": 1,
"agent": { "id": "f3a1c9e0-7b2d-4e5f-8a9b-0c1d2e3f4a5b", "name": "Lead Qualifier" },
"agentId": 12,
"keywordId": 3,
"objective": "Get the email and phone number",
"completed": false,
"capturedFields": ["email"],
"collectedData": { "email": "[email protected]", "phone": null }
}
}collectedDataalways has every field the agent collects, in the agent's order, withnullfor the ones not collected yet. Each agent keeps its own fields, so useagent.idto tell them apart.ai_conversation_completedhas the same shape withcompleted: trueand nocapturedFields.agent.idis the agent's public ID, as inGET /api/agents.agentIdandkeywordIdare internal numeric IDs kept for older integrations.- To read the whole conversation, call
GET /api/conversations/{conversationId}with a token that hasconversations:read.
Delivery and retries
Answer with any 2xx status within 10 seconds. Other statuses, timeouts and connection errors are retried with growing waits (2, 4, 8 and 16 seconds), up to 5 attempts in total. An event that could not start on time, for example during a restart or an outage on our side, is sent once we recover, usually within minutes but later after a long outage, and keeps its X-Event-Id and its original timestamp. Events can arrive more than once, late or out of order, so rely on X-Event-Id and timestamp.
A token is only sent to the site it was saved for: if you move the URL to another domain, the saved token is removed unless you enter a new one.
Deleting an agent deletes its own webhook and token: its events not sent yet are not sent. Events going to the workspace webhook are still sent, with the agent as it was when the event happened.
GET /api/conversations
Required permission: conversations:read.
Lists DM conversations handled by AI agents, newest first, with the data each agent collected and no transcript. Each item has the same fields as GET /api/conversations/{id} without messages.
Query parameters
| Field | Type | Required | Accepted Values | Notes |
|---|---|---|---|---|
| stage | string | No | any (default), data_collected, completed | any: every AI conversation, by last message. data_collected: the agent collected at least one value, by when it got the first (data collected before November 2026 has no such time, so those conversations appear only under any and completed). completed: the objective was reached, by when. |
| agentId | string (UUID) | No | Agent publicId | Only this agent. |
| from | string | No | YYYY-MM-DD (UTC) | Default: 30 days before to. Filters the time the stage uses. |
| to | string | No | YYYY-MM-DD (UTC) | Default: today. At most 366 days after from. |
| limit | integer | No | 1 to 100 | Default 25. |
| offset | integer | No | 0 or more | Use it with pagination.hasMore to read the next page. |
curl -H "Authorization: Bearer YOUR_TOKEN" "https://commentkeyword.com/api/conversations?stage=data_collected&from=2026-03-01"GET /api/conversations/{id}
Required permission: conversations:read.
Returns one DM conversation: the contact, the agent and keyword behind it, every field the agent collects (null until collected) and the transcript, oldest message first. The id is the conversationId sent in webhook events. Up to the latest 1,000 messages are returned; messagesTruncated is true when older ones were left out. If the agent was deleted, the conversation is still returned, with agent: null and only the values collected.
Parameters
| Field | Type | Required | Accepted Values | Notes |
|---|---|---|---|---|
| id | string (UUID) | Yes | Path parameter | The conversationId from a webhook event. |
{
"data": {
"id": "8b0c2d1e-5f6a-4b7c-9d8e-1f2a3b4c5d6e",
"instagramUsername": "user123",
"instagramUserId": "17841400000000000",
"status": "ai_active",
"completed": false,
"dataCapturedAt": "2026-03-01T10:29:05.000Z",
"objectiveReachedAt": null,
"handedOffAt": null,
"agent": { "id": "f3a1c9e0-7b2d-4e5f-8a9b-0c1d2e3f4a5b", "name": "Lead Qualifier" },
"keyword": { "id": "2c9d1e7a-3b4f-4a5c-8d6e-7f8091a2b3c4", "keyword": "GUIDE" },
"collectedData": { "email": "[email protected]", "phone": null },
"createdAt": "2026-03-01T10:20:00.000Z",
"lastMessageAt": "2026-03-01T10:30:00.000Z",
"messages": [
{ "sender": "business", "origin": "automation", "text": "Here is your guide!", "attachments": [], "sentAt": "2026-03-01T10:20:00.000Z" },
{ "sender": "contact", "origin": null, "text": "Thanks! It's [email protected]", "attachments": [], "sentAt": "2026-03-01T10:29:00.000Z" }
],
"messagesTruncated": false
},
"meta": { "authType": "pat", "workspaceId": 1 }
}curl -H "Authorization: Bearer YOUR_TOKEN" https://commentkeyword.com/api/conversations/CONVERSATION_IDGET /api/keywords
Required permission: keywords:read.
Results are newest first (by createdAt).
Query Parameters
| Field | Type | Required | Accepted Values | Notes |
|---|---|---|---|---|
| search | string | No | any text | Case-insensitive search in the keyword text. % and _ match literally. |
| status | string | No | active | inactive | Filters by keyword activation state. |
| limit | integer | No | >= 1 | Default 50. Must be a whole number; values above 100 are clamped to 100, invalid values return 400. |
| offset | integer | No | >= 0 | Default 0. Must be a whole number; invalid values return 400. |
curl -H "Authorization: Bearer YOUR_TOKEN" "https://commentkeyword.com/api/keywords?status=active&limit=20&offset=0"POST /api/keywords
Required permission: keywords:write.
commentReplies and dmMessages support personalization placeholders:{{handle}}, {{name}}, and {{namefirst}}.
Keywords are created active unless you send isActive: false. Active keywords count toward the plan's active-keyword limit: when it is reached, creating an active keyword fails with 409 and code: "keyword_limit_exceeded", while a paused one can still be created. Returns 201 with the Keyword object.
Request Body
| Field | Type | Required | Accepted Values | Notes |
|---|---|---|---|---|
| keyword | string | Yes | non-empty | Leading/trailing spaces removed, repeated spaces collapsed, Unicode NFC. Maximum 100 Unicode characters after normalization. |
| matchMode | string | No | contains | exact | Default contains. |
| matchWithoutAccents | boolean | No | true | false | true is accepted only for keywords with Latin accents (400 otherwise). When true, “guía” also matches “guia”. Default false. |
| scope | string | No | global | post_specific | Default global. post_specific matches only assigned posts - see mediaIds and includeNextPost. |
| commentReplies | string[] | No | array of strings | Default []. Variants are trimmed and empty ones removed. Rendered limit: 500 characters per variant, checked only while publicReplyEnabled is true. |
| publicReplyEnabled | boolean | No | true | false | Default: true when commentReplies has a variant. false sends only the DM. true requires at least one commentReplies variant. |
| dmMessages | string[] | Yes | array of strings | Variants are trimmed and empty ones removed; at least one must remain. Rendered DM plus agent conversation hook limit: 1,000 characters. |
| trackLinks | boolean | No | true | false | Default false. Replaces eligible DM links with tracked links. |
| delaySec | integer | No | 1..60 | Deprecated. Accepted for compatibility and stored (default 30), but currently ignored: DMs are sent as soon as the comment is processed. |
| isActive | boolean | No | true | false | Default true. false creates the keyword paused; a paused keyword does not count toward the active-keyword limit. |
| aiAgentId | string | null | No | agent public ID UUID string or null | If set, must refer to a Live agent in the same workspace. |
| mediaIds | string[] | Conditional | array of non-empty strings | Required when scope is post_specific, unless includeNextPost is true. Ignored for global scope. Values are trimmed and deduplicated. |
| mediaUrls | object | No | media ID → Instagram URL | Optional permalink map for selected media IDs. Entries whose URL host is not instagram.com (or a subdomain) are ignored. |
| includeNextPost | boolean | No | true | false | Default false. post_specific only (true with another scope returns 400). Waits for the next publication, adds it to mediaIds, then automatically becomes false. |
curl -X POST https://commentkeyword.com/api/keywords \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"keyword": "pricing",
"matchMode": "contains",
"scope": "global",
"commentReplies": ["Sent it to you, {{namefirst}}!"],
"dmMessages": ["Hey {{namefirst}}, here are the pricing details."],
"trackLinks": true,
"aiAgentId": "a6be1900-8f4f-4ae6-8f4e-48f8b28f0f17"
}'GET /api/keywords/{id}
Required permission: keywords:read.
Path Parameters
| Field | Type | Required | Accepted Values | Notes |
|---|---|---|---|---|
| id | string | Yes | keyword public ID UUID string | Use keyword public ID. |
curl -H "Authorization: Bearer YOUR_TOKEN" https://commentkeyword.com/api/keywords/5f9619c5-daa7-4f2f-ad6f-971f71f8d7f2PATCH /api/keywords/{id}
Required permission: keywords:write.
Partial update: only provided fields are changed. There are no defaults; omitted fields keep their current values. Returns the updated Keyword object.
Message fields can include {{handle}}, {{name}}, and {{namefirst}}.
Path Parameters
| Field | Type | Required | Accepted Values | Notes |
|---|---|---|---|---|
| id | string | Yes | keyword public ID UUID string | - |
Request Body
| Field | Type | Required | Accepted Values | Notes |
|---|---|---|---|---|
| keyword | string | No | non-empty | Leading/trailing spaces removed, repeated spaces collapsed, Unicode NFC. Maximum 100 Unicode characters after normalization. |
| matchMode | string | No | contains | exact | - |
| matchWithoutAccents | boolean | No | true | false | true is accepted only when the keyword has Latin accents. Resets to false automatically when the keyword is changed to one without Latin accents. |
| scope | string | No | global | post_specific | Changing to global removes all assigned posts (manual and auto-added) and stops waiting for the next post. |
| commentReplies | string[] | No | array of strings | Replaces all variants. Trimmed; empty variants are removed. Rendered limit: 500 characters, checked only while publicReplyEnabled is true. |
| publicReplyEnabled | boolean | No | true | false | false sends only the DM and keeps commentReplies. true requires at least one commentReplies variant. If omitted while commentReplies is replaced, it follows whether a variant remains; otherwise the current value is kept. |
| dmMessages | string[] | No | array of strings | Replaces all variants. Trimmed; empty variants are removed and at least one must remain. Combined DM and agent hook limit: 1,000 characters. |
| trackLinks | boolean | No | true | false | Enables or disables tracked links in DM variants. |
| delaySec | integer | No | 1..60 | Deprecated. Accepted for compatibility and stored, but currently ignored: DMs are sent as soon as the comment is processed. |
| isActive | boolean | No | true | false | Activates or pauses the keyword. Activating counts toward the plan’s active-keyword limit (409 keyword_limit_exceeded when full). |
| aiAgentId | string | null | No | agent public ID UUID string or null | If set, must refer to a Live agent in the same workspace. |
| mediaIds | string[] | Conditional | array of non-empty strings | When provided, replaces the whole set of assigned posts, including auto-added ones. Required only when changing a global keyword to post_specific, unless includeNextPost is true. Existing post-specific keywords may use an empty list to become dormant. Ignored when the resulting scope is global. |
| mediaUrls | object | No | media ID → Instagram URL | Optional permalink map, applied only together with mediaIds. Entries whose URL host is not instagram.com (or a subdomain) are ignored. |
| includeNextPost | boolean | No | true | false | post_specific only (true with a global scope returns 400). true starts waiting; false stops a pending wait without removing assigned posts; omission preserves the current setting. Automatically false after a post is found. |
curl -X PATCH https://commentkeyword.com/api/keywords/5f9619c5-daa7-4f2f-ad6f-971f71f8d7f2 \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"isActive": false}'DELETE /api/keywords/{id}
Required permission: keywords:delete.
If the keyword is linked to an AI agent, the first request returns 409 DELETE_CONFIRMATION_REQUIREDwith an impact summary. Review it, then repeat the request with ?confirm=true.
Path Parameters
| Field | Type | Required | Accepted Values | Notes |
|---|---|---|---|---|
| id | string | Yes | keyword public ID UUID string | - |
Query Parameters
| Field | Type | Required | Accepted Values | Notes |
|---|---|---|---|---|
| confirm | string | Conditional | true | Send confirm=true after receiving DELETE_CONFIRMATION_REQUIRED. Only the exact lowercase value true confirms; 1 or True do not. |
Success response (200)
{
"message": "Keyword deleted successfully",
"data": {
"id": "5f9619c5-daa7-4f2f-ad6f-971f71f8d7f2",
"publicId": "5f9619c5-daa7-4f2f-ad6f-971f71f8d7f2"
},
"meta": { "authType": "pat", "workspaceId": 42 }
}Confirmation required (409)
Like every other response, the id values inside details are public IDs.
{
"error": "Conflict",
"code": "DELETE_CONFIRMATION_REQUIRED",
"message": "Keyword \"pricing\" is linked to existing automation records. Confirm deletion to continue.",
"details": {
"keyword": { "id": "5f9619c5-daa7-4f2f-ad6f-971f71f8d7f2", "publicId": "5f9619c5-daa7-4f2f-ad6f-971f71f8d7f2", "text": "pricing" },
"aiAgents": [
{ "id": "a6be1900-8f4f-4ae6-8f4e-48f8b28f0f17", "publicId": "a6be1900-8f4f-4ae6-8f4e-48f8b28f0f17", "name": "Sales Agent", "isActive": true }
],
"dmJobs": { "total": 40, "pending": 2, "sent": 36, "failed": 1, "cancelled": 1, "other": 0 },
"usageLogsCount": 40,
"conversationsCount": 18,
"deleteEffects": {
"pendingDmJobsWillBeCancelled": true,
"dmJobKeywordReferencesWillBeDetached": true
}
}
}curl -X DELETE -H "Authorization: Bearer YOUR_TOKEN" https://commentkeyword.com/api/keywords/5f9619c5-daa7-4f2f-ad6f-971f71f8d7f2Error Format
{
"error": "Bad Request",
"message": "dmMessages must contain at least one non-empty DM message variant"
}Every error has error and message. Some errors add a machine-readable code, and DELETE_CONFIRMATION_REQUIRED also adds details. Match on code rather than on message text.
409 Conflict cases
code: "keyword_limit_exceeded"(POST /api/keywords, orPATCHwithisActive: trueon a paused keyword): the plan's active-keyword limit has been reached. Pause or delete an active keyword to make room.code: "DELETE_CONFIRMATION_REQUIRED"(DELETE /api/keywords/{id}): the keyword is linked to an AI agent. Reviewdetails, then repeat with?confirm=true.- Overlapping trigger, no
code(POST /api/keywords,PATCH /api/keywords/{id}): the trigger matches another keyword's trigger, ignoring case, and ignoring accents when either keyword hasmatchWithoutAccentson. A global keyword conflicts with any overlapping keyword; two post_specific keywords conflict only when they share a post. - Related records, no
code(DELETE /api/keywords/{id}): other records still reference the keyword, so it could not be deleted safely.
{
"error": "Conflict",
"code": "keyword_limit_exceeded",
"message": "Keyword limit reached. Your current plan allows 3 active keywords. Deactivate a keyword to make room."
}{
"error": "Conflict",
"message": "This keyword already exists or overlaps an accent variant. Only one automation can be configured for the same trigger."
}Common status codes: 200, 201, 400, 401, 403, 404, 409, 500.