Skip to content

API Comment ​

Post, read, update and delete comments on entries. Part of the Webservice module since v10.0.0, before it was a separate package for ExpressionEngine 2

WARNING

Since v10.0.0 the Comment API is part of the module. The separate Webservice Comment API package (ExpressionEngine 2 only) is discontinued (Breaking change). The Comment module of ExpressionEngine needs to be installed.

Enable the API ​

The Comment API is off by default. Enable it with Comment API in the API settings, then enable the API for a member on the member page.

The Comment API follows the rules of the comment form of ExpressionEngine, but it is an implementation of the Webservice module. After updating ExpressionEngine, check that it still works as you expect.

Endpoints ​

MethodURLEndpoint
POST/webservice/commentcreate_comment
GET/webservice/commentread_comment
PUT / PATCH/webservice/commentupdate_comment
DELETE/webservice/commentdelete_comment

Permissions ​

The ExpressionEngine permissions of the member apply, like on the site:

EndpointPermission
create_commentPost comments, and the comment settings of the channel and the entry
read_commentOpen comments for everybody who can call the endpoint. Comments with another status, and the email and IP address, need Moderate comments
update_commentThe text: Edit all comments, or your own comment with Edit own comments (within the comment edit time limit). The status: Moderate comments
delete_commentDelete all comments, or your own comment with Delete own comments

create_comment ​

A comment is always posted as the member of the request, with its name and email. Without credentials (a public endpoint) it is posted as a guest, when the channel does not require membership.

NameDescription
entry_idThe entryRequired
commentThe commentRequired
notify_mey to get an email of the new comments on the entryOptional
nameThe name of a guestRequired for guests
emailThe email of a guestRequired for guests when the channel requires an email
url, locationThe url and location of a guestOptional
page_urlThe url of the page with the comments, used in the notification emails. Default: the comment url (or url) of the channel with the url titleOptional

Like the comment form of ExpressionEngine:

  • comments must be allowed for the channel and the entry, and not be expired (with the comment moderation override an expired comment is moderated);
  • the comment time lock, the duplicate check, the maximum length and the banned names and emails apply (not for a Super Admin);
  • the comment is pending when the channel moderates comments, unless a role of the member is excluded from moderation;
  • the spam service of ExpressionEngine checks the comment when the Spam module is installed;
  • the notifications of the administrators, the author and the subscribers are sent;
  • the hooks of ExpressionEngine are called: insert_comment_start, insert_comment_insert_array and insert_comment_end.

The API has no captcha, the rate limiting protects a public endpoint against spam.

bash
curl -X POST 'https://your-domain.com/index.php/webservice/comment' \
  -H 'Authorization: Bearer <shortkey>' \
  -H 'Content-Type: application/json' \
  -d '{"data":{"entry_id":12,"comment":"Nice article!"}}'
json
{
  "success": true,
  "message": "Comment posted",
  "metadata": {"id": 5},
  "data": [{"comment_id": 5, "entry_id": 12, "author_id": 4, "name": "John", "comment": "Nice article!", "comment_date": 1792427824, "edit_date": 0, "status": "open"}]
}

The status is open, pending (moderated) or spam.

read_comment ​

NameDescription
entry_idOne or more entry ids, an array or comma separatedOptional
comment_idOne or more comment idsOptional
author_idOne or more member idsOptional
statuso (open, default), c (closed), p (pending), s (spam), comma separated. Other than open needs Moderate commentsOptional
orderbycomment_date (default), comment_id or entry_idOptional
sortasc (default) or descOptional
limit, offsetPaging, default 25, maximum 100Optional

update_comment ​

NameDescription
comment_idThe commentRequired
commentThe new textOptional
statusopen, closed, pending or spam (or o, c, p, s)Optional

delete_comment ​

NameDescription
comment_idThe commentRequired

Errors ​

HTTP statusDescription
401Not logged in (update, delete, or a channel that requires membership)
403No permission, or comments are not allowed or expired
404The entry or comment does not exist
422The data is not valid, errors has a message per field
429The comment time lock of the channel
501The Comment module of ExpressionEngine is not installed

Hooks ​

webservice_create_comment_start, webservice_create_comment_end (comment_id), webservice_read_comment_end (the comments, the return value replaces them), webservice_update_comment_end (comment_id) and webservice_delete_comment_end (comment_id).

Changes in v10.0.0 ​

  • Part of the module, for ExpressionEngine 7+, off by default (Comment API in the settings).
  • A comment is posted as the member of the request; member_id is not accepted.
  • The rules of the comment form of ExpressionEngine apply: roles and permissions, moderation, spam, notifications.
  • read_comment only returns open comments without the email and IP address, unless the member can moderate comments. Before, it returned all comments with the email and IP address.
  • search_comment is part of read_comment.