user3125731 user3125731 - 5 months ago 61x
Javascript Question

How to embed yammer private messages on my website?

I know how to embed a feed which has a certain ID. I already did it. Now I'd like to implement the following functionality: If a user receives a private message, it will appear on an embedded feed. The best option in my opinion would be to embed the whole "chat window", but I didn't find a single code sample on the web. How can I do that?


You cannot really embed private mssages like you can with feeds, because Yammer's REST APIs (incl. private messages) require authentication via OAuth 2.0. That means you have to create a Yammer API application which will ask your users to log in and allow you to access their messages. The overall concept of that described in their documentation here and here.

Yammer provides several SDKs you can use, one of them is the Javascript SDK. I pieced togehter a simple example of how you can ask users to log in and then it will display their private messages. Mind you, this is a very simple solution, I just tested it on a single one-to-one conversation.

    <script type="text/javascript" data-app-id="YOUR-APP-CLIENT-ID" src=""></script>
<span id="yammer-login"></span>
<div id="messages"></div>
yam.connect.loginButton('#yammer-login', function (resp) {
    if (resp.authResponse) {
      document.getElementById('yammer-login').innerHTML = 'Welcome to Yammer!';

var msgdiv = document.querySelector("#messages");

  function(response) {
    if (response.authResponse) {
      console.log("logged in");
      var myId = response.authResponse.user_id;
        url: "messages/private.json",
        method: "GET",
        success: function (response) {
            console.log("The request was successful.");
            var usernames = {};
                if(ref.type === "user") {
                    usernames[] = ref.full_name;
                var msg = document.createElement("span");
                msg.innerHTML = usernames[message.sender_id] + ": " + message.body.parsed + "<br/>";
        error: function (response) {
            console.log("There was an error with the request.");
    else {
      console.log("not logged in")

The response from the messages/private.json API endpoint is a JSON file that you can go through. It includes information about the message and the users involved in the conversation.