Forums

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

Asset bulk import Attachment

Davide Cascapera
Community Champion
December 5, 2025

Hi everibody,
We have a big issue. We are trying to migrate some attachments from an external system to Asset, but we don't find any API to upload a binary. Do you have any suggestions? I'm really in trouble :sob:

3 answers

5 votes
Nikola Perisic
Community Champion
December 5, 2025

Hi @Davide Cascapera 

To add more to @Christos Markoulatos 

Screenshot 2025-12-05 at 13.53.44.png

Go through this guide that Thomas gave. It should work for you. Let me know the results!

Christos Markoulatos
Community Champion
December 5, 2025

@Nikola Perisic nice!!! @Davide Cascapera let us know if it works!

Davide Cascapera
Community Champion
December 5, 2025

Hi @Nikola Perisic  and Hi @Christos Markoulatos ,


Thank you for sharing. We had already consulted your solution, and at the moment, we are using the approach you suggested. The problem is that in the second call, we cannot understand why the token that is generated seems to last only 60 minutes.
Firstly, we don't understand who generates this token, and secondly, how to increase its duration. To give you an idea of the scale, we are migrating attachments from an external CMDB to assets, and we are talking about hundreds of thousands of files of different sizes. It is unthinkable to have to change tokens every 60 minutes.

Kind Regards

Davide

Gerusa Lobo
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 Champions.
December 5, 2025

Hi @Davide Cascapera,

You can create a script to retrieve attachments and send them to Assets.

In this script, you could refresh the JWT token after a certain number of attachments have been sent. For example, you can renew it once every 10,000 attachments inside the loop.

1 vote
Christos Markoulatos
Community Champion
December 5, 2025

Hi @Davide Cascapera 

Based on Add attachments to Assets in Jira Service Management Cloud | Jira and Jira Service Management | Atlassian Support

its not possible, only from the UI

Note that attachments can't currently be added via the REST API or CSV.

Unless something has changed recently and they haven't document it yet.

not much help, sorry!

Solved: How do I add a file to the attachments section of ... 

0 votes
Gerusa Lobo
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 Champions.
December 5, 2025

Hi @Davide Cascapera 

Adding to he another comments:

If you need upload the attachments one time, I have a solution for you.

That way will not work if you need synchronise two systems, but it works on demand.

Analyzing the interface upload button to attach files on Assets, using the dev tools, we can find 3 sequence commands:

  • get JWT temporary credentials using a cookie
  • Upload the attach using the JWT credentials
  • Connect the file with object.

Is it possible create a script reading a csv file with object id and file path informations to upload many files in one execution.

In bellow the simple bash script that I created when I was testing it:

 

#!/usr/bin/env bash

set
-euo pipefail

# 🔧 Configurations

WORKSPACE="afd1a" # workspaceId
OBJECT_ID="16" #objectId
JIRA_URL="https://yoursite.atlassian.net"
CRED_URL="${JIRA_URL}/gateway/api/jsm/assets/workspace/${WORKSPACE}/v1/attachments/object/${OBJECT_ID}/credentials"
FILENAME="anexo.png" # filename
LOCAL_FILE="anexo.png" # local filepath

# 1️⃣ get temporary credentials
echo "[INFO] Getting temporary credentials..."

RESPONSE
=$(curl -s "$CRED_URL" \
-H "accept: application/json" \
-H "content-type: application/json" \
-b 'ajs_anonymous_id=%22d47c5516-1047-48d7...') # put the cookie found via devtools here

# Extrair dados
CLIENT_ID=$(echo "$RESPONSE" | jq -r '.clientId')
TOKEN=$(echo "$RESPONSE" | jq -r '.mediaJwtToken')
MEDIA_BASE=$(echo "$RESPONSE" | jq -r '.mediaBaseUrl')

echo "[INFO] Client ID: $CLIENT_ID"

echo "[INFO] Token retrieved."

# 2️⃣ Upload file to Media Service
echo "[INFO] Uploading $LOCAL_FILE to Jira Media Service..."

UPLOAD_URL
="${MEDIA_BASE}/file/binary?name=${FILENAME}"
UPLOAD_RESPONSE=$(curl -s -X POST "$UPLOAD_URL" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: image/png" \
-H "x-client-id: $CLIENT_ID" \
--data-binary "@${LOCAL_FILE}")

echo "$UPLOAD_RESPONSE" | jq .

MEDIA_ID=$(echo "$UPLOAD_RESPONSE" | jq -r '.data.id')

if [[ "$MEDIA_ID" == "null" ]]; then
echo "[ERROR] Unable to retrieve mediaId from upload!"
exit 1
fi

echo "[INFO] Upload completed, mediaId: $MEDIA_ID"

# 3️⃣ Associate file to Asset object
echo "[INFO] Associating file to object $OBJECT_ID in Jira Assets..."

ATTACH_URL="${JIRA_URL}/gateway/api/jsm/assets/workspace/${WORKSPACE}/v1/attachments/object/${OBJECT_ID}"

SIZE=$(stat -f%z "$LOCAL_FILE" 2>/dev/null || stat -c%s "$LOCAL_FILE")

# put the cookie found via devtools here
curl -s -X POST "$ATTACH_URL" \
-H "accept: application/json" \
-H "content-type: application/json" \
-b 'ajs_anonymous_id=%22d47c5516-1047-48d7...' \
--data-raw "{
\"attachments\": [
{
\"contentType\": \"image/png\",
\"filename\": \"${FILENAME}\",
\"mediaId\": \"${MEDIA_ID}\",
\"size\": ${SIZE},
\"comment\": \"\"
}
]
}" | jq .

echo "[INFO] Attachment successfully associated!"

Suggest an answer

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

Atlassian Community Events