Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to fetch attachment using REST API from JIRA is not working

RishabhT September 9, 2020

I am trying to fetch attachment from JIRA using REST API(provide by Jira). But I am not getting the metadeta of attachment and it is giving me only a URL which is also secured. can anyone please help how to get attachment from Jira using REST API?

3 answers

0 votes
Danil Luchin July 20, 2022

It looks like this endpoint returns the binary now.
But I have no idea how to convert it into base64
Any idea how to do that?

Danil Luchin July 20, 2022

@Angélica Luz Could you please help with this?

0 votes
George Mihailoff
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.
June 7, 2022

Atlassian introduced an experimental endpoint to read attachments.

GET /rest/api/3/attachment/content/{id}

https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-attachments/#api-rest-api-3-attachment-content-id-get

0 votes
Angélica Luz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 11, 2020

Hello @RishabhT,

Thank you for reaching out to Atlassian Community!

Just to make sure we are on the same page, I would like to confirm if you are using the API mentioned on the documentation below:

curl --request GET \
  --url 'https://your-domain.atlassian.com/rest/api/3/attachment/{id}' \
  --user 'email@example.com:' \
  --header 'Accept: application/json'

If that's the case, I tested here and it shows the correct response. 

Would mind sharing with us a screenshot of the response you receive?

Regards,
Angélica

Merajul Hasan September 13, 2020

Hi Angelich,

Jira does not provide directly the content of the attachment but the secure URLs of the attachments.

Here my colleague @RishabhT  is concerned with the contents of the attachment.

The createmeta request working fine but returning only URLs perhaps we need file actual content in the form of base64/blob of the attachment.

 

So, Is there a way to fetch the content of the attachment ?

 

We are getting following response currently.

attachment response.png

Angélica Luz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 15, 2020

Hello @Merajul Hasan,

Thank you for the details.

I'm afraid this is not possible using API. Blob is recorded in the database which can't be accessed in Jira Cloud. 

The only APIs available are the ones from the documentation and none of them returns what you need.

Also, I didn't find any feature request suggesting this ability, so please, feel free to raise one on jira.atlassian.com (project JRACLOUD) adding more details about why this feature is important for your environment.

Regards,
Angélica

Suraj Rajoria September 7, 2021

Hi @Angélica Luz 

Is it still not possible? 

I am also looking for the same, using content URI, I would like to get contents so we can insert that attachment in our system. 

Suraj Rajoria September 7, 2021

@RishabhT and @Merajul Hasan  Did you find the solution or workaround? Please share. 

Merajul Hasan September 7, 2021

Unfortunately, there is no solution , u cud not get the content of attachment

Angélica Luz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 8, 2021

Hi @Suraj Rajoria,

Thanks for reaching out to Community!

It's still not possible to get the content of an attachment.

As mentioned in my previous reply, Blob is recorded in the database which can't be accessed in Jira Cloud since it's a restricted function.

Kind regards,
Angélica

Mohammed Talha Toufeeq
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 21, 2023

Hi @Suraj Rajoria

I've found a solution using the atlassian-python-api,

Create an instance on the backend using your username and api key,

I've done it through a FastApi backend on python.

The attachment URLs need to be hit from a seperate route, fetched through sessions looped through in this way:

Here is my route:

@router.get('/v1/jira-get-attachment', status_code=http.HTTPStatus.OK)
async def get_issue_attachment(issue_key: str):
try:
data = jira_ticket_service.get_attachment(issue_key)
response = SuccessResponse(
"URL found", {"data": data}
)
return JSONResponse(content=jsonable_encoder(response.dict()))

Here's the function:

 

def get_attachment(issue_key: str):
issues = jira.get_issue(issue_key)
attachments = issues.get("fields").get("attachment")
urls = []
for attachment in attachments:
content_url = attachment.get("content")
session = jira.session
response = session.get(url=content_url)
urls.append(response.url)
return urls




Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events