Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Send Attachment from One ServiceNow to Other ServiecNow Instance

balaji_prusty1
Giga Guru

Hi,

I am configuring sending attachments from Incident (ServiceNow) to Other ServiceNow instances using the custom app. I configured the below script in BR. But it is always failing with 401 errors. (As below)

{"error":{"message":"Invalid file type: application/json","detail":null},"status":"failure"}

 

------------------------BR Script-------------------

var qry = 'table_name=incident^u_sent_flag=false^table_sys_id=' + current.sys_id;
 var att = new GlideRecord("sys_attachment");
    att.addEncodedQuery(qry);
    att.query();
    while (att.next()) {
        try {

            var r = new sn_ws.RESTMessageV2('x_mea_inte_Integration', 'Send Attachment');
            r.setStringParameterNoEscape('table_sys_id', '611b0822fbb392103bf0f471beefdc06'); // sys_id hard coded  to test
            r.setStringParameterNoEscape('table_name', 'incident');
            r.setStringParameterNoEscape('file_name', att.file_name);
            r.setStringParameterNoEscape("Accept", "application/json");
            r.setStringParameterNoEscape("Content_type", att.content_type);
            r.setRequestBodyFromAttachment(att.sys_id);
            var response = r.execute();
            var responseBody = response.getBody();
            var httpStatus = response.getStatusCode();
            gs.info("Attachment Update Responce Body : " + responseBody);
            gs.info("Attachment update status : " + httpStatus);
        } catch (ex) {
            var message = ex.message;
        }

    }
----------------------
 
Can someone please help with this?
 
Thanks in Advance.
2 ACCEPTED SOLUTIONS

@balaji_prusty1 

did you check the links I shared yesterday?

Unable to send attachment via REST 

Business rule to send attachment to 3rd Party Tool via REST 

Send attachment via rest message 

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

View solution in original post

balaji_prusty1
Giga Guru

Thanks All,

 

We are missing adding these parameters in the rest endpoint. (highlighted in red). Only sent over BR but missed adding in the end point. It's working now.

 

https://******.service-now.com/api/now/attachment/file?table_name=${table_name}&table_sys_id=${table_sys_id}&file_name=${file_name}

View solution in original post

14 REPLIES 14

Ankur Bawiskar
Tera Patron
Tera Patron

@balaji_prusty1 

401 means authentication issue.

Did you check that?

Post that check please see if your script fails and add logs to debug further.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hi Ankur,

 

Sorry, its 400 error. Passing content type from attachment table but still error.

 

: {"error":{"message":"Invalid file type: image/jpeg","detail":null},"status":"failure"}

@balaji_prusty1 

are you sure the target instance has allowed to add image/jpeg on your record?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Yes, it's allowed. 

@balaji_prusty1 

check these links

Unable to send attachment via REST 

Business rule to send attachment to 3rd Party Tool via REST 

Send attachment via rest message 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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