Uploading attachments via REST API (JIRA)

Matt Smith April 23, 2021

Hello! 

We are currently undergoing a migration and I need to bulk upload attachments to existing Jira tickets from a local store; I am attempting to follow the REST API code provided on Atlassian Confluence: 

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

I've created an API key and input this as the password with the username.
When running this I am receiving: 

curl: (26) Failed to open/read local data from file/application

I have attempted moving this file into a higher location and using both parent folder and the document as the {path/to/file} but I must be missing something as I am very new to this. 

Thank you in advance for any support. 

 

1 answer

1 accepted

0 votes
Answer accepted
Prince Nyeche
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 23, 2021

Hi @Matt Smith 

Are you migrating from server to cloud instance or from a cloud to cloud instance?

Matt Smith April 23, 2021

Hey @Prince Nyeche

Thanks for your quick response, it's cloud to cloud - as far as I am aware there is no clean way to do it, 

What we're attempting is bulk download via a 3rd party application available on the Atlassian marketplace and then attempting to find a bulk upload process, 

Thank you! 
Matt

Prince Nyeche
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 23, 2021

Hey @Matt Smith 

If you're familiar with a little bit of python, there's this script I made which does a bulk attachment from instance to instance, fetching the attachments based on JQL. All you need to do is follow the instruction on the readme.md file and you'll be able to migrate your entire attachments without the need to download it.

Prince Nyeche
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 23, 2021

Even though it's a server to cloud implementation, it works on a cloud to cloud instance as well. Let me know if you can use that instead or if you have any questions on it.  Also i wrote this article a few months back on how to transfer attachments between cloud instances via API, you can also take a look at that too.

Matt Smith April 23, 2021

Hey @Prince Nyeche  

Thanks for your help on this, 

The first solution wont work for our example as I understand as our destination project key is different to our source project key, 

I will take a deeper look into the second option over the weekend, admittedly a python novice but I'm thinking our bottle neck will be the fact all of the incidents are not in our workspace currently as we are doing an incremental migration due to the source being currently worked in. 

I will get back to you early next week with any success/failures I have, 

Thank you for your time. 
Matt

Like Jocelyn Weber likes this
Jocelyn Weber April 23, 2021

I wonder if it would work to update the project keys in the old space after the users are in the new space and then run this? 

Like Matt Smith likes this
Matt Smith April 26, 2021

Good Morning @Prince Nyeche 

I have successfully extracted the attachments this morning via your article. 

I notice on there that this advises that the keys must be the same - as we have amended this in our workspace they will not be the same. 

Looking at the csv I notice it stores Project Key and Issue Key, if I manually amend these in the CSV to match our target do you think this will be successful? Admittedly still a good amount of manual work but significantly less than manually uploading the docs. 

Thank you! 
Matt 

Prince Nyeche
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 26, 2021

Hey @Matt Smith 

Yes, if you do that it will upload to those issue keys. As long as you have the report you can manipulate anything you need. Let me know how it goes.

Matt Smith April 26, 2021

Hey @Prince Nyeche 

So I have followed the article quite strictly, I updated the CSV's Project ID, Project Key, Project name and Issue Key to match the destination Project but am receiving the following error when running the import script. 

requests.exceptions.MissingSchema: Invalid URL 'ESINTG': No schema supplied. Perhaps you meant http://ESINTG?

Appreciate any assistance, 
Matt 

Matt Smith April 26, 2021

@Prince Nyeche it works! 

I was misunderstanding the keyword args but after getting my head around that I can see it in action! 

This has no doubt saved tens of hours of manual work and massively help with the integration and maintaining my sanity. 

Thank you! 
Matt

Prince Nyeche
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 26, 2021

Awesome @Matt Smith! Glad to hear it works for you. Have a good day ahead.

Like Matt Smith likes this
Anil Kumar March 30, 2022

Hi @Prince Nyeche Does that script work for moving attachments from Server to Datacenter? please let me know.. thanks.. 

Prince Nyeche
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 31, 2022

Yes, it works between Server to Server. Definitely, it should work for Server to Datacenter.

Anil Kumar March 31, 2022

thanks a lot.. 

Anil Kumar April 5, 2022

@Prince Nyeche hi, I am getting the following error:

"Please check your server credentials, as it might be wrong..."

Do I need to consider API token of Source or Target?

could you please explain.. thanks in advance.

Prince Nyeche
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 6, 2022

Hey @Anil Kumar 

It means the target instance credential is wrong. If you're connecting from server to data center. Your source credential should be your server ones and the target credential should be the one from data center. I believe you will need to use username and password for both connection. Usually, if your user exist on both instances, that should help make things a little bit clearer. If not, you can always enter the appropriate credential for each user you're connecting with. Hope that clarifies?

Suggest an answer

Log in or Sign up to answer