Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to copy and paste entire page via REST API?

Mark Wendell Jose May 24, 2015

I am trying to copy entire page via rest API,

saw an answer in here How to copy a Confluence page via REST API at the right position?, but I do not know what to get from the body.storage and the format on how to pass it in the payload of a post

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Ari Vésteinsson September 24, 2016

I was playing around with Poweshell and the Confluence REST API and created two utility functions, one for copying a page tree and another for deleting a page tree. Perhaps it could be of use to you. 

I uploaded the Powershell script to GitHub: https://github.com/ForritAri/ConfluencePageTrees.

 

George Ivanov July 11, 2017

Hi all, 

with '/rest/api/content' am I able to overwrite an existing page (by page id)?

Or, even better: to create if it does not exist in the target instance->space and overwrite if it exists

Like ariedel likes this
0 votes
Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 26, 2015

As long as you want to copy it to the same space, I believe this is about the simplest example that could possibly work (using jQuery/Javascript, runnable in your browser console).

var copyPage = function(pageId, newParentId) {
  jQuery.ajax({
      url: contextPath + '/rest/api/content/' + pageId + '?expand=space,body.storage,ancestors',
      success: function(response) {
        response.title += " (Copy)";
        if (newParentId) {
          response.ancestors[0].id = newParentId;
        }
        jQuery.ajax({
            contentType: 'application/json',
            type: 'POST',
            url: '/rest/api/content',
            data: JSON.stringify(response),
            error: function(response) {
              console.log(response);
            }
        });
      }
  });
}

Just run copyPage("12345") to copy the page to the same parent, and copyPage("12345","67890") to copy the page to be a child of the page with the id of 67890.

TAGS
AUG Leaders

Atlassian Community Events