Skip to content Skip to sidebar Skip to footer

I Can Not Post Yammer Via Rest Api Using Ajax

Hi I would like to Create JavaScript app which post message to Yammer, using Yammer REST API. but I have a limitation. I Can Not use Yammer SDK to post message. so, I written code

Solution 1:

I've tried your code and found two serious issues that might cause your problems:

  1. You should use https://api.yammer.com/api/v1/messages.json instead of https://www.yammer.com/api/v1/messages.json

  2. Don't JSON.stringify your data as it's supposed to be sent as just that, JSON, not as a string.

Hope it helps!

Solution 2:

Thaks, Juan and Mark. I changed my code in your advice. and code working now. That is here.

functionsendData(msgbody) {

    //var messagebody = new FormData();var testMessage = {
        body: msgbody,
        group_id: 4627253
    }

    var jsonObj = JSON.stringify(testMessage);

    accToken = responseObject.access_token.token;
    var accAuthHead = 'Bearer '+ accToken;

    $.ajax({
        url: "https://api.yammer.com/api/v1/messages.json",
        type: 'POST',
        headers: {
            'Authorization': accAuthHead.toString(),
        },
        data: testMessage,

        success: function (data) {
            alert("ajax post success.");
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert("There was an error with the request." + textStatus + XMLHttpRequest.toString());
        }
    });   
}

but It is a little funny. firstly, I tryed testing this code in "Internet Explorer 10". it did Not work. secondly, I use Chrome(versio 39.0.2171.95 m), it was worked!

I am little confused. Why I get this result?

Post a Comment for "I Can Not Post Yammer Via Rest Api Using Ajax"