It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Adding link to attachment in Confluence Page Via Rest API Edited

Hello!,

 

I need to know if it is possible via rest api to show an attachment on a confluence page as if it were a kind of hyperlink, with a custom text.

I'm trying to do this but it doesn't work for me:



node {
stage("Create hyperlink to attachment"){
sh """
curl -s -D- -H "Authorization: Basic XXXXXXXXXX:XXXXXXXXXXXX" -X PUT -H 'Content-Type: application/json' -d'{
"id": "84652952",
"type": "page",
"status": "current",
"title": "Prueba-Jenkins",
"body": {
"storage": {
"value":
"<ac:link>
<ri:attachment ri:filename="FILENAME.docx"/>
<ac:plain-text-link-body>
<![CDATA[RANDOM COMMENT]]>
</ac:plain-text-link-body>
</ac:link>",
"representation": "storage"
}
}
}' https://XXXXXXXXXXXXXX/confluence/rest/api/content/84652952
"""
}
}

 

Is this way of working correct?

 

Thanks in advance,

Adolfo S.

3 answers

Hi,

Can someone help me?

Thanks

0 votes

I have the same question. 

@Adolfo Santiago Risquez Did you get the answer?

@Ganesh Kumar 

 

Below CURL command did the trick for me. I used shell script and for convenience I have entered every value in a new line, in actual I executed this as a one liner.

Key things to note

 

  • Escape any double quotes if any inside the storage value part. I have highlighted the portions in BOLD where I used '\'  to escape double quotes 
  • Mention the version number correctly. It has to be +1 of your current page version

curl -u 'username:password' -X PUT -H 'Content-Type: application/json' -d '{
"id": "00000000",
"type": "page",
"title": "New page",
"space":{"key":"Test"},
"body":{"storage":{"value":"<table class=\"wrapped\"><colgroup><col /></colgroup><tbody><tr><th><h3>Hyperlink Text</h3></th></tr><tr><td><ac:link><ri:attachment ri:filename=\"Test.csv\" /><ac:plain-text-link-body><![CDATA[Bitbucket_AD_Userlist]]></ac:plain-text-link-body></ac:link></td></tr></tbody></table>",
"representation":"storage"}},
"version":{"number":4}}'

https://confluence.org.com/rest/api/content/00000000

 

Reference: https://developer.atlassian.com/server/confluence/confluence-rest-api-examples/ (Update a Page part)

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Confluence

How is your team having fun and bonding, remotely, utilizing Confluence?

Thanks everyone for answering last week’s question. The winner of the random drawing from those who commented is: @LarryBrock I’ll contact you separately with your prize details. This wee...

276 views 9 6
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you