3

I would like to notify a specific set of people when posting a message with Yammer's REST API. The desired effect should be the same as "Add people to notify" in the native web application: enter image description here

After some research with the REST API documentation, i found the direct_to_id field in the request data object.

direct_to_id - Send a private message directly to the user indicated.

I'm not sure what this attribute actually does, so I tried the following:

var data = {
    "body": "test message",
    "group_id": XXXXXX, //a valid group id
    "direct_to_id": XXXXXXXXXX, //a valid user id 
};

but after I add the "direct_to_id" field to my post, i get a 400 (bad request) error. I also don't know if this method works with notifications to multiple users.

Chuanqi Sun
  • 1,123
  • 14
  • 26

1 Answers1

6

Ok, i figured it out by reverse engineering the yammer embed widget. When posting a message with people to be notified, yammer embed set a "cc" field in the web form, according to fiddler: enter image description here

In javascript, simply do this:

var data = {
    "body": "test message",
    "group_id": XXXXXX,
    "cc": "[[user:XXXXXX]],[[user:XXXXXX]]",
};

This approach is not documented in Yammer's API so I'm not sure if it will be supported in the future. In the meanwhile, I really wish that Yammer had better documentation. It would save developers lots of time and trouble.

Chuanqi Sun
  • 1,123
  • 14
  • 26
  • What are the primary issues you've had that you think could be solved with better documentation? What would you like to see? – Marco Aug 18 '14 at 22:29
  • 2
    I would like to see "How to tag specific recipients" in the documentation under REST API --> messages. It would also benefit developers a lot if the documentation has more example code. – Chuanqi Sun Aug 21 '14 at 18:22
  • Agreed on more examples. It's on our list. The reason tagging recipients isn't there is because it's not officially supported. You've essentially reverse engineered it above. But you use it at your own risk. If we want to support it as a thing that was usable for third parties, we would probably give it a better API first :) – Marco Aug 22 '14 at 00:05
  • I'm still wondering what the "direct_to_id" property does. How is it different from "notify specific people?" – Chuanqi Sun Aug 25 '14 at 15:51
  • 1
    The Yammer API uses the same endpoint for group messages and private messages. Private messages used to be called direct messages. direct_to_id refers to the list of users to add to a private message. The cc field refers to users who are notified on group messages. I hope that makes sense. – Marco Aug 25 '14 at 21:38
  • 1
    FYI, the meaning of "notified" has changed a bit over time as well. Even when using the cc field, it doesn't cause a notification to be sent. Instead it adds the conversation to the user's inbox, and the inbox count goes up. The notification count is now reserved for activity feed items. – Marco Aug 25 '14 at 21:40
  • This is certainly a thing that it would be useful to see actively supported if we want to offer a more complete Yammer integration in our software. – glenatron Nov 24 '14 at 11:33