Yammer REST API - post message with attachment

Visitor

Hi,

 

I am trying to integrate Yammer REST API to post a message into a group with attachment as per documentation - 

https://developer.yammer.com/docs/messages-json-post

 

What is working for me so far - 

  • Able to post a message without an attachment using postman
  • Able to post a message without an attachment using JAVA program
  • Able to post a HTML message without an attachment using postman (using "Announcements" feature)
  • Able to post a HTML message without an attachment using JAVA program (using "Announcements" feature)
  • Able to post a HTML message with an attachment using postman (using "Announcements" feature)

But, I am NOT able to 

  • Post a HTML message with an attachment using JAVA program 

 

Below is code snippet - 

 

File fileToUse = new File("logo.png"); 
FileBody fileBody = new FileBody(fileToUse, ContentType.MULTIPART_FORM_DATA);
StringBody stringBody1 = new StringBody("12345", ContentType.MULTIPART_FORM_DATA);

MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addPart("attachment1", fileBody);
builder.addPart("group_id", stringBody1);

HttpEntity entity = builder.build();

httpPost.setEntity(entity);
HttpResponse response = client.execute(httpPost);

 

Did anyone face this issue? appreciate your thoughts on this.

 

0 Replies