April 16, 2020
Estimated Post Reading Time ~

Adobe CQ5 AEM cURL Commands

The focus of this tutorial is on basic or most frequently used AEM cURL commands. There are no limits to the number of cURL commands that you can use with AEM.In this tutorial, I will show you how to create any custom cURL command and a few flavors of basic AEM cURL commands.

After completing this article you will have a clear understanding of:
What is the cUrl?
How to install a cUrl?
How to find cURL command for any AEM Operation?
List of useful AEM cURL commands and their usage?

What is the cUrl?
cURL is an open-source command-line tool for performing URL Manipulations. It is designed for transferring data using various protocols like FTP, FTPS, Gopher, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP and many more. cURL was released in 1997. The name cURL stands for “see URL“.

How to install a cUrl?
You can download a cURL executable file from http://curl.haxx.se/dlwiz/ for your operating system or cURL from http://curl.haxx.se/download.html according to your operating system. Windows users can follow below steps if you have downloaded executable file:-
Unzip the tar file.

Set the Environmental Variable. Append the path of cURL.exe directory(D:\cURL\AMD64\) or custom path where you have unzipped the file to “Path variable”.
Open a command prompt type curl –help and enter. If everything is ok u will get Curl basic commands syntaxes else you will get an error message “curl” is not recognized as an internal or external batch command.

How to find cURL command for any AEM Operation?
In this article, I have covered most frequently asked AEM cURL commands. But you are free to find out any cURL command used for any AEM operation. Follow below steps to know any AEM cURL command:
Use Firefox –> Press F12 and open FireBug console.
Click on the “NET” tab in FireBug and enable it by clicking “Enable”.
Perform any AEM operation on a webpage.
Click “invoke”.

In FireBug console, you will see the full request URL when you take mouse on top of your request url under the POST tab. Copy full path along with parameters from the “POST” tab under it.
You got your URL that you can append at the end of the cURL command and access the same resource using cURL.

The above process is very much useful for testers to automate AEM operations. Let's have a look at AEM cURL commands.

List of useful AEM cURL commands and its usage
As we all know AEM is based on REST protocol, it supports only http request and cURL can be used as a magical wand to do anything in AEM in just a blink.

I have divided cURL commands based on its usage into the following sections:
  1. AEM User Management cURL commands.
  2. AEM Package Management cURL commands.
  3. AEM OSGI Bundle Management cURL commands.
  4. AEM JCR Query builder cURL commands.
  5. AEM Backup cURL commands.
  6. AEM JCR Node Manangement cURL commands.
  7. AEM Replication cURL commands.
  8. AEM Page Management cURL commands.
  9. Few AEM Miscellaneous cURL Commands.
AEM User Management cURL commands:
Below are the AEM cUrl commands for User Management :

Create a new User using cURL AEM command
curl -u admin:admin -FcreateUser= -FauthorizableId=ankur-Frep:password=ankur http://localhost:4502/libs/granite/security/post/authorizables
Create a new user under the specified folder
curl -u admin:admin -FcreateUser= -FauthorizableId=testuser -Frep:password=testuser -FintermediatePath="/home/users/test/" http://localhost:4502/libs/granite/security/post/authorizables
Create a new Group using cURL AEM command
curl -u admin:admin -FcreateGroup=testgroup -FauthorizableId=testGroup http://localhost:4502/libs/granite/security/post/authorizables
Add a Property to an existing User using cURL AEM command
curl -u admin:admin -Fprofile/age=30 http://localhost:4502/home/users/a/ankur.rw.html
Create a User with a profile using cURL AEM command
curl -u admin:admin -FcreateUser=testuser -FauthorizableId=ankura -Frep:password=ankur -Fprofile/gender=male http://localhost:4502/libs/granite/security/post/authorizables
Create a new User as a member of a Group using cURL AEM command
curl -u admin:admin -FcreateUser=testuser -FauthorizableId=testuser -Frep:password=abcd123 -Fmembership=contributor http://localhost:4502/libs/granite/security/post/authorizables
Add User to a Group using cURL AEM command
curl -u admin:admin -FaddMembers=testuser http://localhost:4502/home/groups/t/testGroup.rw.html
Remove a User from a Group using cURL AEM command
curl -u admin:admin -FremoveMembers=testuser http://localhost:4502/home/groups/t/testGroup.rw.html
Set a User’s Group Memberships using cURL AEM command
curl -u admin:admin -Fmembership=contributor -Fmembership=testgroup http://localhost:4502/home/users/t/testuser.rw.html
Delete user and Group using cURL AEM command
curl -u admin:admin -FdeleteAuthorizable= http://localhost:4502/home/users/t/testuser
curl -u admin:admin -FdeleteAuthorizable= http://localhost:4502/home/groups/t/testGroup
Change a user password using cURL AEM command
curl -u testuser:OLD_PWD -F rep:password="NEW_PWD" http://localhost:4502/home/users/t/testuser.rw.html
curl rep:password="test" –user admin:admin http://localhost:4502/home/users/a/alison@geometrixx.com
AEM Package Management cURL commands:

Below are the AEM cUrl commands for Managing Packages in AEM:
AEM cURL command for accessing Help Menu
curl -u admin:admin http://localhost:4502/crx/packmgr/service.jsp?cmd=help

AEM cURL command to get list of all the packages in your AEM instance
curl -u admin:admin http://localhost:4502/crx/packmgr/service.jsp?cmd=ls

Build or Rebuild an existing package using AEM cURL command
curl -u admin:admin -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages/samplepackage.zip?cmd=build
Note: my_packages/samplepackage.zip is the path of the package which need to be built

