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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

How can i create a new page from a users template using rest api

Hi, I want create a new page from a users template. How can i do that using rest api?
If you can give me example on Python, I will be very grateful!
I will also be glad for any help!

3 answers

1 vote

Hello Михаил and welcome to the Community!

To use the REST API to create a page from a users template you will need to complete a few steps. You will need to take this as an approach to find the template, extract the content as a storage value and then pass this through to your REST API call to create a page. Here is how it would look in steps:

  1. Locate an example page with the template applied.
  2. Scrub that page via a REST API call using the following endpoint: GET /rest/api/content (This will allow you to get the storage format).
  3. From this, pass the storage format to your create call using this endpoint: POST /rest/api/content

While these steps are simplified, this process should allow you to create a page based off a user template.

Regards,
Stephen Sifers

Hello Stephen,

I have the same question and am very grateful for the instructions. But I get stuck on the first step already. What does "Locate an example page with the template applied." mean?

Well, I have a user template. It has a title and an entityid, but I can't get both via GET /rest/api/content. Therefore I need type=page and a "title". If I first create an example page manually, I can of course query this, but that's exactly what I don't want.

Thanks,

Volker

 function criaPagina() {
 
      //This creates a page in a space.
      var paginaano = $('#ano :selected').val();
      var demanda = $("#demanda");
      var link = $("#link");
      var jsondata = {
          "type": "page",
          "title": demanda.val(),
          "ancestors": [{
              "id": paginaano
            }],
          "space": {
              "key": AJS.params.spaceKey
          },
          "body": {
              "storage": {
                  "value": "<p>Clique no link abaixo para acessar a demanda no Clarity:</p>" + "<a class='009' href='" + encodeURIComponent(link.val())+"'>Demanda no Clarity</a>" + buscaTemplate(),
                  "representation": "storage"
              }
          }
      };
 
      $.ajax({
          type: "POST",
          url: "/rest/api/content/",
          contentType: "application/json; charset=utf-8",
          dataType: "json",
          async: false,
          headers: {
                "Authorization": "Basic " + UserBase64
           },
          xhrFields: {
          withCredentials: false
          },
          data: JSON.stringify(jsondata),
          success: function (response) {
              console.log('Page saved!');
              atualizaPagina(response["id"]);
          },
          error: function (xhr, errorText) {
              console.log('Error ' + xhr.responseText);
alert("Algo deu errado, consulte o administrador da ferramenta para mais detalhes");           }
      });
  }
 
  function buscaTemplate() {
      var dataToReturn = "Error";
      AJS.$.ajax({
          url: "/rest/api/content/" + homePgId + "?expand=body.storage",
          type: "GET",
          dataType: "JSON",
          async: false,
          success: function (msg) {
              dataToReturn = (msg["body"]["storage"]["value"]);
          },
error: function (xhr, errorText) {
              console.log('Error ' + xhr.responseText);
alert("Algo deu errado, consulte o administrador da ferramenta para mais detalhes");           }
      });
      return dataToReturn;
  }

Is it possible to update template variables while creating new page with the template ? I have a template with 5-6 variables and need to update those to new values when creating new page. 

Like xiapazi xiapazi likes this

Upvote this so we can get the api method! 


https://jira.atlassian.com/browse/CONFSERVER-11393

Suggest an answer

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

What do you think is the most *delightful* Confluence feature? Comment for a prize!

- Create your own custom emoji 🔥 - "Shake for Feedback" on mobile 📱 - An endless supply of GIFs via GIPHY 🤩 Is there anything quite as nice as a pleasant surprise? Comment below with what...

335 views 23 8
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