Jul 05 2017 12:14 PM
I have code that can post and delete messages via the rest API. Now that Yammer allows editing of posts, I would like to update posts via the REST API as well. Is this possible?
I haven't seen any documentation and I can't get it to work yet. I have seen via Fiddler that the UI does a REST call such as:
PATCH https://www.yammer.com/api/v2/messages/<messageid> Authorization: Bearer <token> Accept: application/json, text/javascript, */*; q=0.01 (other headers) {"body":"<simple body text>","recipients":[],"references":{"ogos":[]}}
If I try this manually via Postman I get a 404. Is this because it isn't supported via the REST API or do I just need to work more on getting the headers/body correct? I realize that the UI is providing several headers values in addition to Authorization that may "authorize" the request like cookies, browser-token, oauth_token, and _session, but I know that my simple POST/DELETE calls can get by with just the Authorization header.
Jul 05 2017 12:31 PM - edited Jul 05 2017 12:44 PM
Well, I posted too soon. I figured it out. I somehow had a typo in the URL and was posting to v1/messages instead of v2/messages.
Jul 12 2017 10:19 AM
Documented in a dev blog post [1], there isn't a supported endpoint for editing posts. The endpoint you found is undocumented, and therefore might change at any point without notice.
1- https://developer.yammer.com/blog/edit-posts-whats-changing-whats-staying-the-same
Aug 22 2017 05:44 AM
Jun 12 2018 02:24 AM
Hi,
By any chance, is there any information about REST api for edit comments functionality ?.
Thanks,
Guru
Sep 12 2018 02:17 AM
Hi,
I am evaluating Yammer for my company need, any chance to share the code you've developed to post and delete via API ?
thanks
Alberto
Sep 12 2018 12:20 PM - edited Sep 12 2018 12:24 PM
I would also really like to know how you implemented your edit solution.
function editComment(id) {
yam.platform.request({
url: "https://api.yammer.com/api/v2/messages/"+id,
method: "PATCH",
data: {
"body" : "Edited comment"
},
success: function (res) { //print message response information to the console
alert("The request was successful.");
console.dir(res);
},
error: function (res) {
alert("There was an error with the request.");
console.log(res)
}
})
}
When using "https://api.yammer.com/api/v2/messages/", I get 2 errors. First, 503 (Service Unavailable) and a "Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource." error.
But when I use "https://www.yammer.com/api/v2/messages/", I don't get the 503 error, only the cross domain one.
This is strange, because I can get messages from Open Graph Objects (OGO), post comments and replies and create OGO at the same time. I don't know why I get this cross domain error only with this endpoint.
Am I doing it all wrong? Because it works for everything else.
I also know that officially, there is no endpoint
Sep 12 2018 12:48 PM
Sep 13 2018 07:43 AM
SolutionThere you go
To add a comment :
function addComment() {
yam.platform.request({
url: "https://api.yammer.com/api/v1/messages.json",
method: "POST",
data: {
"body" : "Commment Content",
"group_id": "GroupID",
"replied_to_id": "commentID",
"og_url": "URL of current page",
"og_title": "Title of the Open-Graph Object",
"og_description": "OGO description",
"og_private": "true"
},
success: function (res) { //print message response information to the console
alert("The request was successful.");
console.dir(res);
},
error: function (res) {
alert("There was an error with the request.");
console.log(res)
}
})
}
All the parameters starting with"og_" are to create an open graph object which links the comment with a page. If you don't want one, just don't use any of the "og_" fields. Also, you can post directly to a group by using "group_id". If the group is set to private and you want the OGO to also be private, set true to "og_private".
And if your comment is a reply to an other comment, get that first comment id, then use "replied_to_id".
To delete comments :
function deleteComment(id){
yam.platform.request({
url: "https://api.yammer.com/api/v1/messages/"+id,
method: "DELETE",
success: function (res) { //print message response information to the console
alert("The request was successful.");
console.dir(res);
},
error: function (res) {
alert("There was an error with the request.");
console.log(res)
}
})
}
It is very straightforward. Pass the id of the comment you want to delete and there you go! In case of success, the "console.dir(res);" command should return nothing, because the object would be deleted. But you can do w/e you want in the success and error sections.
Sep 13 2018 10:08 PM
Sep 09 2019 08:30 AM - edited Sep 09 2019 08:31 AM
Same issue here, about almost an year, and the same error persists, did you figured out any solution to editing a message via API?
Analising the Yammer with the fiddler i saw that yammer uses an version 2 of the api
PUT https://www.yammer.com/api/v2/messages/ HTTP/1.1
and send the data in JSON format as follows:
{"content_state":{"blocks":[{"key":"0","text":"reply reply","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}}],"entityMap":{}},"recipients":[],"references":{"ogos":[]}}
But i cannot replicate this behavior on my WebPart (yes, I using SPFx framework to implement a webpart that perform some integration with Yammer)
Best Regards
Sergio.
May 20 2020 09:00 AM
@Charles Pauze-Robert I tried your code using "PATCH" but its not working for me and giving the same error which you were facing . Do you succeed in editing messages via API ? If yes would it be possible to share the code or some more hints ?
thanks
Nov 18 2021 07:58 AM