Delete a package using AEM cURL command
curl -u admin:admin -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages/samplepackage.zip?cmd=delete
Install a package using AEM cURL command
curl -u admin:admin -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages/samplepackage.zip?cmd=install
Uninstall a package using AEM cURL command
curl -u admin:admin -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages/samplepackage.zip?cmd=uninstall
Download a package into local filesystem using AEM cURL command
curl -u admin:admin http://localhost:4502/etc/packages/my_packages/samplepackage.zip > <local filepath>
Upload but don’t install a package from the File system using AEM cURL command
curl -u admin:admin -F file=@"C:\sample\samplepackage.zip" -F name="samplepackage" -F force=true -F install=false http://localhost:4502/crx/packmgr/service.jsp
Upload and Install a package from the File system using AEM cURL command
curl -u admin:admin -F file=@"C:\sample\samplepackage.zip" -F name="samplepackage" -F force=true -F install=true http://localhost:4502/crx/packmgr/service.jsp
AEM OSGI Bundle Management cURL commands:
Below are the AEM cUrl commands for OSGI Bundle Management in AEM:

Build a Bundle using AEM cURL command
curl -u admin:admin -F bundleHome=/apps/training/src/com.day.sample -F descriptor=/apps/training/src/com.day.sample/com.day.sample.bnd http://localhost:4502/libs/crxde/build
Start a Bundle using AEM cURL command
curl -u admin:admin http://localhost:4502/system/console/bundles/com.day.sample -Faction=start
Stop a Bundle using AEM cURL command
curl -u admin:admin http://localhost:4502/system/console/bundles/com.day.sample -Faction=stop
Install a Bundle from the File system using AEM cURL command
curl -u admin:admin -F action=install -F bundlestartlevel=20 -F bundlefile=@"<path of samplejar.jar>" http://localhost:4502/system/console/bundles
AEM JCR Query builder cURL commands:
Below are the AEM cUrl commands for JCR search or JCR query builder in AEM:

Find an Asset from the JCR using AEM cURL command

curl -s -u admin:admin GET "http://localhost:4502/bin/querybuilder.json?path=%2fcontent%2fgeometrixx%2fen&property=fileReference&property.value=%2fcontent%2fdam%2fgeometrixx%2fshapes%2ftri_equilateral.png&type=nt%3aunstructured"
AEM Backup cURL commands:

Below are the AEM cUrl commands for OSGI Bundle Management in AEM 

Initiate backup to a folder using AEM cURL command
curl -u admin:admin -X POST http://localhost:4502/system/console/jmx/com.adobe.granite%3Atype%3DRepository/op/startBackup/java.lang.String?target=C:\sampleFolder\backupTest.zip
Stop a running Backup using AEM cURL command
curl -u admin:admin -X POST http://localhost:4502/libs/granite/backup/content/admin/backups.cancel.html
Note: You can also initiate backup through AEM Backup Console.

AEM JCR Node Manangement cURL commands:
Below are the AEM cUrl comands for JCR Node Management in AEM:

Delete a Node using AEM cURL command
curl -X DELETE http://localhost:4502/content/geometrixx/en/products/jcr:content/par/flash -u admin:admin
Note: You can delete any directory, node and siteusing above command, text after jcr:content is nodeName on which you need to perform action par/flash = Node Name
Create or Add a Node using AEM cURL command
curl --data jcr:primaryType=nt:unstructured --user admin:admin http://localhost:4502/content/geometrixx/en/toolbar/testNode
AEM Replication cURL commands:
Below are the AEM cUrl commands used for replication in AEM:

Activate Page using cURL command
curl -u admin:admin -X POST -F path="/content/geometrixx/en/pag" -F cmd="activate" http://localhost:4502/bin/replicate.json
Deactivate Page using cURL command
curl -u admin:admin -X POST -F path="/content/geometrixx/en/pag" -F cmd="deactivate" http://localhost:4502/bin/replicate.json
Tree Activation(entire tree structure) using cURL command
curl -u admin:admin -F cmd=activate -F ignoredeactivated=true -F onlymodified=true -F path=/content/geometrixx/en/community http://localhost:4502/etc/replication/treeactivation.html

Note: Change Path variable in script to activate or deactivate respective page.

AEM Page Management cURL commands:
Below are the AEM cUrl commands used for page management in AEM:

Lock a Page using AEM cURL command
curl -u admin:admin -X POST -F cmd="lockPage" -F path="/content/geometrixx/en/toolbar/contacts" -F "_charset_"="utf-8" http://localhost:4502/bin/wcmcommand
Unlock a Page using AEM cURL command
curl -u admin:admin -X POST -F cmd="unlockPage" -F path="/content/geometrixx/en/toolbar/contacts" -F "_charset_"="utf-8" http://localhost:4502/bin/wcmcommand
Copy or Move a Page using AEM cURL command
curl -u admin:admin -F:operation=copy -F:dest=/content/geometrixx/en/products/contacts http://localhost:4502/content/geometrixx/en/toolbar/contacts
Few AEM Miscellaneous cURL Commands:
Below are the few miscellaneous AEM cUrl commands:

Datastore Garbage Collection using AEM cURL command
curl -u admin:admin -X POST http://localhost:4502/system/console/jmx/com.adobe.granite:type=Repository/op/runDataStoreGarbageCollection/java.lang.Boolean
Tar Optimization using AEM cURL command
curl -u admin:admin -X POST http://localhost:4502/system/console/jmx/com.adobe.granite:type=Repository/op/startTarOptimization/
Flush Dispatcher Cache using AEM cURL command
curl -H "CQ-Action: Flush" -H "CQ-Handle: /content/geometrixx/en/products" -H "CQ-Path:/content/geometrixx/en/products" -H "Content-Length: 0" -H "Content-Type: application/octet-stream" http://dispatcher-server-hostname:port/dispatcher/invalidate.cache



By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.