Downloading Attachment (File) from REST API JIRA on-prem to local drive

Hi, I have a problem downloading the attachment (file) from the REST API JIRA on-prem response:
Example url:
https://domain.com/jira/secure/attachment/{id}/{file_name}

This is my CSharp (C #) code:

var client = new RestSharp.RestClient("https://jira_domain.pl/secure/attachment/1234567/file_name.doc");
client.Timeout = -1;
var request = new RestSharp.RestRequest(Method.GET);
request.AddHeader("Authorization", String.Format("Basic {0}", Secret));
response = client.Execute(request);
fileBytes = client.DownloadData(request);

I used the Invoke Method activity to write a byte array (byte[]) to a file. The file writes, but instead of 1.11MB, it only has 4KB.
image

When I perform the same query using cURL in Postman:

curl -L -O -k -u 'user:pass' -X GET https://jira_domain.pl/secure/attachment/1234567/file_name.doc

I have the option to save the attachment via the Save Response> Save to a file option:

image

File saved by Postman:
image

File saved by Invoke Method:
image

Both IRestResponse.RawBytes As Byte [] and fileBytes As Byte [] = client.DownloadData(request) have the same number of bytes:
image

What’s the problem?
Why is Postman able to save the file and my code not?

@ppr, @Yoichi, @loginerror, @Cristian_Negulescu

Hello Adrian,
In this video I download documents from jira via rest api

Thanks,
Cristian Negulescu

Also on this video at time 6:05 I show how I download file in vb.net code
UiPath download and upload files to any website via (HTTP request) - YouTube

1 Like

Hi,

StausCode shows Unauthorized. So probably there is some matter with format of ID/Password.

The following might help you.

Regards,

Hi,
thanks for reply @Yoichi and @Cristian_Negulescu.

Working RestSharp code for REST API JIRA [GET] attachment:

var client = new RestSharp.RestClient(URL);
client.Authenticator = new 
RestSharp.Authenticators.HttpBasicAuthenticator(username,password);
var request = new RestSharp.RestRequest(Method.GET);
response = client.Execute(request);
1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.