Send attachment data to external system using Rest API in JSON format.

Bandaru Sree Le
Kilo Contributor

Hi Team,

I need to send attachment data to external system in JSON format. How can I do it?

Should I also encode data to base64 in this case?

Please help me!

 

Thank You

11 REPLIES 11

@Bandaru Sree Lekha 

You can then use Excel Parser to read the Excel file and send the data.

refer below link for example

read excel file

Let me know if I have answered your question.

If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar , I can use Glideexcelparser to read excel. But, stuck to convert it to json format. Can you please help me here? 

Thank you for your quick response.

Hi,

can you share how the JSON request should look like

Consider your excel has 4 rows and 4 columns so how it should be sent

Should it be sent row wise like this

{

"row1":"row1Data",

"row2":"row2Data",

"row3":"row3Data",

"row4":"row4Data"

}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur, 

The excel contains dynamic rows and fixed columns.

The following code helps to read excel, please help me how can I convert the data to JSON in the following code.


var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id',current.sys_id);

gr.query();

gs.sleep(100);

if(gr.next()){//use `while` if dealing with multiple attachments

if(gr.getValue('file_name').indexOf('xlsm') != -1 && gr.getValue('file_name').indexOf('file1') != -1){


var parser = new sn_impex.GlideExcelParser();

var attachment = new GlideSysAttachment();

// Use the attachment sys_id of an Excel file
var attachmentStream = attachment.getContentStream(gr.sys_id);

// Set the source to be parsed
parser.parse(attachmentStream);

// Get the worksheet names to be parsed in the Excel document
var list_sheet_name = parser.getSheetNames();

gs.info(" Sheet Names : " + list_sheet_name.join(", "));

//var headers = imp.getColumnHeaders().toString().split(',');
var headers = parser.getColumnHeaders();

}

}

Hi,

how the 3rd party expects the json request body?

you should ask them and include it accordingly

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader