yammer

Yammer REST API - Get all messages older message before newer and therefore cannot return older_than


We are trying to retrieve all messages from a specific group in Yammer, but are in some cases having issues retrieving older messages.

Example:

In a perfect world where every post in a Yammer group is added synchronous and not being commented or liked, we can easily retrieve every message using the parameter older_than:id

However, if an older message is commented it seems that this message is then returned in between the newer messages.

This can result in edge cases where an older message is the last item in the messages array and when using that message items id to query older messages we only get messages older than that and risk not returning newer messages in between.

We are using the REST API /messages/in_group/[:group_id].json which is documented here:

https://developer.yammer.com/docs/messagesin_groupgroup_id

Code sample:

We have trimmed down the code sample to illustrate our approach for retrieving all messages.

yam.platform.request({
url: 'messages/in_group/' + vm.webpartSettings.feedId + '.json?threaded=true' + (oldest ? ('&older_than=' + oldest) : ''),
method: 'GET',
success: function (response) {

    // Parse messages
    var lastId;
    var parsedMessages = response.messages.map(function (m, i) {
        if (i === (response.messages.length - 1)) {
            lastId = m.id;
        }

        return {
            id: m.id,
            author: response.references.filter(function (r) {
                r.type === 'user' && r.id === m.sender_id;
            })[0],
            date: new Date(m.created_at),
            url: m.web_url,
            image: getImageFromAttachments(m.attachments),
            text: m.body.parsed,
            likes: m.liked_by.count,
            likedByCurrentUser: m.liked_by.names.some(function (u) {
                return u.user_id === response.meta.current_user_id;
            })
        };
    }).filter(function (m) {
        return m.image;
    });

    vm.messages = vm.messages.concat(parsedMessages);

    // If there are more messages get them, otherwise render the grid
    if (response.meta.older_available) {
        getAndParseMessages(lastId);
    } else {
        // render method removed       
    }
},
error: function (response) {
    // error method removed
}
});

When calling the API with query param threaded:true we expected to retrieve the thread starter (first message) for each thread and having them sorted by created date and not by "latest activity".

Does anyone know how this functionality was intended to use to query older messages or are we missing something?

Update

I created a Uservoice for Yammer to be integrated with the full Office 365 developer platform. You can upvote it here: https://yammer.uservoice.com/forums/399627-yammer/suggestions/36474385-integrate-yammer-in-the-full-office-365-developer


Solution

  • You should use the Data Export API for bulk data tasks like this. The REST API is designed for user client applications, and querying data in the pattern you are following is one of the constraints.