How to fetch comments with attached documents of an issue via rest api

Ankush Sharma January 21, 2020

We have a use case where user can attach file/image in the comment section. But when we are retrieving comments for a particular issue we are not able to reference file which belongs to a particular comment and the attachments are present in other object called as attachment. the comments lies inside comment array. How can i get comments with the attached files in the comment section?

1 answer

0 votes
Mohamed Benziane
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 21, 2020

Hello @Ankush Sharma 

 

I just try in my dev instance this API :

https://developer.atlassian.com/cloud/jira/platform/rest/v3/#api-rest-api-3-issue-issueIdOrKey-comment-get

It retrieve all comment from an issue. When you have an attachment in a comment the API should return something like this :

body": {
"version": 1,
"type": "doc",
"content": [
{
"type": "mediaGroup",
"content": [
{
"type": "media",
"attrs": {
"id": "039e7ec6-9e7a-42c1-b261-833430aa2aa9",
"type": "file",
"collection": "jira-10608-comment-10121"
}
}
]
},
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "hello "
}
]
}
]
},

Here what my comment looks like 

comments.png

Hope this helps 

Ankush Sharma January 21, 2020

That i know already but the problem is the files i have attached when i gets the comments via rest api then the files i have uploaded, i am getting those files in attachment response and it was very confusing which file belongs to which comment and if comment section has more than one document then there is relation between the two. 

Ankush Sharma January 23, 2020

Waiting for the reply

Mohamed Benziane
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 23, 2020

The API return the comment and the file that belong to it in the body. So if you have 2 comment, you will have 2 body with their attachment and string comment.

 

Hope this helps

Ankush Sharma January 23, 2020

Still the name of the attached file is missing in body of comment and it is available in attachments object then how can i get which file belongs to which comment

tuor4eg May 12, 2020

Hello there!

I have the same question, can anybody help?)

Suggest an answer

Log in or Sign up to answer