cancel
Showing results for 
Search instead for 
Did you mean: 

Upload file to JIRA issue with Web API Services

MateuszBartczak
Level 4
Hi All,

I'm looking for some help with uploading attachment to JIRA issue by using POST action in Web API Services with Single or Multiple Files. I tried multiple solutions so far, but with no success. For a single file approach I tried to use various headers like Content-Type equal to application/json, application/pdf, application/x-binary (and binary), application/octet-stream, etc., X-Atlassian-Token: no-check, Content-Disposition: form-data and many many different combinations. All request were made against such endpoint (as per JIRA docu): https://jira.{base-url}.net//rest/api/[Version]/issue/[Issue ID]/attachments (Version = 2). So far I manage to got 2 results that make any sense. In single file case I'm getting status code 415 which means "Unsupported Media Type" and I was sure that I will be able to fix it with proper header name, but no luck so far 😞 (I'm trying to upload binary file loaded to data item/collection). For the multiple files request I'm receiving status 200 but response content is empty, and...the file is not getting uploaded. I also tried to run cmd command with following cURL code and it's working fine:
curl -D- -u {username}:{password} -X POST -H "X-Atlassian-Token: nocheck" -F "file=@{path/to/file}" http://{base-url}/rest/api/2/issue/{issue-key}/attachments​

The only problem is the fact that I'm not able to read response content back to Blue Prism, and this is why I would like to have it in Web API Service where I have a lot others actions too. Does anybody have some experience with that?

Some more details:
I'm on BP 6.10.1, I've removed common headers, other activities are working fine, only file upload is not working.

Thank you in advance!

1 BEST ANSWER

Helpful Answers

MateuszBartczak
Level 4
Hi @ewilson

Thank you for your respond. After many hours of fight I manage to finally made it works directly from Web API Services. Below screenshots from solution:
34952.png

34953.png
The most important part of this solution was to use multiple files method (even if you uploading single file at once), then create an input collection where you can import fields from particular action (by clicking 'Import' button) or reproduce them as per the screenshot:

34954.png
'File' field needs to has binary file loaded. In the 'File Name' I put full path to the same file. 'Field Name' in this case must be equal to 'file' (without quotes ofc) and 'Content-Type' equal to 'application/octet-stream'. Otherwise JIRA will be responding with status code 200, but no file will be attached.

Edit: I forgot to mention that you need also to use Issue KEY, not issue ID as input parameter (e.g. KEY-123, not e.g. 123456). With Issue ID it won't work.

With all of that, solution is working perfectly. What I found strange is the header 'Content-Type' that cannot be passed through 'Headers' in API tool, but needs to be defined in Collection.

View answer in original post

4 REPLIES 4

ewilson
Staff
Staff
Hi @MateuszBartczak,

One thing I noticed from the URL you specified is that you have an extra "/" in there.​ Not sure if that was just a cut-and-paste error, but you'd definitely want to remove that if that's the way the URL is seen in the WebAPI.

34948.png
Cheers,
Eric

ewilson
Staff
Staff
You might also take a look at this thread. @Zdeněk Kabátek mentioned that the file contents are sent as a Base64 encoded string. If JIRA is expecting the file contents to show up as a binary stream, that would cause a content mismatch error. In that case, you would need to switch to the Utility - HTTP VBO (or your own code stage) to perform the file submission.

You can use a tool like Fiddler to see exactly what's in the request when it's sent from Blue Prism.

Cheers,
Eric​

MateuszBartczak
Level 4
Hi @ewilson

Thank you for your respond. After many hours of fight I manage to finally made it works directly from Web API Services. Below screenshots from solution:
34952.png

34953.png
The most important part of this solution was to use multiple files method (even if you uploading single file at once), then create an input collection where you can import fields from particular action (by clicking 'Import' button) or reproduce them as per the screenshot:

34954.png
'File' field needs to has binary file loaded. In the 'File Name' I put full path to the same file. 'Field Name' in this case must be equal to 'file' (without quotes ofc) and 'Content-Type' equal to 'application/octet-stream'. Otherwise JIRA will be responding with status code 200, but no file will be attached.

Edit: I forgot to mention that you need also to use Issue KEY, not issue ID as input parameter (e.g. KEY-123, not e.g. 123456). With Issue ID it won't work.

With all of that, solution is working perfectly. What I found strange is the header 'Content-Type' that cannot be passed through 'Headers' in API tool, but needs to be defined in Collection.

ewilson
Staff
Staff
@Mateusz Bartczak,

Glad to hear you got it working. So it seems what was required was a multi-part form definition which is what I believe using the “Multiple Files” option gives you.

Cheers,
Eric​