Jira REST Integration - How to send attachment?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2014 08:40 AM
Again, many thanks to John James Andersen for his work on the Jira REST interface.
I have made a tremendous amount of progress on it, and have a heavily customized version of my own running for the Service Catalog. However, now the requirement has come up to send attachments from the catalog over to Jira.
John also had a nice write-up on how to get the attachments out of Service-Now here: http://www.john-james-andersen.com/blog/service-now/sending-out-servicenow-attachments-via-soap.html. I also found write-ups on how to insert attachments via REST to jira here: How do I upload attachment to JIRA Issue via REST API? - Atlassian Answers.
The problem that I'm seeing is that the first link, the data is returned in the raw format, whereas the Jira integration is expecting an actual file.
So, I was wondering if anyone had any suggestions on how to handle this?
My initial thought is to use Orchestration to kick off a perl script on my mid-server and pass it the sys_id of the RITM. Then the perl script would query the sys_attachment table and, for each attachment found, download the attachment and send it over to the Jira instance. This way Service-Now is the one who kicked off the whole thing, so it's not just sitting there running all the time.
Any suggestions are welcome
Thanks!
- Labels:
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2016 03:24 PM
Hi Gary,
From Geneva onwards, ServiceNow supports REST Attachment API which enables user to download/upload attachments. Here is the doc link:
Regards,
Pankaj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2016 12:33 PM
We have done something very similar using the Attachment API in Geneva, but in python.
Through REST you get can all of the info needed to post to Jira. You'll need the metadata and the actual file:
For the metadata, if you know the sys_id of the attachment:
GET /attachment/{sys_id} ==> returning "file_name" and "content_type"
For the file:
GET /attachments/{sys_id}/file ==> returning attachment_file
Then we posted it to our Jira Instance:
file = {
'file': (attachment_meta["file_name"], attachment_file.content, attachment_meta["content_type"])
}
response = requests.post(jira_instance_attachment_url, auth=auth, headers={"X-Atlassian-Token": "no-check"}, files=file)
In summary, for us to post attachments successfully to Jira, we had to provide the file_name, raw content, and the especially the content_type. You can get all this info from within the ServiceNow Attachment API.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2016 10:57 AM
Hi Reenan,
Could you provide a screenshot or a piece of the code in Service Now?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2016 01:02 AM
In a perfect world you should be able to use this,
RESTMessageV2 - setRequestBodyFromAttachment(String attachmentSysId)
Write your script and done.
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();
But I have not been able to get this to work OOB. I believe Jira is only expecting a multipart-form/data message and ServiceNow is sending a application/octet-stream (i think). The only way I have been able to send attachments via REST is with the Mid server using a custom .jar file called from a script include.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2016 02:47 PM
Hi Nick,
I hope you're well. I'm currently busy with a ServiceNOW <=> Jira Integration including attachments. I've used the POC update set found on the share, however I'm stuck at the attachment part.
My ServiceNOW instance is running on Helsinki. Could you guide me on how I can setup a bi-directional attachment synchronization from ServiceNOW to JIRA?
Thank you.
Phil