Friday, September 16, 2011

How to create pages using curl command in CQ / WEM

Use Case For testing (If you are trying to capture certain events or testing something in MSM)

Solution There are various way of creating pages using curl command in CQ Some of them are as follows

1) curl -u admin:admin –F cmd="createPage" -F label="" -F parentPath="/content/geometrixx/en/company" -F template="/apps/geometrixx/templates/contentpage" -F title="new page" http://localhost:4502/bin/wcmcommand

2) curl -u admin:admin -F "jcr:primaryType=cq:Page" -F "jcr:content/jcr:primaryType=cq:PageContent" -F "jcr:content/jcr:title=New Page" -F "jcr:content/sling:resourceType=geometrixx/components/contentpage" http://localhost:4502/content/geometrixx/en/page

3) curl --data jcr:primaryType=cq:page --user admin:admin http://<host>:<port>/content/geometrixx/en/toolbar/test3

And then

curl --data jcr:primaryType=PageContent --user admin:admin http://<host>:<port>/content/geometrixx/en/toolbar/test3/jcr:content


You can also use JAVA code to create pages in CQ.

Sling Content Manipulation POST API detail can be found here http://sling.apache.org/site/manipulating-content-the-slingpostservlet-servletspost.html

Thanks Henry Seginor, Paul from Adobe for providing this information

