Using the Tridion UGC Web Service to Add Grades

I know I can add comments through the UGC web service using something like the following: -

WebServiceClient ugcCall = new WebServiceClient();

string ugcData = "{ \"d\" :{\"Content\":\"" + comment + "\",\"Status\":2,\"ItemPublicationId\":\"" + PublicationId + "\",\"ItemId\":\"" + itemid + "\",\"ItemType\":\"16\",\"Id\":0,\"ModeratedDate\":\"\",\"LastModifiedDate\":\"\",\"CreationDate\":\"\",\"Score\":0,\"Moderator\":\"\",\"User\":{\"Id\":\"ACME%5Cjbloggs\",\"Name\":\"Joe Bloggs\"}}}";

string result = ugcCall.UploadString("/Comments", "POST", ugcData);

      

My question is what is the syntax for adding ratings, likes and dislikes? Is this documented anywhere?

MTIA

John

+3


source to share


1 answer


The command to load ratings is '/ Ratings' instead of '/ Comments'. Of course, JSON is different too. In the code below, I am not writing the JSON manually, instead I create a simple Rating object and use the JavascriptSerializer to convert it to JSON:



TcmUri tcmUri = new TcmUri(itemUri);
WSR_ContentDelivery.User user = new WSR_ContentDelivery.User { Id = GetUserId() };
WSR_ContentDelivery.Rating rating = new WSR_ContentDelivery.Rating
{
  CreationDate = DateTime.UtcNow,
  LastModifiedDate = DateTime.UtcNow,
  ItemPublicationId = tcmUri.PublicationId,
  ItemId = tcmUri.ItemId,
  ItemType = tcmUri.ItemTypeId,
  RatingValue = ratingValue.ToString(),
  User = user,
  Id = "0"
};

JavaScriptSerializer oSerializer = new JavaScriptSerializer();

WSClient.UploadString("/Ratings", "POST", "{d:" + oSerializer.Serialize(rating) + "}", GetUserId());

      

+5


source







All Articles