How to add excel attachment to multiple pages using REST Api

OToole August 16, 2018

Hi All,

I have a page with an excel attachment,  I want to be able to create new confluence pages from Jira that have a link to that attachment so that all pages are editing the same document.

I get the  link to the attachment using the get 

{_links={base=http://******:8090, context=, self=http://*******:8090/rest/api/content/5242957/child/attachment?filename=FM00872.xlsx}, limit=50, results=[], size=0, start=0}

// get attachment
def attach = "rest/api/content/"+ page_id + "/child/attachment?filename=FM00872.xlsx"
log.debug attach

authenticatedRequestFactory
.createRequest(Request.MethodType.GET, attach)
.addHeader("Content-Type", "application/json")
.execute(
new ResponseHandler<Response>()
{
@Override
void handle(Response response) throws ResponseException {
confResponse = new JsonSlurper().parseText(response.getResponseBodyAsString())
log.debug confResponse
}
}) 

 but now how do I add it to the new page?   I have this code that will load a file as an attachment.  But I don't have a file now, just a url link.  So what do I use in place of  .setFiles()

It doesn't matter to me if it shows up in the second page as a link or an excel attachment as long as the user can open and edit it.

If it is a link in the page rather than an attachment I would like to be able to just click on the link and have it open in excel,  is that possible?  if so I believe I would need the link to look something more like  

<a href="/plugins/servlet/confluence/editinword/5242957/attachments/FM00872.xlsx" rel="nofollow" class="office-editable-pathauth" title="">
<span>
Edit in Office
</span> </a>

// Add attachment as child
authenticatedRequestFactory
.createRequest(Request.MethodType.POST, "rest/api/content/" + page_id + "/child/attachment")
.addHeader("X-Atlassian-Token", "nocheck")
.setFiles(partList)
.execute(new ResponseHandler<Response>() {
@Override
void handle(Response response) throws ResponseException {
if(response.statusCode != HttpURLConnection.HTTP_OK) {
log.debug response.statusCode
log.debug response.getResponseBodyAsString()
throw new Exception(response.getResponseBodyAsString())
}
}
})

Thanks

 

1 answer

0 votes
Gonchik Tsymzhitov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 8, 2018

Hi! 

Have you tried for the full generated page as Confluence storage format. I mean upload attachments, than create 2 pages.  Where one is just link to another attachments.

After compare pages, You can regenerate page programmatically with correct link

Cheers,

Gonchik Tsymzhitov   

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events