Pass Attachment to third Party Application from SN through REST API : Getting an error

SandyNow
Tera Contributor

Hello Geeks,

 

I have built an outbound integration in Customer Service App to create a case record in Third Party Application (ServiceDeskPlus by Manage Engine) through REST API.

 

I need to send an attachment to the newly created record in SDP and I have written an BR on attachment table and triggering REST API call but getting below error with error code 500 in response status

 

{"response_status":{"status_code":4000,"messages":[{"status_code":4004,"type":"failed","message":"Internal error"}],"status":"failed"}}

 

 

BR On Attachment Table

On Insert - Async

 

Script in BR :

 

var resultGr = new GlideRecord("sn_customerservice_case");
resultGr.addQuery("sys_id", current.table_sys_id);
resultGr.addQuery("account", '<account sys id>'); // running for specific account
resultGr.query();
if (resultGr.next()) {
var caseid = resultGr.sys_id.toString();
gs.info("Case sys id : " + caseid);
try {
var r = new sn_ws.RESTMessageV2('New Integration', 'UploadAttachment');
r.setRequestBodyFromAttachment(current.sys_id);
r.setRequestHeader("Content-Type", resultGr.content_type);
r.setStringParameterNoEscape('request_id', resultGr.correlation_id);

 

var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.info("The value of the POST Response is " + httpStatus + "Body : " + responseBody);
} catch (ex) {
var message = ex.message;
}
}

 

Can you please help to identify where the issue is ?

 

NOTE : I have tried it through postman as well to send the attachment to the specified endpoint but same error.

10 REPLIES 10

SandyNow
Tera Contributor

@Ankur Bawiskar Followed your few post on attachment part but no luck yet. Appreciate your help here.

 

Ankur Bawiskar
Tera Patron
Tera Patron

@SandyNow 

please check what the 3rd party accepts when it comes to attachment.

Do they require base64 data, file name, content type etc

Since you mentioned you are unable to test it with Postman, 1st try with Postman and then replicate in ServiceNow

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,

 

I was able to send it thru Postman and here what the 3rd Party is accepting but how can I accommodate 'input_file' in REST API ?

 

@SandyNow 

Thank you for marking my response as helpful.

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