Forums

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

Confluence API - How to set title of an attachment preview added to a page with "view file" macro

M Umer
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!
September 19, 2021

I am trying to add a preview of an attached file to a page through confluence API with view file macro. It works fine but the title of the preview is some random Id. When I add a preview through web it shows the file name as the title of the attachment preview. I can't find the documentation to set this preview title. The left one in the image is added through API and the right one through web.

This is the call to upload the attachment 

curl -v -S --header 'Authorization: Basic ${token}' -X POST -H "X-Atlassian-Token: no-check" -F "file=@filePath" https://abc.atlassian.net/wiki/rest/api/content/${PageId}/child/attachment

This is the page content

<p class="media-group">
<ac:structured-macro ac:name="view-file" ac:schema-version="1" ac:macro-id="8470d36e-7035-4ee4-9ea5-d8a3fc87b843">
<ac:parameter ac:name="name">
<ri:attachment ri:filename="' + fileName + '" ri:version-at-save="1" />
</ac:parameter>
</ac:structured-macro>
</p>

This is the JSON body

{
"type": "page",
"title": "pageTitle",
"version": {
"number": 2
},
"body": {
"storage": {
"value": "${content}",
"representation": "storage"
}
}
}

This is the call to the API to update page content

curl -H 'Authorization: Basic ${token}' -H 'Content-Type: application/json' -X PUT -d'@requestBody' https://abc.atlassian.net/wiki/rest/api/content/${PageId}?expand=body.storage

 

attachments.jpg

1 answer

0 votes
Kishan Sharma
Community Champion
September 19, 2021

Hi @M Umer Welcome to the Atlassian Community!

Are you passing below parameter in your json body ? it will update title for the attachment and might solve your problem. 

"title": "<string>"

Please share the json body if possible and the endpoint you are using.

M Umer
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!
September 19, 2021

Updated my question.

Kishan Sharma
Community Champion
September 21, 2021

thank you, can you please confirm if this is for Cloud or Server, because i am unable to find view-file macro on cloud.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events