UGC Comments API

Follow

Agility User Generated Content has been extended to support commenting as a built in feature. Comments can be enabled on a content definition, or UGC Record Type. When Comments are enabled a new UGC Comment Record Type will be created to store the comment content items.

Comment content items use the same API calls as standard UGC records for saving (SaveRecord) and retrieving records (GetRecord/SearchRecords). An additional helper method has been added to help search for comments as well and produce comment hierarchies when comments are expected to be threaded. This new call is "SearchComments" and you can see the method signature below.

Object Types

Base Comments
Object

Below is the base Comment Object Structure

var comment = {
   ID: -1,
   RecordTypeName: "CommentsForBlogEntries",
   RelatedContentID: 123,
   Name: "MyName",
   Comment: "My Comment",
   ParentRecordID: -1
};

CommentSearchArg
Object

API.CommentSearchArg = function() {
   RelatedContentID: -1;
   PageSize: 20;
   RecordOffset: 0;
   SortedField: "CreatedOn";
   SortDirection: "DESC";
   RecordTypeName: "";
   CacheKey = null;
   OtherStates = [];
   State = API.RecordState.Published;
   FileStorage = API.FileStorage.RelativeURL;
   Columns = [];
}

 

API Samples (JS)

The comments API is, by design, only available in the JavaScript SDK and there is no .NET API alternative.

Agility.UGC.API.SearchComments(commentSearchArg, callback)
The SearchComments API call will return a list of comments based on the search criteria. The call is very similar to the SearchRecords call and the CommentSearchArg object share many of the same properties. The Primary property that must be set it the RelatedContentID property which is the link between the comments and the item being commented on.
var commentSearchArg = {
    RelatedContentID: 1234, //ID you are pulling comments for
    PageSize: 10,
    RecordOffset: 0,
    SortedField: "CreatedOn",
    SortDirection: "asc",
    RecordTypeName: "CommentRecordTypeName"
 };
 
Agility.UGC.API.SearchComments(commentSearchArg, function (data) {
    if (data.ResponseType == 0) {
        //Render Comment Data
        //data.ResponseData.Records
        //data.ResponseData.TotalRecords
    }
});
 
Agility.UGC.API.SaveRecord(comment, callback)
Saving a comment is done by performing the same SaveRecord call as you would with any UGC item. The comment record must be in a specific format though as you can see from the code example below
var comment = {
    ID: -1,
    RecordTypeName: "CommentsForBlogEntries", //record type/content reference name
    RelatedContentID: 123, // content item to link to
    ParentRecordID: null, //for nested comments
 
    //Default Comment Fields
    Name: "My Name", 
    Comment: "This is my comment
};
 
Agility.UGC.API.SaveRecord(comment, function (data) {
    alert("Comment Submitted Successfully");
});
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.