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

REST API attachments Transfer to JIRA

harishdasari
Tera Guru

Hi,

We have already implemented Snow-JIRA integration and built it by our own not using the John anderson POC for snow-jira integration update set.

Requirement is we want to implement the attachment transfer from Snow to JIRA application using REST API.

I have referred lot of community articles but unable to implement it because JIRA application supports only Multipart/form-data, it will not support Binary data format for attachments.

Anyone if worked please help me with code, how they have implemented would be really helpful for lot developers.

Thank you.

20 REPLIES 20

Hello Ankur,

I am following the same method as you have shared above.

 

In HTTP headers,

Content-Diposition ---> form-data,

Content-Type ----> multipart/form-data,boundary=AAA,

X-Atalassian-Token --->no-check

 

In json body, 

I am passing the json body as -

{
      "attachments": [{
          "content_type": "image/png",
          "file_name": "Screenshot (153).png",

          "size_bytes ": "137246 ",
          "sys_id": "f576b5211b091950f7b82fcde54bcbae"
      }]
  }

 

In the status code, I can see 200 as status code, but no attachment being added to Jira

Hi @Ankur Bawiskar ,

 

We have similar requirement to send attachment to Jira from ServiceNow. I have done configuration by following ur steps as shown below, but still getting 400 error code:

RupeshRamChi1_0-1706632734904.pngRupeshRamChi1_1-1706632757543.pngRupeshRamChi1_2-1706632778371.png

If i remove header x-Atlassian-token from the rest http method, then i'm getting 404 error. 

RupeshRamChi1_3-1706632910563.png

Can you please let me know where i might be going wrong ? and im able to attach documents to jira issue with the same login. and im able to hit and create issue from other api, so there is no problem with user/authentication.

Please let me know if u need any other screenshot to get more idea ?

Hi @Ankur Bawiskar 

Can you please share any sample requests here?

harishdasari
Tera Guru

Hi Ankur,

Here is the code i am using to send multipart/formdata.. please help to send attachment to JIRA. i am using attachment api

 

(function executeRule(current, previous /*null when async*/) {
	
	// Add your code here
		var JiraAttachment = new sn_ws.RESTMessageV2('Jira REST API', 'Post Attachment');
	       JiraAttachment.setEndpoint("http://jira.dev.na.XXXX.biz/rest/api/2/issue/WM-16/attachments");
	      JiraAttachment.setHttpMethod("post");
	      JiraAttachment.setMIDServer("USNMIDSRVNDCTEST");
	    JiraAttachment.setBasicAuth("X987111", "Qscvht@369");
		JiraAttachment.getRequestHeader("Content-Type", " multipart/form-data");
		JiraAttachment.setRequestHeader('X-Atlassian-Token', 'no-check');
	    JiraAttachment.setQueryParameter('table_name', 'incident');
	    JiraAttachment.setQueryParameter('table_sys_id', "0344cd86dbc567c076b17d8bbf961931");
	    JiraAttachment.setRequestBodyFromAttachment("c23f3c4713696b00926635528144b0fb");	
		var Attachmentresponse = JiraAttachment.execute();
		var AttachmentBodyBody = Attachmentresponse.getBody();
		var httpStatus = Attachmentresponse.getStatusCode();
		var errorCode = Attachmentresponse.getErrorMessage();
			
			gs.log('****Sendingattach  ' + httpStatus  +  errorCode);
			
			
	
	
	
	
})(current, previous);

 

 

 

Hi Harish,

So you are using mid server for this.

Did you check by adding logs in mid server?

Also why you cannot directly consume the JIRA API and why to use mid server since I assume JIRA can be accessed publicly.

Regards

Ankur

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