How to download issue attachments via API using OAuth

I used the following API to get issue details:

which provides the following attachment URL:

Code that i tried:

public static void makeHttpGet(){
CloseableHttpClient httpclient = HttpClients.createDefault();
String url = "";
String accessToken = "***********************";
HttpGet get = new HttpGet(url);
get.setHeader("oauth_signature", CONSUMER_PRIVATE_KEY);
get.setHeader("oauth_token", accessToken);
get.setHeader("oauth_consumer_key", "********");
get.setHeader("oauth_signature_method", "RSA-SHA1");
get.setHeader("oauth_timestamp", ""+System.currentTimeMillis());
get.setHeader("oauth_nonce", "abcd"+System.currentTimeMillis());
get.setHeader("oauth_version", "1.0");
CloseableHttpResponse response = httpclient.execute(get);
int status = response.getStatusLine().getStatusCode();
if (status >=200 && status < 300) {
	HttpEntity entity = response.getEntity();
	if (entity.isStreaming())
		byte data[] = EntityUtils.toByteArray(entity); 
		FileOutputStream fout = new FileOutputStream(new File("failure.png"));
}catch(Exception e)
{ e.printStackTrace(); }


The above code downloads a file with the login page content i.e. it redirects to login page instead of downloading the actual file.

However it works when i trigger a request with basic authentication(username:pass) in header, instead of Oauth.

1 answer

This widget could not be displayed.

I am having the same issue, but with basic authentication.  How are you connecting with basic auth and downloading the file?

Hi Kevin,

Try the following code for basic authetication

public static void makeBasicAuth(){
			HttpClient hc = new HttpClient();
			String url = "";
			GetMethod get = new GetMethod(url);
			BASE64Encoder base64encoder = new BASE64Encoder();
			byte[] b = "username:password".getBytes();
			String cp = base64encoder.encode(b);
			get.setRequestHeader("Authorization", "Basic "+cp);
			int code = hc.executeMethod(get);
			InputStream is = get.getResponseBodyAsStream();
			if(is!=null && code >=200 && code <= 300){
				FileOutputStream fout = new FileOutputStream(new File("file.png"));
				int read = 0;
                byte[] bytes = new byte[1024];
                while ((read = != -1) {
                	fout.write(bytes, 0, read);
				System.out.println("Download failed");
		}catch(Exception e){



Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

128 views 2 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you