I try to add attachment file to opened issue through POSTMAN or curl to Jira. However, it returns me 404 error. I do not have any problem with permissions, since, I checked all of them with other REST API from Jira, also, the file I send has only 4 kb of data and it is '.txt' file. I did my request according to following url: -api-3-issue-issueIdOrKey-attachments-post
I have found several examples on how to upload an attachment to an issue in jira, however I have not been able to make any of them work. I posted this question on the Jira Community Help Forums but it has been over a week with 0 replies so hoping the community here can help.
Looks like you haven't loaded the file's data into the postbody to send with the web request. Here's a link to a PHP file for a REST request using curl that handles a file attachment. Look at the buildpostbody function.
Part of the attachment process is loading the file content and adding it to the postbody as a string. It also provides the correct Content identifier as well based on the file contents. Just providing the filename to the curl function isn't sufficient.
I am using Jira's API to add an attachment file to a case. My issue is after my code attaches a file, and I go to the JIRA case to confirm, I see two things. First, if it is an image, I can see a thumbnail of the image. If I click it, though, I get an error saying "The requested content cannot be loaded. Please try again." Second, under the thumbnail, instead of showing the name of the file, it has the path that the file was originally uploaded from (id: c:/wamp/www/...." Is there a reason this is happening? Here is my code:
Once the file gets added to Jira, when I log into jira, I can see the thumbnail but the title under the file is something like: c:/wamp/www/mySite/web/system/files/my_folder/DSC_0344_3.JPG instead of the file name.
The curl example is just intended to show what needs to be provided when sending an HTTP POST request to the Jira REST API endpoint in order to add an attachment to an issue. You can just provide the same data in any other way without using curl.
In the below threads you can find examples showing how to add an attachment using PHP or Java or python. Just keep in mind that there are differences depending if you are using Jira Cloud or Server (e.g. In Cloud you must use email address and api-token instead of username and password to authenticate):
Does anyone know why I can retrieve an attachments body using curl but using either postman or Salesforce it returns an empty body? The requests using postman or salesforce both return 200 OK and give no signs of errors in the header, yet the body is still empty.
I'm trying to add an attachment when creating a ticket. My code works great to open a parent ticket and than passing the parent ID to create subtasks, but if I try to add an attachment all hell breaks lose. I've seen a few examples trying to...
I have been searching online for a while and I've not found a solid answer to this (lots of partial answers, though). Still nothing I do works. I'm trying to write a powershell script to send attachments to JIRA using cURL (have not found...
I am trying to attach a txt file from my local computer to Jira issue using Invoke-Restmethod and i am getting following error Invoke-RestMethod : The remote server returned an error: (415) Unsupported Media Type. At C:\scripts\jira4.ps1:30 char:15 +...
Hi, I am trying to upload a file through jira's REST API. I am using my own java REST client based on jersey and json parser. How do I construct json query for REST API? REST resource: issue/"issueKey"/attachments It should be something like in the...
While uploading an attachment during issue creation as an anonymous user throws an error saying "You are not authorized, the session has expired or connection is lost" though the "Browse Project", "create issues" and "create attachments" permissions to "Anyone on the web" group was given to "Anyone on the web".
A simple example to attach a file called "myfile.txt" to the container with id "123", with a comment included: curl -D- -u admin:admin -X POST -H "X-Atlassian-Token: nocheck" -F "file=@myfile.txt" -F "comment=This is my File"
A example to attach a file called "myfile.txt" to the container with id "123", with a comment, and set the minorEdits flag to be true: curl -D- -u admin:admin -X POST -H "X-Atlassian-Token: nocheck" -F "file=@myfile.txt" -F "minorEdit=true" -F "comment=This is my File"
When updating the binary data of an attachment, the comment related to it together with the field that specifies if it's a minor edit can be updated as well, but are not required. If an update is considered to be a minor edit, notifications will not be sent to the watchers of that content.
A simple example to upload a file called "myfile.txt" to the Attachment with id "456" in a container with id "123", with the comment updated, and minorEdit set to true: curl -D- -u admin:admin -X POST -H "X-Atlassian-Token: nocheck" -F "file=@myfile.txt" -F "minorEdit=true" -F "comment=This is my updated File"
I am attempting to use the download tool to carry out some API commands. Per this article( -Designer-Knowledge-Base/APIs-in-Alteryx-cURL-and-Download-T...) , I have been able to understand how curl commands translate to fields in the download too. It states the Get/put, - d (for data) and - H (for headers) equivalents in the download tool, but is there a -F equivalent available in the download tool as well - for the purpose of uploading a file via api? Or any other method to use download tool to upload a file via API
Following the suggestions on that post, I have got the download tool to seemingly work - It shows a 200 response in the Download Headers field, which would mean it's successfully uploaded attachment - However on checking the environment(Jira) where attachment was expected, I see that it hasn't actually attached the file. The DownloadData field in Download tool does not show anything aside from a box type symbol made of square brackets like the following- '[]' - not sure what that means and if it indicates an issue in the upload? Could there be something about the file blob/string data that I am sending which is causing this?
You can retrieve and set encrypted custom field values and attachments using Jira REST and Java APIs. This lets you copy your unencrypted data over to other fields or use it with third-party integrations, automations, or scripts.
An alternative to this export is using curl to export issues individually. This process includes comments and involves lots of quick JIRA queries. As an added bonus, I can avoid any XML SAX state logic that a single large XML file would have needed, so I can focus on transforming issues into bugs in isolation. Sweet.
Attachments: Bugzilla expects attachments embedded in the XML file, so we need to convert our binary files into base64 strings and then include them inline. Below is Ruby code to convert to base64. Keep in mind that the import process takes far longer when attachments are included.
Starting with version 1.8.3 we are also allowing authentication with tokens on the attachment download endpoints for Jira and Confluence.
The workaround described below is not required anymore.
For best security practices we recommend enabling the Disable Basic Authentication with User Password option in the system-wide settings.
Enabling Disable Authentication with Session Cookies provides additional security but requires sending the authentication header with every request.
In order to download attachments, one needs to authenticate against a REST endpoint first and use the session cookie for the subsequent request to retrieve the attachment via the non-REST endpoint. Below are some Curl examples for Jira and Confluence.
The Jira Python library provides some convenient methods to retrieve Jira content. Please see for installation instructions.
The following snippet shows how to authenticate with a user and API token and how to download attachments from an issue.
After I got above-mentioned error, I tried semi-automated and manual approach, with the same result:
certbot certonly --test-cert --webroot -w /opt/atlassian/jira/atlassian-jira/ -d jira.craz.cz
certbot certonly --test-cert --manual -d jira.craz.cz
Create a .templates folder in the root of your project. In this folder, create a template file called jira.json, which adds formatted comments to a Jira issue. An example jira.json file can be found in our Sample project.
Additional environment variables are then set, such as the build number, build date, and commit number. These environment variables are used to replace values in the jira.json comment template using sed, a stream editor for parsing and transforming text.
For a small instance with a small team, cloning and moving with the native Jira options is a solution without any added cost or configuration, but the risk of error and time spent on the process only increases when you have lots of projects or a larger team cloning and moving. This solution works to clone attachments, some custom fields, but not comments.
If you are using Jira on premise (Server or Data Center), the documentation on how to clone an issue with Automation is available here. The clone made with Automation for Jira will not copy attachments, issue links, or comments, but you could configure additional rules to sync comments, for example.
If specifying valid JSON objects for advanced field cloning is a piece of cake and your team has structured and complex processes for using Jira, Automation could be the right solution for you. You will have more control over cloning custom fields compared to the native options, but you will need to spend considerable time configuring and maintaining your rules. You will also lose the possibility to clone attachments.
9738318194