Question

I'm just trying to run a little prototype that posts UGC comments using the UGC web service.

The code example is below. I'm getting a 403 response from the web service which indicates I'm not authorised to use the service so I presume I need to create an authentication header? Does anybody have any examples of how to post comments using the UGC web service?

string ugcData = "{d\":{\"Content\":\"FROM WEB SERVICE\",\"Status\":2,\"ItemPublicationId\":\"68\",\"ItemId\":\"17805\",\"ItemType\":\"16\",\"Id\":0,\"ModeratedDate\":\"\",\"LastModifiedDate\":\"\",\"CreationDate\":\"\",\"Score\":0,\"Moderator\":\"\",\"User\":{\"Id\":\"DOMAIN%5Cbsmith\",\"Name\":\"Bill Smith\"}\"}";

WebServiceClient ugcCall = new WebServiceClient();

ugcCall.UploadString("/PostData", "POST", ugcData);

MTIA.

John

Was it helpful?

Solution

You should try to post on the Comments collection:

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

Then you will see that you're missing the CreationDate, moment in which you need to add to your entity something like:

\"CreationDate\":\"/Date(1359457694472)\"

(I have not actually checked if you need more quotes in there). For the format of the date in a JSON string check the odata specs.

If you still have problems, try to change DOMAIN%5Cbsmith to another dummy value ('test' for example).

If that is not enough then maybe you can look at the logs generated by the UGC WebService and try to make-out some stack-trace.

One more thing to notice here: the UGC properties need to be defined correctly in the Web.config in order for the post to even happen.

Hope this helps.

OTHER TIPS

I've used the same approach as you are following, namely using a generated proxy for the UGC web service. To create the correct json we used the standard .NET JavaScriptSerializer. This makes the code a bit easier to read, I think.

Here is a code snippet, maybe it helps a bit. Of course you need to make sure the variables are set.

 WSR_ContentDelivery.User user = new WSR_ContentDelivery.User
 {
        Id = GetUserId(),
        Name = username,
        EmailAddress = email,
        ExternalId = website
 };

 WSR_ContentDelivery.Comment comment = new WSR_ContentDelivery.Comment
 {
        CreationDate = DateTime.UtcNow,
        LastModifiedDate = DateTime.UtcNow,
        ItemPublicationId = tcmUri.PublicationId,
        ItemId = tcmUri.ItemId,
        ItemType = tcmUri.ItemTypeId,
        Content = content,
        User = user,
        Status = Statuses.SubmittedNeedsModeration,
        Score = 0
 };

 JavaScriptSerializer serializer = new JavaScriptSerializer();
 return WSClient.UploadString("/Comments", "POST", "{d:" + 
        serializer.Serialize(comment) + "}", user.Id);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top