tridiontridion-2011tridion-content-deliveryugc

Using the Tridion UGC web service to add ratings


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


Solution

  • 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());