Why attachments are not being added in JIRA when sent from Servicenow

Prajwal Ashok Nagrale November 4, 2022

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

1 answer

1 accepted

0 votes
Answer accepted
Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 4, 2022

Hi @Prajwal Ashok Nagrale 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

Prajwal Ashok Nagrale November 6, 2022

Hi, we have used REST Api to *integrate SN and JIRA . 

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 7, 2022

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

Prajwal Ashok Nagrale November 7, 2022

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("Payload sent jira: " + sm.getRequestBody());    

gs.info("Response jira: " + response.getBody());    

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}"
      }]
  }

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 7, 2022

Hi @Prajwal Ashok Nagrale 

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

Prajwal Ashok Nagrale November 7, 2022

Hi,

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

 

Regards,

Prajwal

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 8, 2022

Hi @Prajwal Ashok Nagrale 

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

Prajwal Ashok Nagrale November 10, 2022

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 ?

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 10, 2022

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events