Created

Apr 27, 2012

Creating multiple pages in one REST call

Posted by Feike Visser

This week a question came up on how to create multiple content-pages with one REST-call in Adobe CQ5.

Of course you first reaction is "great question", but how is that going to work?

The solution is a very nice, very simple one and shows how powerful REST is.

<html>
   <body>
      <form method="post" action="http://localhost:4502/content/myproject/mycountry/myregion/mycontent">
         <input type="hidden" name="../../../jcr:primaryType" value="cq:Page"/>
         <input type="hidden" name="../../../jcr:content"/>
         <input type="hidden" name="../../../jcr:content/jcr:primaryType" value="cq:PageContent"/>

         <input type="hidden" name="../../jcr:primaryType" value="cq:Page"/>
         <input type="hidden" name="../../jcr:content"/>
         <input type="hidden" name="../../jcr:content/jcr:primaryType" value="cq:PageContent"/>

         <input type="hidden" name="../jcr:primaryType" value="cq:Page"/>
         <input type="hidden" name="../jcr:content"/>
         <input type="hidden" name="../jcr:content/jcr:primaryType" value="cq:PageContent"/>

         <input type="hidden" name="./jcr:primaryType" value="cq:Page"/>
         <input type="hidden" name="./jcr:content"/>
         <input type="hidden" name="./jcr:content/jcr:primaryType" value="cq:PageContent"/>


         <input type="submit"/>
      </form>
   </body>
</html>

The form as shown above about will create the complete path to "/content/myproject/mycountry/myregion/mycontent", so that will mean four pages "myproject", "mycountry", "myregion", "mycontent".

With the ../ notation you can refer to the correct level and specify properties you want to assign

To test this in your local CQ5-instance you create a .html file and copy the content from the form into the file. Open the file in a browser and hit the 'Submit' button.

COMMENTS

  • By Rob In der Maur - 12:16 PM on Apr 27, 2012   Reply
    Great example of how easy it is to modify the content repository by simply using the SlingPostServlet. Ensure you log on to CQ5 before trying this html file otherwise you will get an Authentication Failed.
  • By Alex - 1:47 PM on Apr 30, 2012   Reply
    Instead of the somewhat complex ../ relative paths used in the post, you can also address a common parent as request resource and use relative paths down from there:

    POST /content
    myproject/jcr:primaryType=cq:Page
    myproject/mycountry/jcr:primaryType=cq:Page
    myproject/mycountry/myregion/jcr:primaryType=cq:Page
    myproject/mycountry/myregion/mycontent/jcr:primaryType=cq:Page

    Might be a bit more intuitive.

    The post servlet will create any missing (intermediary) node, regardless of whether it is part of the request resource or of any parameters pointing to a property.
  • By foreclosure attorneys - 2:17 AM on Jan 27, 2013   Reply
    This topic is the one that I have been looking into from last 3 days and your insight is extremely useful. Thanks for sharing this information.
  • By Windows 8 drivers - 8:08 AM on Mar 04, 2013   Reply
    I am totally new to this page and have no idea about computers and technology. The whole thing on this page appears like Greek and Latin to me. It would be great if someone who has an idea about REST and its other aspects could share some thoughts.
  • By Tommy Anderson - 6:33 PM on Mar 05, 2013   Reply
    Hello Feike, just wanted to thank you for this tutorial, if you can call it that... it helped me to solve my problem
  • By wqeywerwe wewewewe - 2:35 AM on Apr 08, 2013   Reply
    I'm no expert, but CQ5 is a large enterprise class content management system. I'm assuming this line of code makes it possible to publish multiple pages rather easily instead on making multiple entries. I've been thinking of making the switch, but it seems like overkill for anything besides fortune 500 companies.
  • By photo booth nj - 5:06 PM on Apr 27, 2013   Reply
    Thanks for keeping us informed
  • By wedding photographer nj - 9:49 PM on Apr 27, 2013   Reply
    Its great to see you taking the time to share this information
  • By austin wedding photographer - 8:59 AM on May 04, 2013   Reply
    Great post i must say and thanks for the information. Education is definitely a sticky subject.
  • By Binäre optionen broker - 5:42 PM on May 13, 2013   Reply
    I actually though this process would involve so much work rather than just this simple code on the CQ5 platform, its great to see how simple this application is encrypted.