0

I cannot figure out what fields or tags Yammer expects for my post variables when trying to post an attachment using the messages API. Yammer documentation says:

"The first method is the easiest, simply use file form elements with names attachment1 through attachment20. If there are a several attachments or the attachments are large it may take some time for a message to POST causing your application to appear to hang."

I read through the specification they said they are using RFC 1867 but still cannot get a simple text file or url (shown below) to post as an attachment. If I take out the attachement1 variable in the post array $jtext then the body of the message will post as expected.

I'm also not entirely sure that this should be a multi-dim array.

Any help is appreciated!

This is written in PHP.

        $jtext=array("body"=>$text,
                     "attachment1"=>array("type"=>"file","name"=>"https://www.google.com/"));
        
        $url="https://www.yammer.com/api/v1/messages.json";
        curl_setopt($ch, CURLOPT_POST,1);
        curl_setopt($ch, CURLOPT_POSTFIELDS,$jtext);
        curl_setopt($ch, CURLOPT_URL,$url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer '.$accToken,'Content-Type: multipart/form-data'));        
        curl_setopt($ch, CURLOPT_TIMEOUT, 60);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
        $result = curl_exec($ch);
Community
  • 1
  • 1
chaz
  • 1
  • 4

1 Answers1

0

I have had better luck using the pending attachments resource. It's 2 steps, so it might help you to see where you are getting stuck.

Try to send the file to the pending attachments resource first with POST https://www.yammer.com/api/v1/pending_attachments.

If it was successful, you receive an id for the attachment, and then just send the id as pending_attachment1 -pending_attachment20 or however many you are attaching with the new message endpoint.

  • 1
    I don't suppose you would care to elaborate at all on the process you went through here? I can't figure out what pending_attachments is actually expecting to receive and nothing I send seems to work. Question here: http://stackoverflow.com/questions/30221415/yammer-attachments-how-do-i-use-the-pending-attachments-call – glenatron May 14 '15 at 14:54