The CreatorCon Call for Content is officially open! Get started here.

Send attachment from Servicenow to JIRA using REST API

kumaran
Giga Expert

I am working in ServiceNow to JIRA integration using REST API, I have implemented all the fields to create JIRA issue.

I am currently trying to send attachment from ServiceNow to JIRA ticket using mid server.

I used the below code as example in the post Jira REST Integration - How to send attachment? :

var request = new sn_ws.RESTMessageV2();

              request.setHttpMethod('post');

              request.setRequestHeader("X-Atlassian-Token","no-check");

                request.setRequestHeader("Content-type","multipart/form-data");

              request.setEndpoint('https://{jiraURL}/rest/api/2/issue/SN-2/attachments');

              request.setBasicAuth("username","password");

              request.setRequestBodyFromAttachment('abd7460b0fe39e001dc906ace1050e9f'); //sys_id of attachment record

            var response = request.execute();

I am getting error in ECC Queue as 'attachment does not exists'

If anyone implemented this , please let me know .

Thanks in Advance.

31 REPLIES 31

Hi Pedro Silva



Luckily, I was able to send and receive attachments using OOB APIs.


Please follow the link below.



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



Please revert, if you face any problem.



Thanks and Regards


Neeraj


Thanks



I will see what I can do


Hi neeraj_sharma,



I managed to create the attachment in Jira.


but.. not quite



it creates with 0.0kb file size.. so guessing the encoding is wrong and obviously the file is corrupt.



this is my code:


createAttachment : function( attachment_sys_id, key ){


var attachmentMessage = new sn_ws.RESTMessageV2('JIra Issue Attachment', 'post');


attachmentMessage.setBasicAuth(gs.getProperty('com.snc.integration.jira.jira_api_user'), gs.getProperty('com.snc.integration.jira.jira_api_password'));



var attachmentRec = new GlideRecord("sys_attachment");


if (attachmentRec.get(attachment_sys_id)) {


attachmentMessage.setRequestHeader("Accept", "application/json");


attachmentMessage.setRequestHeader("Content-Type","multipart/form-data; boundary=IDSNOW"+attachment_sys_id);


attachmentMessage.setRequestHeader("X-Atlassian-Token", "nocheck");


attachmentMessage.setRequestBody("--IDSNOW"+attachment_sys_id+"\r\n"+


"Content-Disposition: form-data; name=\"file\"; filename=\""+attachmentRec.file_name+"\"\r\n"+


"Content-Type: application/octet-stream\r\n"+


"Content-Transfer-Encoding: base64\r\n\r\n"+


"dIMVGkUy5ntp7q7VNj/luw=="+"\r\n"+"--IDSNOW"+attachment_sys_id+"--");


}


attachmentMessage.setStringParameter('base_url', gs.getProperty('com.snc.integration.jira.base_jira_instance_url'));


attachmentMessage.setStringParameter("issueKey", key);


gs.log(attachmentMessage.getRequestBody());


var res = this._submitBodyTypeRequest(attachmentMessage, true);


return res;


},



and it creates:


find_real_file.png




How can I solve this?



Thanks,


Pedro


Hi Pedro,



We are integrating our system with Jira.


I am facing issue like content-type is incorrect, can I know how do you get the Boundary in Jira application ?


what I needs to do to get the Boundary from Jira application.



please help me, I am stuck here.



Thank you.


Hi Pedro,



Currently we are integrating servicenow with Jira application and right now I am facing similar issue like you.


file which is transferring from servicenow to Jira is successfully transferring but file size is 0 and it doesn't have content in it.



could you please help me on this, you help will be appreciated.



find_real_file.png



Thank you.