Rest API for Delete Yammer Comments
Yammer is providing Documentation on Rest API and they are very proactive in updating those over time period. I was working on rest API for delete yammer comment in my SharePoint site using jQuery.
Rest API : https://www.yammer.com/api/v1/messages/:message_id
here, message_Id : numeric value of message id
Method : Delete
Let me explain this with one example :
function deleteComment(MessagePostId) {
var result = confirm("Are you sure you want to delete this Comment?");
if (result) {
yam.platform.request({
url: "https://api.yammer.com/api/v1/messages/" + MessagePostId,
method: "DELETE",
async: false,
beforeSend: function (xhr) { xhr.setRequestHeader('Authorization', token) },
success: function (res) {
alert("The Comment has been deleted.");
//Code to remove item from array and display rest of the comment to screen
},
error: function (res) {
alert("Please try again after some time.");
}
})
}
}
Yeah that's it..!! This will remove a yammer message if you either
(1) have posted the message yourself
(2) be an administrator of the group the message was posted to or
(3) be an admin of the network the message is in.
But while deleting comments I figure out that if I delete comment rigorously and when it comes to 3rd comment it throws an error in console "Rate Limit due to excessive requests". But after few seconds if I tried to delete, it works fine for next two comments. At the end I found that I am hitting rate limits which prevents multiple deletion requests from a regular user like those which you've hit. The API is designed for client applications where you perhaps make an occasional deletion, but aren't deleting in bulk.
To handle rate limits, you need to update your code to check the response value in one variable. If it's an HTTP 429 response then you are being rate limited and need to wait before retrying the original request.
Woohhh.. Thanks for sharing.
ReplyDelete