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

@Ankur Bawiskar Hi Ankur, do you know how to add 'input-file' in REST API body along with attachment ? I have attached the screenshot from postman in earlier post. Below is the script in BR to trigger REST API.

 

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;
}
}

SandyNow
Tera Contributor

@Ankur Bawiskar 

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 in SN ?

@SandyNow 

Did you ask them regarding how it has to be done? some API documentation from them?

 

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

They have shared the Postman collection as below and endpoint.
 
{
"info": {
"_postman_id": "b8f10c40-d89d-4610-81af-fe6b8cb9bef2",
"name": "AttachmentAPI",
"description": "Attachment post.",
"_exporter_id": "42831747"
},
"item": [
{
"request": {
"method": "PUT",
"header": [
{
"key": "authToken",
"value": "********-****-****-****-************",
"type": "text"
},
{
"key": "Content-Type",
"value": "application/x-www-form-urlencoded",
"type": "text"
}
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "input_file",
"value": "",
"type": "file"
}
]
},
"url": {
"protocol": "https",
"host": [
"test-helpdesk",
"ca"
],
"path": [
"api",
"v3",
"requests",
"******",
"upload"
]
}
},
"response": []
}
]
}
 

@Ankur Bawiskar Did you get chance to look at the postman collection ? Appreciate your response.