Using curl command line tool you can do all sort of operations like create , delete, move and copy operation in AEM, this is very useful when it comes to maintenance projects. simple example is if you are using blueprint to create pages and after some point of time if you want to update blueprint template at code level then you need to create a page once again some client’s will accept to author pages once again and some client don’t so here, the curl commands help’s us to update page’s

What is Curl ?

Curl is a command line tool for doing all sorts of URL manipulations and transfers, you can download and install curl command line tool by clicking this link
Once the installation is completed just execute below command to cross check whether the installation is successful or not
“curl –help”

AEM Node Operations

Changing order of a node

The first thing which I am going to cover here is changing order of node, the below command moves eventviewer node to after dsc node

curl -u admin:admin -F":order=after dsc" http://localhost:4502//content/geometrixx/en/events/
eventviewer

You can use :order operation by using these parameters such as first, last, before, after and numeric

Create a node

The below command creates a node

curl --data jcr:primaryType=nt:unstructured -u admin:admin http://localhost:4502/content/geometrixx/en/events/keysandstrokes
Move a node

Use below command to move a node under dsc node

curl -u admin:admin -F":operation=move" -F":dest=/content/geometrixx/en/events/
dsc/" http://localhost:4502/content/geometrixx/en/events/
eventviewer
Copy a node

Use below command to copy and paste eventviewer node to below dsc node

curl -u admin:admin -F":operation=copy" -F":dest=/content/geometrixx/en/events/
dsc/" http://localhost:4502/content/geometrixx/en/events/
eventviewer
Delete a node

Use below command to delete eventviewer node

curl -F":operation=delete" http://localhost:4502/content/geometrixx/en/events/eventviewer

AEM Page operations

Create a page using AEM Curl command line tool
curl -u admin:admin -F "jcr:primaryType=cq:Page" -F "jcr:content/jcr:primaryType=cq:PageContent" -F "jcr:content/jcr:title=keysandstrokes" -F "jcr:content/sling:resourceType=geometrixx/components/contentpage" http://localhost:4502/content/geometrixx/en/keysandstrokes
Delete a page
curl -u admin:admin -X POST -F cmd="deletePage" -F path="/content/geometrixx/en/keysandstrokes" -F "_charset_"="utf-8" http://localhost:4502/bin/wcmcommand
Move a page
curl -u admin:admin -F":operation=move" -F":dest=/content/geometrixx/en/toolbar/" http://localhost:4502/content/geometrixx/en/keysandstrokes
Copy a page
curl -u admin:admin -F":operation=copy" -F":dest=/content/geometrixx/en/products/" http://localhost:4502/content/geometrixx/en/keysandstrokes
Activate a page
curl -u admin:admin -X POST -F path="/content/geometrixx/en/products" -F cmd="activate" http://localhost:4502/bin/replicate.json
Deactivate a page
curl -u admin:admin -X POST -F path="/content/geometrixx/en/products" -F cmd="deactivate" http://localhost:4502/bin/replicate.json

AEM Package Manager Operations

list out all the packages in AEM instance

curl -u admin:admin http://localhost:4502/crx/packmgr/service.jsp?cmd=ls

The below list of commands helps you to perform different operations in AEM package manager,  you just need to change command keyword

Command Name  Description
cmd=ls list of all the packages in AEM instances
cmd=install Install an existing package
cmd=uninstall Uninstall an existing package
cmd=build Build an existing package
cmd=delete Delete an existing package
cmd=help to see list of commands

Upload package

curl -u admin:admin -F file=@"C:\aem\keysandstrokes.zip" -F name="keysandstrokes" -F force=true -F install=false http://localhost:4502/crx/packmgr/service.jsp

Upload and install package

curl -u admin:admin -F file=@"C:\ame\keysandstrokes.zip" -F name="keysandstrokes" -F force=true -F install=true http://localhost:4502/crx/packmgr/service.jsp

By coderss

Leave a Reply

Your email address will not be published. Required fields are marked *