21 comments:

  1. Hi Yogesh.
    Is there a similar way to create and maintain users/groups/permissons using curl?
    I've been trying to do this using the examples from the Apache Sling homepage, but I get a number of error messages each time.

    ReplyDelete
  2. Did you check http://forums.adobe.com/message/4031201
    And http://sling.apache.org/site/managing-users-and-groups-jackrabbitusermanager.html

    You need appropriate bundle for this to work

    Or try

    curl -u admin:admin -F:status=browser -F_charset_=UTF-8 -Frep:password=test -Frep:userId=yogeshTest -FgivenName=yogesh -FfamilyName=upadhyay http://localhost:4502/libs/cq/security/authorizables/POST

    ReplyDelete
  3. Is there a way to activate a page using cURL?

    ReplyDelete
    Replies
    1. Sorry for replying late .. was really busy ... You can use [1] or [2] .. let me know if that helps

      [1] curl -u admin:admin -F cmd="Activate" -F path="some page path" http://localhost:4502/bin/replicate.json

      [2] curl -u admin:admin -F cmd=activate -F ignoredeactivated=true -F onlymodified=true -F path= http://localhost:4502/etc/replication/treeactivation.html

      Delete
  4. I'm trying to add a replication agent on the author and getting a response of:

    Method POST not supported (405)
    The requested URL /bin/wcmcommand resulted in an error in com.day.cq.wcm.core.impl.commands.WCMCommandServlet.

    This is the command that I'm sending:

    curl -u admin:admin –F cmd="createPage" -F label="publish22" -F title="publish22" -F parentPath="/etc/replication/agents.author" -F template="/libs/cq/replication/templates/agent" https://author.hostname.com/bin/wcmcommand

    ReplyDelete
  5. ok, looks like this works:

    curl -u admin:admin --data "status=browser&cmd=createPage&label=publish22&title=publish22&parentPath=/etc/replication/agents.author&template=/libs/cq/replication/templates/agent" https://author.hostname.com/bin/wcmcommand

    ReplyDelete
  6. Hi,

    I am creating page using wcmcommand through jquery and its being created successfully but I am not able to add additional properties in page jcr for example I want to add property fullname:asedd in page jcr. Can you please help me out?

    ReplyDelete
    Replies
    1. Sujeet,

      You can also do that using CURL or form post see http://sling.apache.org/site/manipulating-content-the-slingpostservlet-servletspost.html for example.

      Delete
  7. Can you please tell me where can i find curl command?

    ReplyDelete
  8. Sujeet,

    For curl please see http://curl.haxx.se/docs/manpage.html it comes with any Unix based system. For windows you can use something like Wget to do same thing.

    Yogesh

    ReplyDelete
  9. Is there any similar way to create packages using curl, I need to pass the value of filters as well through curl.

    Thanks
    Rohit Varshney

    ReplyDelete
    Replies
    1. Check Here if this helps http://www.cqtutorial.com/courses/cq-admin/cq-admin-lessons/cq-maintenance/cq-package-manager

      Delete
  10. How to rename a package using curl ?

    Thanks
    Rohit Varshney

    ReplyDelete
    Replies
    1. Check here http://www.cqtutorial.com/courses/cq-admin/cq-admin-lessons/cq-maintenance/cq-package-manager

      Delete
  11. Hi.. I am Migrating content from DCTM to CQ.
    I want to use com.day.cq.wcm.api.Pagemanager in my Java code.
    Can you please tell me which jar file can be used ?

    ReplyDelete
    Replies
    1. You can not use PageManager Jar file outside CQ Context. You have to use CURL service or jackrabbit API. In case you have to find dependency within CQ context for pom.xml then you can use http://HOST:PORT/system/console/depfinder and put your package name.

      Delete
  12. Hi,

    I am trying the below curl command to add two filters to a package with in CQ5.4 author, however I am facing errors.

    curl -g -u admin:admin -X POST --data _charset_=UTF-8 --data groupName=my_packages --data version=0 --data filter=[{"root":"/apps/test/components/adv","rules":[]},{"root":"/apps/test/components/check-link","rules":[]}] --data packageName=curlpackage-0 --data path=/etc/packages/my_packages/curlpackage-0-0.zip http://localhost:4502/crx/packmgr/update.jsp

    Error:{"success":false,"msg":"Could not modify package. Missing value. at character 7
    of [{root:/apps/LearnBuild/components/att-advantage,rules:[]},{root:/apps/LearnB
    uild/components/check-link,rules:[]}]","path":"/etc/packages/my_packages/curlpac
    kage-0-0.zip"}

    Can you please help? Please let me know what is missing here. I checked the below links as well, but still need to get this error resolved.

    http://www.cqtutorial.com/courses/cq-admin/cq-admin-lessons/cq-maintenance/cq-package-manager

    http://aemfaq.blogspot.com/2013/09/creating-package-with-filtersexclusion.html

    ReplyDelete
  13. Hi Yogesh,

    Thanks for the post.

    How we do pass DATA TYPE of property using CURL command or a MULTI VALUE property

    For example:
    I have a MULTI VALUE property whose type in CRX is appearing as "String[]"

    How do we do this using CURL. What should I write in CURL command to specify this. Currently by default CURL sets the data type as "String" for everything.

    ReplyDelete
    Replies
    1. Please check http://sling.apache.org/documentation/bundles/manipulating-content-the-slingpostservlet-servlets-post.html either you can use multiple value for same property or TypeHint

      Delete
  14. Yogesh,

    You are simply awsome !

    Yes TypeHint works like charm. Also using TypeHint we can specify the DATATYPE too.

    So if I give below parameter with Boolean[] it create multi value
    -F "jcr:content/myVar@TypeHint=Boolean[]"

    and if I remove [] then it creates single value property
    -F "jcr:content/myVar@TypeHint=Boolean"

    Example Command:
    1) MULTI VALUE

    curl -u admin:admin -F "jcr:primaryType=cq:Page" -F "jcr:content/jcr:primaryType=cq:PageContent" -F "jcr:content/myVar@TypeHint=Boolean[]" -F "jcr:content/myVar=true" -F "jcr:content/sling:resourceType=geometrixx/components/contentpage" http://localhost:4502/content/geometrixx/en/rohit2

    2) SINGLE VALUE

    curl -u admin:admin -F "jcr:primaryType=cq:Page" -F "jcr:content/jcr:primaryType=cq:PageContent" -F "jcr:content/myVar@TypeHint=Boolean" -F "jcr:content/myVar=true" -F "jcr:content/sling:resourceType=geometrixx/components/contentpage" http://localhost:4502/content/geometrixx/en/rohit2




    ReplyDelete