You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
Within some fields in JIRA, images can be added inline such as in the description or in comments. Although they appear inline, they are seemingly being added as attachments and then JIRA is maintaining a link somewhere. Unfortunately, I'm struggling to figure out what that link is when using the API.
Calling /rest/api/3/issue/<issue-key> against an issue where an image has been added inline returns the following:
After uploading an image attachment, you can do an HTTP request to fetch the attachment content, which will redirect to a media URL. The media ID that you need can be extracted from this media URL. You can get the media URL by doing a HTTP GET without automatically following redirects. There's no need to actually fetch the image, just look at the redirect URL (in the HTTP "Location" header).
For example, when adding an inline image to the description, you can get the media ID in this way, then update the description or comment to use that image. I've tested this just now, and it works.
Here's an example.
If this is the main attachment URL:
https://example.atlassian.net/rest/api/3/attachment/12345
When we fetch it, the JSON contains a "content" property, which would be:
https://example.atlassian.net/rest/api/3/attachment/content/12345
When we do an HTTP GET on this content URL, it redirects to another URL using the Location header:
Location: https://api.media.atlassian.com/file/12345678-1234-1234-1234-123456789abc/binary?token=WHATEVER&client=WHATEVER&dl=true&name=something.jpg
We need that UUID "12345678-1234-1234-1234-123456789abc" that comes after /file/ in the redirected URL, this is the media ID.
You can then use that media id in the ADF, something like this:
{
"version": 1,
"type": "doc",
"content": [
{
"type": "mediaSingle",
"attrs": {
"layout": "align-start",
"width": 100.0,
},
"content": [
{
"type": "media",
"attrs": {
"id": "12345678-1234-1234-1234-123456789abc",
"type": "file",
"collection": ""
}
}
]
}
]
}
If you need to go the other way, and find the attachment ID (12345) given the media ID (12345678-1234-1234-1234-123456789abc), you could scan all the issue's attachments one by one in this way. In our case, we are tracking these attachment IDs and media IDs along with some other information in a database, so we don't have to query every attachment each time.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @Jehan Bhathena , I just tested this and wasn't able to find the location header. Are you?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Lam Le ,
yes, I checked it via my browser console.
Unfortunately not sure how we can check this on a API tool like postman.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah, thanks for the guidance. Found it using my browser console, but still stuck on trying to find this location header using http get through 'Automation For Jira' as a header response.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.