The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

Adding link to attachment in Confluence Page Via Rest API

Adolfo Santiago Risquez
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!
August 24, 2018

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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Charles Mervin
January 23, 2020

@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)

0 votes
Ganesh Kumar
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!
January 7, 2020

I have the same question. 

@Adolfo Santiago Risquez Did you get the answer?

0 votes
Adolfo Santiago Risquez
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 26, 2018

Hi,

Can someone help me?

Thanks

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

TAGS
AUG Leaders

Atlassian Community Events