Hey all,
I'm trying to load an attachment to a Confluence Space.
I'm using this:
USER_NAME=XXXXX
USER_PASSWORD=XXXXXX
CONFLUENCE_BASE_URL=http://<CONFL_URL>
ATTACHMENT_TYPE=file
ATTACHMENT_FILE_NAME=myfile2.txt
PAGE_ID=<PAGEID>
curl -u $USER_NAME:$USER_PASSWORD \
-X POST \
-H "X-Atlassian-Token: nocheck" -F "file=@${ATTACHMENT_FILE_NAME}" -F "comment=File attached via REST API" \
${CONFLUENCE_BASE_URL}/rest/api/content/${PAGE_ID}/child/attachment 2>/dev/null \
| jq -r '.results[].title'
REST_CONTENT_FULL_OUTPUT=$(curl -u ${USER_NAME}:${USER_PASSWORD} \
${CONFLUENCE_BASE_URL}'/rest/api/content/'${PAGE_ID}'?expand=body.storage,version,space' 2>/dev/null)
if [ ${ATTACHMENT_TYPE} = "image" ]; then
echo ${REST_CONTENT_FULL_OUTPUT} | \
jq '{body: {storage: {value: (.body.storage.value + "<p><ac:image ac:height=\"250\"><ri:attachment ri:filename=\"'${ATTACHMENT_FILE_NAME}'\" /></ac:image></p>"), representation: .body.storage.representation}}, id: .id, type: .type, title: .title, space: {key: .space.key}, version: {number: (.version.number + 1)}}' \
> modified-page-data.json
else
echo ${REST_CONTENT_FULL_OUTPUT} | \
jq '{body: {storage: {value: (.body.storage.value + "<ac:structured-macro ac:name=\"view-file\" ac:schema-version=\"1\" ac:macro-id=\"'${MACRO_UUID}'\"><ac:parameter ac:name=\"name\"><ri:attachment ri:filename=\"'${ATTACHMENT_FILE_NAME}'\" /></ac:parameter><ac:parameter ac:name=\"height\">250</ac:parameter></ac:structured-macro>"), representation: .body.storage.representation}}, id: .id, type: .type, title: .title, space: {key: .space.key}, version: {number: (.version.number + 1)}}' \
> modified-page-data.json
fi
curl -u ${USER_NAME}:${USER_PASSWORD} \
-X PUT \
-H 'Content-Type: application/json' \
--data @modified-page-data.json \
${CONFLUENCE_BASE_URL}'/rest/api/content/'${PAGE_ID} 2>/dev/null \
| jq -r '.id'
Everything works fine, as long as the Confluence Page <PAGEID> does not have a attachment called "myfile2.txt".
As soon as I upload the file and rerun the Script, I'd expect I would upload the file again as the newest version. The other myfile2.txt file would be the older version.
Instead, nothing happens and I get the error:
jq: error (at <stdin>:0): Cannot iterate over null (null)
Could anybody please help with that problem?
Thank you in advance!
Kind regards,
Felix
Dear @Felix Köhn ,
yes, you can! ;)
a) get the ID of your attachment to update:
GET /rest/content/{id}/child/attachment
b) update the attachment data:
POST /rest/content/{id}/child/attachment/{attachmentId}/data
So long
Thomas D
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.