The Now Platform® Washington DC release is live. Watch now!

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Multipart/form-data attachment pusg using Rest API from Snow->Jira

Ashish Avinav
Giga Contributor

Hi All,

 

We are integrating ServiceNow  with JIRA .We are facing issue with attachment push from SNOW->JIRA.

As we have to use Content-Type as "multipart-form-data", am not able to set request with attachment that need to be send.

Seems like setRequestBodyFromAttachment('sys_id') is not working, as its returning Http Status -200, but no response object.

 

Below script am using:

 

try
{
var req = new sn_ws.RESTMessageV2('Jira Integration Attachment', 'Post Attach');
req.setStringParameterNoEscape('key', event.parm1);
req.setRequestHeader("X-Atlassian-Token","no-check");
req.setRequestHeader("Content-type","multipart/form-data;boundary="+file[i].id); // file[i].id- sys id of attachment
req.setRequestHeader("Accept","application/json");
req.setMIDServer('mid-sever name);
req.setEccParameter('skip_sensor', true);
req.setStringParameter("file",file[i].name); // name of file
req.setRequestBodyFromAttachment(file[i].id); // sys id of attachment

var res= req.execute();

var resBody= res.getBody();
}

catch(ex)
{
gs.log("exception : "+ex);
}

 

 

Please help with this.

Thanks,

Ashish Avinav

9 REPLIES 9

Christian_
Giga Guru

Hello, 

Don't think that the multipart/form-data header is supported. 
Have read on the Community that this should work when using an MID server, but nothing that I’ve had the possibility to investigate further.

When we faced this issue, we solved this by using a third party in the middle. (NodeJS app)

Marco Perez1
Tera Contributor

I was facing the same issue, got HI team on this and servicenow DOES accepts form-data format, although it wont accept files to be attached (unless you are on LONDON and the IntegrationHub plugin has been purchased ($$$$), and it will be available ONLY on "Flow Designer").

Try this:

var r = new sn_ws.RESTMessageV2('<12312312312321>', 'POST');
var var1 = "test1";

var var2 = "test2";

var var3 = "test3";
r.setStringParameterNoEscape('form1', var1);
r.setStringParameterNoEscape('form2', var2);
r.setStringParameterNoEscape('form3', var3);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();

Please mark as this as helpful if it was.

Regards

ashik1
Kilo Guru

I have tried to debug code from another thread and works perfectly for me. I have posted complete solution code here - https://community.servicenow.com/community?id=community_question&sys_id=0679b3b0dbfeeb00f21f5583ca96...

Hello Ashik. your link is not working. Could you please share it again?