Home

Yammer REST API - post message with attachment

%3CLINGO-SUB%20id%3D%22lingo-sub-698162%22%20slang%3D%22en-US%22%3EYammer%20REST%20API%20-%20post%20message%20with%20attachment%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-698162%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20trying%20to%20integrate%20Yammer%20REST%20API%20to%20post%20a%20message%20into%20a%20group%20with%20attachment%20as%20per%20documentation%20-%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdeveloper.yammer.com%2Fdocs%2Fmessages-json-post%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdeveloper.yammer.com%2Fdocs%2Fmessages-json-post%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20is%20working%20for%20me%20so%20far%20-%26nbsp%3B%3C%2FP%3E%3CUL%3E%3CLI%3EAble%20to%20post%20a%20message%20without%20an%20attachment%20using%20postman%3C%2FLI%3E%3CLI%3EAble%20to%20post%20a%20message%20without%20an%20attachment%20using%20JAVA%20program%3C%2FLI%3E%3CLI%3EAble%20to%20post%20a%20HTML%20message%20without%20an%20attachment%20using%20postman%20(using%20%22Announcements%22%20feature)%3C%2FLI%3E%3CLI%3EAble%20to%20post%20a%20HTML%20message%20without%20an%20attachment%20using%20JAVA%20program%20(using%20%22Announcements%22%20feature)%3C%2FLI%3E%3CLI%3EAble%20to%20post%20a%20HTML%20message%20%3CSTRONG%3Ewith%20an%20attachment%3C%2FSTRONG%3E%20using%20postman%20(using%20%22Announcements%22%20feature)%3C%2FLI%3E%3C%2FUL%3E%3CP%3EBut%2C%20I%20am%20NOT%20able%20to%26nbsp%3B%3C%2FP%3E%3CUL%3E%3CLI%3EPost%20a%20HTML%20message%20%3CSTRONG%3Ewith%20an%20attachment%3C%2FSTRONG%3E%20%3CSTRONG%3Eusing%20JAVA%20program%3C%2FSTRONG%3E%26nbsp%3B%3C%2FLI%3E%3C%2FUL%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBelow%20is%20code%20snippet%20-%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CEM%3EFile%20fileToUse%20%3D%20new%20File(%22logo.png%22)%3B%26nbsp%3B%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3EFileBody%20fileBody%20%3D%20new%20FileBody(fileToUse%2C%20ContentType.MULTIPART_FORM_DATA)%3B%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3EStringBody%20stringBody1%20%3D%20new%20StringBody(%2212345%22%2C%20ContentType.MULTIPART_FORM_DATA)%3B%3C%2FEM%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CEM%3EMultipartEntityBuilder%20builder%20%3D%20MultipartEntityBuilder.create()%3B%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3Ebuilder.addPart(%22attachment1%22%2C%20fileBody)%3B%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3Ebuilder.addPart(%22group_id%22%2C%20stringBody1)%3B%3C%2FEM%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CEM%3EHttpEntity%20entity%20%3D%20builder.build()%3B%3C%2FEM%3E%3C%2FP%3E%3CP%3E%3CEM%3EhttpPost.setEntity(entity)%3B%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3EHttpResponse%20response%20%3D%20client.execute(httpPost)%3B%3C%2FEM%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDid%20anyone%20face%20this%20issue%3F%20appreciate%20your%20thoughts%20on%20this.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-698162%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAPI%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EREST%20API%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EYammer%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Highlighted
Senthil1986
Occasional 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.

 

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
17 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
flashing a white screen while open new tab
cntvertex in Discussions on
11 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
28 Replies