# Using HTTPConnector to add attachment to JIRA task

**URL:** <https://forum.cloverdx.com/t/using-httpconnector-to-add-attachment-to-jira-task/1629>\
**Category:** CloverDX Platform\
**Created:** [May 21, 2015, 12:00am UTC](https://forum.cloverdx.com/t/using-httpconnector-to-add-attachment-to-jira-task/1629 "2015-05-21T00:00:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![martin\_stangler](https://avatars.discourse-cdn.com/v4/letter/m/48db29/32.png) [@martin\_stangler](https://forum.cloverdx.com/u/martin_stangler)\
**Post date:** [May 21, 2015, 12:00am UTC](https://forum.cloverdx.com/t/using-httpconnector-to-add-attachment-to-jira-task/1629/1 "2015-05-21T00:00:00Z")

</div>

Im currently working on ad-hoc integration of JIRA to other business using REST API. There is no problem create or modify tasks but I unable to adding attachment (xlsx file).

JIRA documentation is pretty good [https://docs.atlassian.com/jira/REST/latest/#d2e2035](https://docs.atlassian.com/jira/REST/latest/#d2e2035) and **curl** example works pretty well for me.

Actually now I use curl command executed in **ExecuteScript** component.

```auto

function integer transform() {

    string script = 'curl -D- -k'
    + ' -u ${JIRA_AUTH}' // HTTP Basic auth. credentials, format: USER:PASSWORD - admin:admin
    + ' -X POST' // HTTP POST method
    + ' -H "X-Atlassian-Token: nocheck"' // XSRF protection handling
    + ' -F "file=@' + toAbsolutePath(dictionary.FILE_TO_ATTACH_URL) + '"' // file to submit
    + ' ${JIRA_INSTANCE_REST_API_URL}/issue/' + $in.0.key + '/attachments'; // JIRA instance REST API URL - http://localhost:2990/jira/rest/api/2/issue/TEST-1/attachments
    
    $out.0.script = script;
    
    return ALL;
}

```

As You can see - This solution has security issue because of password revealing in temporary script on filesystem. This solution is only acceptable as short-term workaround. HTTP Basic auth is a must.

I need to use **HTTPConnector** to this. Sadly Multipart entities are not described good enough. Doc examples and reality differs.

Use file as multipart entity doc example:

> To use files as multipart entitie map only \*\_File field. Do not map \_Content field.

```auto

$out.3.field3_File = "${PROJECT}/workspace.prm";

```

In reality, multipart fields are mapped as $out.4.\* (not $out.3.\*) and there is no such field $out.4.fieldX\_File but fieldX\_EntitySourceFile. I found it pretty misleading.

I found this HTTPConnector mapping to run with no error or invalid response code on my private JIRA mock, but attachment has not been added.

```auto

function integer transform() {

        map[string,string] headers;
	headers["Authorization"] = "Basic " + byte2base64(str2byte("admin:admin","utf-8"));
	headers["X-Atlassian-Token"] = "nocheck";
	
	$out.0.additionalHTTPHeaders = headers;	
	$out.0.URL = "http://localhost:2990/jira/rest/api/2/issue/TEST-1/attachments";
	
	// multipart attachment
	$out.4.field1_EntitySourceFile = "d:\\xxx.txt";

	return ALL;
}

```

Other properties as defauls except “Multipart entities” set to “field1”. There is warning

> ‘Multipart entities’ attribute will be ignored, because ‘Add input fields as parameters’ attribute is set to ‘false’.

It leads me to switch-on and -off that parameter with no effect.

Please help me to set parametters properly to do the task.

Thank You

Martin

Environment used:  
Local DEV CloverETL installation: CloverETL Server 4.0.4.13/13 (Tomcat bundle) + Designer 4.0.4.013  
Local DEV JIRA installation: latest JIRA Plugin SDK (atlas-run-standalone --product jira)

---

<div class="post-metadata">

**Author:** ![simaj](https://avatars.discourse-cdn.com/v4/letter/s/a183cd/32.png) [@simaj](https://forum.cloverdx.com/u/simaj)\
**Post date:** [May 26, 2015, 9:34am UTC](https://forum.cloverdx.com/t/using-httpconnector-to-add-attachment-to-jira-task/1629/2 "2015-05-26T09:34:11Z")

</div>

Hi Martin,

The thing is, that while in the first example you followed correctly Jira’s multipart/from-data parameter name convention in the second you didn’t. According to the Jira documentation the name of the parameter that contains attachments must be “file”. So I suggest to change the name of the field “field1” to “file”, redefine the multipart entity and correct it in the code as below.

```auto

function integer transform() {

        map[string,string] headers;
   headers["Authorization"] = "Basic " + byte2base64(str2byte("admin:admin","utf-8"));
   headers["X-Atlassian-Token"] = "nocheck";
   
   $out.0.additionalHTTPHeaders = headers;   
   $out.0.URL = "http://localhost:2990/jira/rest/api/2/issue/TEST-1/attachments";
   
   // multipart attachment
   $out.4.file_EntitySourceFile = "d:\\xxx.txt";

   return ALL;
}

```

---

<div class="post-metadata">

**Author:** ![martin\_stangler](https://avatars.discourse-cdn.com/v4/letter/m/48db29/32.png) [@martin\_stangler](https://forum.cloverdx.com/u/martin_stangler)\
**Post date:** [May 27, 2015, 11:21am UTC](https://forum.cloverdx.com/t/using-httpconnector-to-add-attachment-to-jira-task/1629/3 "2015-05-27T11:21:35Z")

</div>

Thank you. It does work now.

I did not realize that “name of the parameter” as mentioned in JIRA doc is represented by “Multipart entities” property and MUST have identical value

```auto
2015-05-27 13:08:57,234 INFO 2195550 [ADD_ATTACHMENT_2195550] [{"self":"http://localhost:2990/jira/rest/api/2/attachment/10204","id":"10204","filename":"20150527_OSVC.xlsx","author":{"self":"http://localhost:***@example.com","avatarUrls":{"16x16":"http://localhost:2990/jira/secure/useravatar?size=xsmall&avatarId=10122","24x24":"http://localhost:2990/jira/secure/useravatar?size=small&avatarId=10122","32x32":"http://localhost:2990/jira/secure/useravatar?size=medium&avatarId=10122","48x48":"http://localhost:2990/jira/secure/useravatar?avatarId=10122"},"displayName":"admin","active":true,"timeZone":"Europe/Prague"},"created":"2015-05-27T13:08:57.114+0200","size":7171,"mimeType":"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","content":"http://localhost:2990/jira/secure/attachment/10204/20150527_OSVC.xlsx"}]
2015-05-27 13:08:57,235 INFO 2195550 [ADD_ATTACHMENT_2195550] Token [#2] created.
2015-05-27 13:08:57,235 INFO 2195550 [ADD_ATTACHMENT_2195550] Token [#2] sent to output port 0.

```
