Hi,
Through this post , I would like to introduce cURL commands for numerous applications in AEM. Its quite a handy tool to deal with packages, backups, and various usecases in AEM. You may find ample of applications of cURL by the end of this post. After going through the post you will be able to write curl commands for almost any functionality in AEM on your own.
So lets get started.
What is cURL?
cURL is a command line tool for doing all sorts of URL manipulations and transfers. It is used for transferring data using various protocols, HTTP,FTP, Gopher, TELNET, etc. It comes in handy for automation, and if you know how script you can create powerful tools that will facilitate your work process. The name stands for Curl URL Request Library.
Installation
You may download and install cURL from http://curl.haxx.se/download.html as per the OS you are using . For Windows users make sure you have appended the Environment variable ‘Path‘ with C:\Program Files\cURL\bin (or the path of bin where you have installed cURL).
Now you may able to open your command prompt and type curl. If everything is fine your cURL is installed. Go try it using
cURL help:
curl --help
Install the manual for all the default cURL commands: This will help you as a reference if you want to explore more in cURL
curl --manual > <curlManual.txt> /*give complete path of the text file curlManual.txt above */
cURL GET:
curl www.google.co.in
Useful cURL Commands
Now let us jump to AEM application of cURL . cURL is mostly used for handling packages in AEM , but you may use it for other purposes too. As AEM is based on REST protocol , cURL can be used to do anything and everything in AEM . I will start stating its application with commands and examples : starting from simpler to complex usage.
You may visit your AEM instance and hit the URL http://localhost:4502/crx/packmgr/service.jsp for getting the list of commands which are useful in AEM. I will illustrate each application below. All the below commands are tried and tested on AEM 6.0
Package Management Commands:
- Help Menu for useful AEM commands
curl -u admin:admin http://localhost:4502/crx/packmgr/service.jsp?cmd=help
- List of all the packages in your AEM instance
curl -u admin:admin http://localhost:4502/crx/packmgr/service.jsp?cmd=ls
- Build an existing package
curl -u admin:admin -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages/samplepackage.zip?cmd=build
- Delete an existing package
curl -u admin:admin -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages/samplepackage.zip?cmd=delete
- Install an existing package
curl -u admin:admin -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages/samplepackage.zip?cmd=install
- Uninstall an existing package
curl -u admin:admin -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages/samplepackage.zip?cmd=uninstall
- Download an existing package into filesystem
curl -u admin:admin http://localhost:4502/etc/packages/my_packages/samplepackage.zip > <local filepath>
- Upload and don’t install an existing package from File system
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 an existing package from File system
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
User Management Commands:
- Create a new User
curl -u admin:admin -FcreateUser= -FauthorizableId=hashim -Frep:password=hashim http://localhost:4502/libs/granite/security/post/authorizables
- Create a new Group
curl -u admin:admin -FcreateGroup=group1 -FauthorizableId=testGroup1 http://localhost:4502/libs/granite/security/post/authorizables
- Add a Property to an existing User
curl -u admin:admin -Fprofile/age=25 http://localhost:4502/home/users/h/hashim.rw.html
- Create a User with a profile
curl -u admin:admin -FcreateUser=testuser -FauthorizableId=hashimkhan -Frep:password=hashimkhan -Fprofile/gender=male http://localhost:4502/libs/granite/security/post/authorizables
- Create a new User as a member of a Group
curl -u admin:admin -FcreateUser=testuser -FauthorizableId=testuser -Frep:password=abc123 -Fmembership=contributor http://localhost:4502/libs/granite/security/post/authorizables
- Add User to a Group
curl -u admin:admin -FaddMembers=testuser1 http://localhost:4502/home/groups/t/testGroup.rw.html
- Remove a User from a Group
curl -u admin:admin -FremoveMembers=testuser1 http://localhost:4502/home/groups/t/testGroup.rw.html
- Set a User’s Group Memberships
curl -u admin:admin -Fmembership=contributor -Fmembership=testgroup http://localhost:4502/home/users/t/testuser.rw.html
- Delete user and Group
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
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/alister@geometrixx.com
JCR Node Management Commands:
- Delete a Node
curl -X DELETE http://localhost:4502/content/geometrixx/en/products/jcr:content/par/flash -u admin:admin
- Create or Add a Node
curl --data jcr:primaryType=nt:unstructured --user admin:admin http://localhost:4502/content/geometrixx/en/toolbar/test3
- Create a Page (Although its not recommended to do with cURL, as we have Page Manager API for this.)
curl -u admin:admin -F "jcr:primaryType=cq:Page" -F "jcr:content/jcr:primaryType=cq:PageContent" -F "jcr:content/jcr:title=Curl Page" -F "jcr:content/sling:resourceType=geometrixx/components/contentpage" http://localhost:4502/content/geometrixx/en/curlPage
AEM Replication Commands:
- Activate
curl -u admin:admin -X POST -F path="/content/geometrixx/en/pag" -F cmd="activate" http://localhost:4502/bin/replicate.json
- Deactivate
curl -u admin:admin -X POST -F path="/content/geometrixx/en/pag" -F cmd="deactivate" http://localhost:4502/bin/replicate.json
- Tree Activation
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
OSGi Bundle Management Commands:
- Build a Bundle
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
curl -u admin:admin http://localhost:4502/system/console/bundles/com.day.sample -Faction=start
- Stop a Bundle
curl -u admin:admin http://localhost:4502/system/console/bundles/com.day.sample -Faction=stop
- Install a Bundle from File system
curl -u admin:admin -F action=install -F bundlestartlevel=20 -F bundlefile=@”<path of samplejar.jar>” http://localhost:4502/system/console/bundles
Page Management Commands:
- Lock a Page
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
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/Move a Page
curl -u admin:admin -F:operation=copy -F:dest=/content/geometrixx/en/products/contacts http://localhost:4502/content/geometrixx/en/toolbar/contacts
JCR Query API Commands:
- Find an Asset from the JCR
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"
Alternatively, you may use Query Debugger to initiate any query you want and copy the “JSON QueryBuilder Link” given there to initiate the same in cURL.
Backup Commands:
- Initiate a Backup to a Target folder
curl -u admin:admin -X POST http://localhost:4502/system/console/jmx/com.adobe.granite%3Atype%3DRepository/op/startBackup/java.lang.String?target=C:\sample\backupTest.zip
- Stop a running Backup
curl -u admin:admin -X POST http://localhost:4502/libs/granite/backup/content/admin/backups.cancel.html
Alternatively , you may use AEM Backup Console for initiating a backup for your AEM instance.
How to use cURL for any functionality in AEM:
As you all might be knowing that AEM is completely based on REST , so you can easily trace any POST/GET call and write a cURL for that call. Its quite simple and handy to do so with the following steps:
- As an example , I have picked Backup for AEM instance. Open to the URL in Firefox.
- Open the Firebug console and go to the Network Tab.
- Fill the form for initiating the Backup as shown below
- While clicking on Start keep a watch at the POST call from the Firebug Console>Network.
- In every functionality you will see a call to server: either a POST or GET. Here you will find a POST call to the
- URL: http://localhost:4502/libs/granite/backup/content/admin/backups/
- Parameters: _charset_=utf-8&force=false&installDir=C%3A%5CAEM+Dev%5CAEM&target=C%3A%5Csample%5CBackup&delay=1000
- After observing these values you can write your cURL command as:
curl -d "_charset_=utf-8&force=false&installDir=C%3A%5CAEM+Dev%5CAEM&target=C%3A%5Csample%5CBackup&delay=10" -u admin:admin -X POST http://localhost:4502/libs/granite/backup/content/admin/backups/
This way you will be able to convert any of the AEM functionality in cURL. You can try exploring this from the System Console while modifying any configurations.
I hope these commands will help you understand and use cURL in a better way. Do let me know if there are any problems you are facing with cURL , I will try to help you guys.
Go Explore cURL !!
Pingback: Automate your cURL Completely – CQ5 AEM Tricks of Trade
Hi Hashim,
Thanks for the info…very helpful. I was looking for curl command to create version of a page.
Can you please post it here. Thanks in advance.
Shams.
LikeLike
Hi,
You can find out the curl for any of the functionaliity from the browser console call. Its very simple. Just perform the event which you want to do and make a similar call using curl. e.g. –
curl -u admin:admin -X POST -F cmd=”createVersion” -F path=”/content/geometrixx/en/toolbar/contacts” -F “_charset_”=”utf-8” http://localhost:4502/bin/wcmcommand
Hope it helps
Regards
Hashim
LikeLike
Hi Hashim,
Can we create a simple tool from which on click of any button we can run these commands on the background. Can you please let me know how to start off on this.
Thanks,
Tushar
LikeLike
Yes sure you can do so. OnClick of a button call a servlet in which you write some java code to execute the command you need.
http://stackoverflow.com/questions/31964264/covert-curl-to-java-code
Regards
Hashim
LikeLike
Thanks for a great post,
Can you help me in finding list packages which are more than 100 MB in size.
Thanks
Nouman
LikeLike
Hi,
You cant do that with a direct Curl Command. You have to extract data from the URL : /crx/packmgr/list.jsp?_dc=1456988059227&_charset_=utf-8 . Modify this JSON response to check for size parameter.
Regards
Hashim
LikeLike
Thanks I will modify and sort this with sed
LikeLike
Is there a way to simply get information about a user without knowing the path?
LikeLike
Hi Brandon,
Could you please check the link for various User management related cURL commands :http://www.wemblog.com/2012/03/how-to-do-user-management-using-post.html
I am not sure if they are still applicable for AEM 6.1 /6.2 .
If you are able to do the required task with a get/post call you can write curl for that. If there is nothing OOTB you can always write a custom servlet and call that custom servlet using the curl command as per need.
Regards
Hashim
LikeLike
Hi Hashim, I am trying to hit a Servlet or Service deployed in OSGi bundle using cURL. I used something like this:
curl -u admin:admin -F cmd=”generateMyPage” -F label=”” -F parentPath=”/content/brand/en/homepage” -F template=”/apps/brand/templates/homepage” -F title=”My_New_Page” http://localhost:4502/bin/wcmcommand
generateMyPage() is a method in my service class which has the code of creating a page. How do I hit this method using a command line cURL ?
Thanks !
LikeLike
Hi Hashim,
I wish to hit a REST servlet (path = /bin/createcontent) or service in AEM using a curl command line. What is the command of doing so ? For service it will be a method to be invoked such as createPages() and for servlet it can be a GET. If I use POST, it says wcmcommand does not support POST.
Cheers,
Som
LikeLike
Hi,
Consider the service call as a normal POST/ GET operation. You can use any of the GET or POST calls defined in the link https://hashimkhan.in/aem-adobecq5-code-templates/curl-aem-commands/ and give appropriate parameters as per your servlet.
If you can post the cURL command here I can help more.
Regards
Hashim
LikeLike
Hi,
GET command would be a normal cURL command. To invoke a particular method of your servlet in POST you need to pass some parameter in your cURL which will invoke that method in your servlet. You might have to change the parameter usage in the servlet.
eg. 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
In the above command, the cmd=”unlockPage” is the parameter whose value decides which method to call in the servlet /bin/wcmcommand
I hope this will help you.
Thanks
Hashim
LikeLike
Hi Hashim,
I was wondering if it’s possible to add a property to every single page returned from the querybuilder that matches a particular case? For example, I want to add a property to every page that is of sling:resourceType – foundation/components/redirect.
Below is the curl command to get all pages of the desired type in the path. I’ve changed one of the page types to verify this command works correctly.
curl -s -u admin:admin -X GET “http://localhost:4502/bin/querybuilder.json?path=/content/geometrixx/en/company&type=cq:Page&p.hits=selective&p.properties=jcr:content/sling:resourceType&property=jcr:content/sling:resourceType&property.1_value=foundation/components/redirect&p.limit=-1”
LikeLike
Hi Hashim,
is there any command to transmit the data from AEM 5.6 to AEM 6,1 using curl on https servers.
Thanks
LikeLike
Hi Neeraj, There is no direct command for that. But you can always create package via cURL and deploy it via cURL.
LikeLike
What is the CURL command to invoke a workflow by passing the payload parameter?
LikeLike
Hi,
In the blog above I have shared how to build a cURL command for any action in AEM . Please read that . Try something similar to
curl -d “_charset_=utf-8&payloadType=JCR_PATH&:status=browser&payload:/content/geometrixx/pagepath&model=/etc/workflow/models/request_for_activation/jcr:content/model&startComment=Comment&workflowTitle=Title” -u admin:admin -X POST http://localhost:4502/etc/workflow/instances
LikeLike
Hi,
Is there any way to run curl command for multiple payloads at a time?
LikeLike
It depends on what are you trying to do in cURL . If you can do anything using the UI , or if the POST servlet accepts multiple payloads you can do similar thing in cURL too.
LikeLike
Hi Hashim,
I am trying to download an AEM package to my local file system using curl in java. I am using the command as:
ProcessBuilder packageDownloadProcess = new ProcessBuilder(“curl”, “-u”, “admin:admin”, “”, “”, curlDownloadPath, “>”, fileFullPath);
Here curlDownloadPath = http://localhost:4502/etc/packages/cox/Application_LOB_PackageName_20160902153139.zip;
and
fileFullPath = C:\data\Application_LOB_PackageName_20160902153139;
On doing so, I am not able to download the package to my local file system. Please help me out.
Thanks
Nitul
LikeLike
Hi Nitul,
Which AEM version are you using to do this ? Can you try something. Use the package manager and try to download a sample package. Note the parameters in the POST call there. and try to create the cURL command using the parameters .
eg. https://alan-mushi.github.io/asap/2015/08/29/AEM-curl-list.html
If the cURL command worked fine for you above , then you can go ahead and try the same using the code.
LikeLike
Hi Hashim, thanks a lot for the commands. Do you know how can I add these curl commands in Java program to run using a java application?
LikeLike
Hi, There could be several ways for that : http://stackoverflow.com/questions/18636567/converting-curl-request-to-http-request-java Try to google for more.
LikeLike
Thanks for the great post Hashim!
I was hoping to run a few curl commands from my desktop to localhost using a form and ajax.
Since it’s on my desktop I figured that writing in HTML/JS would suffice. (No need to hide username, password, etc.)
After doing this, I receive “authentication failed”. I think it has to do with CORS but do you know of ways to fix?
$(“form”).on(“submit”, function(e) {
e.preventDefault();
//curl -u admin:admin -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages/samplepackage.zip?cmd=delete
$.ajax({
url: “http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages/test.zip?cmd=delete”,
method: “POST”,
headers: {
“Authorization”: “Basic ” + btoa(“admin:admin”)
},
success: function(data) {
console.log(“success”);
},
error: function() {
console.log(“failed”);
}
});
});
LikeLike
Hi, Can you tell me the Curl command for downloading all Cq 5.6.1 DAM assets from server to local drive?
Thanks,
Sathish
LikeLike
Hi Sathish, Have you explored WebDav for this requirement ?
LikeLike
there is lots more curl examples here https://github.com/paulrohrbeck/aem-links
LikeLike
This is really great Max. Thanks for this :)
LikeLike
Hi Hashim,
Can we use the “change the password query” to change the name of node. Now when I am using the rep command the curl is not able to resolve it.
LikeLike
Hi, May I know what are you trying to achieve ? what is the use case ? If you can explain me the exact problem , i can suggest you an appropriate cURL command.
LikeLike
Hi,
Actually I want to rename the name of the node i.e. par .For that, I have used rep command of curl.
Curl command : curl -u Name:par -F rep:Name=”NEW_NAME” http://localhost:4602/content/geometrixx/en/products/triangle/jcr:contentcurl rep:Name=”para” –user admin:admin http://localhost:4602/content/geometrixx/en/products/triangle/jcr:content
Initially I was trying with sling pipes but from that I was not able to do. But then I tried with this.
There are no. of pages where I want to change the name of “par”(node name). Please let me know how can I achieve this.
LikeLike
Sorry my bad..my curl command is wrong with respect to change the node name.
LikeLike
Hi Hashim,
Can you help me out in above challenge ?
LikeLike
Can you please help with curl for recompiling all jsp function
LikeLike
Hi,
Try to create cURL from the browser console and Chrome. Goto /system/console/slingjsp and click on Recompile all JSPs and then monitor it in Network Tab of Chrome Developer Tool. There is an option to Copy cURL from there. Screenshot- https://ibb.co/dezZVa
LikeLike
Hi Hashim,
Wonderful article about cURL
I wanted to stop the running CQ instance by sending ctrl-C signal from Jenkins. How can I do this?
Thanks
Arvind
LikeLike
Hi Arvind, You can write a shell script in your AEM instance and then create a Jenkins Job to execute that shell script. http://stackoverflow.com/questions/21276351/how-can-i-execute-shell-script-in-jenkins
LikeLike
Hi Hashim,
I need to take package of paths and its concepts (from cq:tags). How is it possible to include the paths from cq:tags or list those paths using curl command?
LikeLike
Hi, You can create a cURL command by adding multiple filters to create a package https://gist.github.com/nateyolles/dd4ebe0a6b83c369029b And its upto your code how you want to fetch thats list of filters– either by cq:Tags properties or any other property.
LikeLiked by 1 person
Hi Hashim,
I would like to modify the jcr:mixinTypes for these values cq:LiveRelationship, cq:LiveSyncCancelled, and cq:LiveSyncCancelled
Could you please show me how to do that with CURL?
Thanks
LikeLike
Hi Vyong,
Is there an OOTB servlet to make this change ? Or is there a custom servlet which does that ? You can probably call that POST servlet / html call via cURL to perform this action.
LikeLike
Hi Hashim,
Actually I can use CURL to modify the value for jcr:mixinTypes but it only let me update to 1 value. This property is Name[]. I want to add multiple values to it. The strange thing is I can do that with a different property for example I create a jcr:test with Name[] and add multiple values to it. It just didn’t work with jcr:mixinTypes
LikeLike
Oh. Maybe its the restriction for the service call you are making . What command are you using to do this ?
LikeLike
Hi Hashim,
I was recently having issues with the Tree Activation command. When I ran this command for a file with a special character (I am trying to replicate Spanish and French files) the file name would get encoded and then processed, causing the replication to fail. So, for example, the word “Navegación” gets encoded to “Navegación”. Since there is no file called “Navegación”, the command fails and the file does not get replicated. Do you know how I can disable encoding when I run curl commands?
LikeLike
You might have to encode and decode the properties to use it. This happens sometimes.
LikeLike
Hi Hashim, thank you for your response! Could you explain what you mean by encoding and decoding the properties? Do you mean altering the actual node properties of the files on the author instance?
LikeLike
You shouldn’t give special characters in filenames. Give it in the title of the page.
LikeLike
Hi Hashim,
Thanks for the post , I need to get the user detail and group associated with it could you please help me here. how can i get this detail using command line
LikeLike
I am not sure what exactly you need, but you can check these scripts + curl commands to fetch that information https://github.com/hashimkhan786/aem-shell-scripts/blob/master/userMigration.sh
LikeLike
Pingback: About curl commands – Kaushik G
Pingback: complete AEM. – Kaushik G
Can i upload multiple packages at same time in my local using CURL command?
LikeLike
Hi,
Yes you can do so. I would prefer to upload packages one by one though. instead of doing all at once as it would be a load to the server.
Create a text file with list of packages.
Place the packages in the same folder or any other folder.
Now write a bash script to execute cURL commands one by one from the list of packages.
LikeLike
Hello Hashim, thanks for putting up this write up and keeping it a live thread. Is there any way I can retrieve a few properties from a OSGi config.
For example, curl -s -u admin:admin -dpropertylist=cq.searchpromote.configuration.server.uri http://localhost:4502/system/console/configMgr/com.day.cq.searchpromote.impl.SearchPromoteServiceImpl just to retreive the property I want alone and not the complete JSON
LikeLike
Hi Nirmal , You should be able to parse the JSON which you get from the existing servlet. As your curl command uses an existing servlet, unless you write one of your own to process that JSON its not possible.
Alternatively you can use jq to fetch the property value . eg :
echo $(curl -u admin:admin http://localhost:4502/system/console/configMgr/com.day.cq.rewriter.linkchecker.impl.LinkCheckerTransformerFactory?post=true) | jq .pid
LikeLike
Hi Hashim,
Is there any way to break inheritance on component level using curl command?
LikeLike
Hi, Yes sure, Read this to check Console to find out the curl command.
there should be POST call when you click Cancel Inheritance from the dialog. You can recreate that POST with proper FORM data for that particular component node
eg – on this page http://localhost:4502/editor.html/content/geometrixx/en/toolbar.html
there is a POST call –
Request URL: http://localhost:4502/content/geometrixx/en/toolbar/_jcr_content/rightpar
Request Method: POST
with form data:
_charset_: utf-8
./sling:resourceType: foundation/components/iparsys
./jcr:lastModified:
./jcr:lastModifiedBy:
./inheritance: cancel
./inheritance@Delete:
./inheritance@Delete: true
./inheritance@TypeHint: String
./iparsys_fake_par/inheritance@Delete:
./iparsys_fake_par/inheritance@Delete: true
./iparsys_fake_par/inheritance@TypeHint: String
./iparsys_fake_par/sling:resourceType: foundation/components/iparsys/par
LikeLike
Hi Hashim,
I want to delete jar files under /apps/project/install/ using curl which will be used in a jenkins job. Is there a way to do it because the jar file name will change after every execution.
LikeLike
Hi Hashim,
Interesting stuff out here. Kudos!
I am stuck while using cURL to rename multiple assets in DAM. I have made a cURL command that renames a single file (by capturing POST through Developer tools in Chrome).
But, I need to use that command to rename around 1000s of files after they’re uploaded in DAM. Since, multiple renaming is not possible in TouchUI, we have to provide an automated solution to rename a large number of assets that’d otherwise be huge manual effort for the client.
I was hoping you could suggest something like creating a batch to be used in curl or something. Here is the curl command to rename one asset in DAM-
curl -u admin:admin ‘http://devfm1aemadts11.amr.c**p.i***l.com:4502/bin/wcmcommand’ –data ‘cmd=movePage&integrity=true&_charset_=utf-8&%3Astatus=browser&destParentPath=%2Fcontent%2Fdam%2Fdita-sandbox%2Fsample-2&destName=TESTDITASUCCESS.gif&srcPath=%2Fcontent%2Fdam%2Fdita-sandbox%2Fsample-2%2FTESTDITA.gif’ –compressed
Thanks!
LikeLike