415 error when trying to send attachment to JIRA form ServiceNow

NikhilSingh
Tera Contributor

Hi,

 

I am trying to send attachment from ServiceNow to JIRA through REST message, but I am getting 415 error, tried the same via postman as well and same error.

 

Attaching screenshot of the configuration that I have done for easier understanding. I have also added the code to build JSON object, although I can see all the details coming in properly in the LOG request that I am capturing.

 

Please help with this issue. Thanks.

// Code for getting attachment data and building JSON object to send to JIRA

                        var returnData = {};
			var incGr = new GlideRecord('incident');
			incGr.addActiveQuery();
			incGr.addQuery('sys_id',attachment.table_sys_id);
			incGr.addNotNullQuery('correlation_id');
			incGr.query();
			if(incGr.next()){
				var r = new sn_ws.RESTMessageV2('Create Issue', 'Attachment');
				var issueID = incGr.getDisplayValue('correlation_id');
				r.setStringParameter('issueId',issueID);
				var body = {
					'attachment': [{
    				'file': "" + attachment.file_name,
    				'content_type': "" + attachment.content_type,
    				'content': "" + GlideStringUtil.base64Encode((new GlideSysAttachment()).getBytes(attachment))
					}]
				};

				r.setRequestBody(JSON.stringify(body));
				gs.log('## Log Request ## ' + JSON.stringify(body), 'JIRA-Attachment');
				var response = r.execute();
				var responseBody = response.getBody();
				var httpStatus = response.getStatusCode();
				gs.log('## Log Response ## ' + responseBody + ' ' + httpStatus, 'JIRA-Attachment');
				//gs.log('## Log Status ## ' + httpStatus );

				returnData.status = httpStatus;
				returnData.response = responseBody;

				return returnData;

 

9 REPLIES 9

Danish Bhairag2
Tera Sage
Tera Sage

Hi @Danish Bhairag2 , Thanks for reply, I tried the solution from the above post, but I am still getting 415 error. Please check the request body

## Log Request ## {"attachment":[{
"content_type":"image/png",
"file_name":"postman.png",
"size_bytes":"1124594",
"sys_id":"afcbf3e1474ab5104b5b9e79e16d4398",
"Content-Transfer-Encoding":"iVBORw0KGgoAAAANSUhEUgAACGgAAAX0CAYAAACfQ617AAAMP2lDQ1BJQ0MgUHJvZmlsZQAASImVVwdYU8kWnluSkEBCCV1K6E0QqQGkhNACSO82QhIglBgDQcWOL"
}]
}

NikhilSingh
Tera Contributor

@Ankur Bawiskar Can you check as you have already provided solution related to this problem?

@NikhilSingh 

Since you mentioned the same error came from postman it means the way how request is sent along with body is not proper

Did you check JIRA documentation?

are you not using JIRA spoke for this?

check this link

How to send attachments from servicenow to jira 

check this KB as well

Jira spoke - upload attachment from Jira to Service now 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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