3

I know I can add comments through the UGC web service by 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 and likes and dislikes? Is this documented anywhere?

MTIA

John

Daniel Neagu
  • 1,711
  • 11
  • 13
John
  • 271
  • 1
  • 5

1 Answers1

5

The command for uploading ratings is '/Ratings' instead of '/Comments'. The JSON is different too, of course. In the code below, I don't write out the JSON manually, instead I construct 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());
Quirijn
  • 3,529
  • 12
  • 28
  • 1
    Would be nice to add the fact that the WebServiceClient is not public API in UGC and might change in the future. – Daniel Neagu Feb 19 '13 at 13:21
  • Thanks for the example Quirijn! – John Feb 20 '13 at 09:13
  • Thanks Daniel. Do you have any more info on this? Are there plans to make it public? Do you know if any changes are likely in the near future? – John Feb 20 '13 at 09:15
  • At this moment, there are no plans to make it publicly available but you can rest assured because there are no changes scheduled for that area for the next two releases. – Daniel Neagu Feb 20 '13 at 10:46
  • Thanks Daniel. Much appreciated. – John Feb 20 '13 at 10:51