How can I post /attach a file on Yammer using REST Api?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2018 07:42 AM
Below is the code snap... Please let me know is that possible, because the file is posted using Postman.
var target = new GlideRecord('sys_attachment');
target.addQuery('sys_id','432122c326a4f8b15f8121f3b718110c751');
target.addQuery('table_sys_id', 'ef43c6d40a41245700c77f9bf387afe3');
target.query();
gs.print(target);
while(target.next())
{
/*
var sa = new GlideSysAttachment();
var binData = sa.getBytes(target);
var base64Data = GlideStringUtil.base64Encode(binData);
*/
var clientToken = '0818014-pP7Fgt8w4g92uYFgeWABUGYDks';
var request = new sn_ws.RESTMessageV2();
request.setHttpMethod('post');
request.setRequestHeader("Authorization","Bearer"+clientToken);
//request.setRequestHeader("Accept","application/form-data");
request.setRequestHeader('Content-Type','application/form-data');
request.setEndpoint('https://www.yammer.com/api/v1/pending_attachments/');
request.setRequestBodyFromAttachment('432122c326a4f8b15f8121f3b718110c751');
var response = request.execute();
gs.print(response);
var httpResponseStatus = response.getStatusCode();
gs.print("http response status_code: " + httpResponseStatus);
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2018 07:47 AM
Hi Parag,
It should send the attachment data. Can you check with the 3rd party whether they are receiving any attachment data?
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2018 08:09 AM
I have already referred the link but it was not working for my problem. Need some different help from that code snap-it.
Thanks for Reply 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2018 01:45 AM
Do you any other alternative that will solve the issue. Because after executing the code it replies with server error 500.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2018 01:54 AM
Hi Parag,
You need to check the API of yammer that should help you understand how are they expecting the attachment.
https://www.codeproject.com/Questions/408329/post-on-yammer-with-an-attachment
https://stackoverflow.com/questions/25172765/posting-yammer-message-with-attachment
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader