Why attachments are not being added in JIRA when sent from Servicenow
Asked by Prajwal Ashok Nagrale:

During JIRA ServiceNow integration , when attachment is sent from servicenow but not added in JIRA Issue attachments . why it is not added in attachment and what is left to be done so that it can get added


Answers:
author: Stefan Salzl
body: Hi [@Prajwal Ashok Nagrale](/t5/user/viewprofilepage/user-id/5070890) and welcome to the community,

How did you integrate SN and Jira? Are you using a Plugin? If so: which one? How are attachments sent to jira?

Please share some more details regarding your problems. This helps the community to find a solution.

Best  
Stefan

comments: author: Prajwal Ashok Nagrale
body: Hi, we have used REST Api to \*integrate SN and JIRA .


author: Stefan Salzl
body: In order to be able to analyse the problem the community please add some deeper insight and details.

Without knowing how your integration/calls look like, where are they triggered, how is api call sent, etc... the community could just do guesses.

Best  
Stefan


author: Prajwal Ashok Nagrale
body: Integration call through business rule of serviceNow

(function executeRule(current, previous /**null when async** / ) {

var arr = \[\];

var gsu = (typeof GlideStringUtil != 'undefined') ? (GlideStringUtil) : (Packages.com.glide.util.StringUtil); //few versions support the first one, other supports second

var gsa = (typeof GlideSysAttachment != 'undefined') ? (new GlideSysAttachment()) : (new Packages.com.glide.ui.SysAttachment());

var gr = new GlideRecord("sys_attachment");

gr.addQuery('table_sys_id', current.table_sys_id);

gr.query();

while (gr.next()) {

var attachmentData = gsa.getBytes(gr);

var attachment = String(Packages.java.lang.String(attachmentData));

var encData = GlideStringUtil.base64Encode(attachmentData);

var obj = {};

obj\["content_type"\] = gr.getValue('content_type');

obj\["file_name"\] = JSUtil.escapeText(gr.getValue('file_name'));

obj\["size_bytes"\] = gr.getValue("size_bytes ");

obj\["sys_id"\] = gr.getUniqueValue();

obj\["Content-Transfer-Encoding"\] = "base64" + encData.toString();

arr.push(obj);

}

var finalObj = {};

finalObj\["attachment"\] = arr;

var sm = new sn_ws.RESTMessageV2('Neste Siili JIRA', 'Add attachment');

var response = sm.execute();

var status = response.getStatusCode();

[gs.info](http://gs.info/)("Payload sent jira: " + sm.getRequestBody());

[gs.info](http://gs.info/)("Response jira: " + response.getBody());

[gs.info](http://gs.info/)("Status jira : " + status);

})(current, previous);

Payload --

{  
"attachments": \[{  
"content_type": "image/png",  
"file_name": "Screenshot (153).png",  
"size_bytes ": "137246 ",  
"sys_id": "f576b5211b091950f7b82fcde54bcbae",  
"Content-Transfer-Encoding": "base64${base64EncodedData}"  
}\]  
}


author: Stefan Salzl
body: Hi [@Prajwal Ashok Nagrale](/t5/user/viewprofilepage/user-id/5070890)

I do not know any engine of SN. I can just reflect the issue from Jira perspective.

So which endpoint of the jira API are you calling? How do you determine the issue key where the attachment should be added?

Best  
Stefan


author: Prajwal Ashok Nagrale
body: Hi,

Just want to know in Which format Jira accepts an Attachment using Rest API ?

Regards,

Prajwal


author: Stefan Salzl
body: Hi [@Prajwal Ashok Nagrale](/t5/user/viewprofilepage/user-id/5070890)

This is an example how an attachment can be added via curl api call:

```
curl --location --request POST 'https://your-domain.atlassian.net/rest/api/3/issue/TEST-123/attachments' -u 'email@example.com:<api_token>' -H 'X-Atlassian-Token: no-check' --form 'file=@"myfile.txt"'
```

see detailed documentation here:

<https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-attachments/#api-rest-api-3-issue-issueidorkey-attachments-post>

Hope this is helpful.

Best  
Stefan


author: Prajwal Ashok Nagrale
body: Hi,

Can you check whether this payload is correct for jira.

{  
"attachment": \[{  
"content_type": "text/plain",  
"file_name": "test.txt",  
"size_bytes": "2",  
"sys_id": "1326b90a1bc3d51014811023b24bcb5c",  
"Content-Transfer-Encoding": "base64dHQ="  
}\]  
}

and the reponse from JIRA is Blank. do you know why the response is blank ?


author: Stefan Salzl
body: To be honest I?m not a developer. I can handle easy api calls as described in the documentation. So adding attachment via curl (as described above) worked in my system.

What I could find in the community was the following post. The question from Radek on 11.02. might cover your problem:

<https://community.atlassian.com/t5/Jira-Core-Server-questions/Upload-attachments-on-Jira-through-the-REST-API/qaq-p/1941991>

Best  
Stefan


Tags: integration