Showing posts with label CURL Commands. Show all posts
Showing posts with label CURL Commands. Show all posts

January 4, 2021
Estimated Post Reading Time ~

CQ5 curl commands

Note 1: The following CQ curl commands assume an admin:admin username and password.
Note 2: For Windows/Powershell users: use two "" when doing a -F cURL command.
Example: -F"":operation=delete""
Note 3: Quotes around the name of the package (or name of the zip file, or jar) should be included.

Uninstall a bundle (use http://localhost:4505/system/console/bundles to access the Apache Felix web console)
curl -u admin:admin -daction=uninstall http://localhost:4505/system/console/bundles/"name of bundle"

Install a bundle
curl -u admin:admin -F action=install -F bundlestartlevel=20 -F
bundlefile=@"name of jar.jar" http://localhost:4505/system/console/bundles

Build a bundle
curl -u admin:admin -F bundleHome=/apps/centrica/bundles/name of bundle -F
descriptor=/apps/centrica/bundles/com.centrica.cq.wcm.core-bundle/name_of_bundle.bnd
http://localhost:4505/libs/crxde/build

Stop a bundle
curl -u admin:admin http://localhost:4505/system/console/bundles/org.apache.sling.scripting.jsp
-F action=stop

Start a bundle
curl -u admin:admin http://localhost:4505/system/console/bundles/org.apache.sling.scripting.jsp
-F action=start

Delete a node (hierarchy) - (this will delete any directory / node / site)
curl -X DELETE http://localhost:4505/path/to/node/jcr:content/nodeName -u admin:admin

Upload a package AND install
curl -u admin:admin -F file=@"name of zip file" -F name="name of package"
-F force=true -F install=true http://localhost:4505/crx/packmgr/service.jsp

Upload a package DO NOT install
curl -u admin:admin -F file=@"name of zip file" -F name="name of package"
-F force=true -F install=false http://localhost:4505/crx/packmgr/service.jsp

Rebuild an existing package in CQ

curl -u admin:admin -X POST http://localhost:4505:/crx/packmgr/service/.json/etc/packages/name_of_package.zip?cmd=build

Download (the package)
curl -u admin:admin http://localhost:4505/etc/packages/export/name_of_package.zip > name of local package file

Upload a new package
curl -u admin:admin -F package=@"name_of_package.zip" http://localhost:4505/crx/packmgr/service/.json/?cmd=upload

Install an existing package
curl -u admin:admin -X POST http://localhost:4505/crx/packmgr/service/.json/etc/packages/export/name of package?cmd=install

Activate
curl -u admin:admin -X POST -F path="/content/path/to/page" -F cmd="activate" http://localhost:4502/bin/replicate.json

Deactivate
curl -u admin:admin -X POST -F path="/content/path/to/page" -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 http://localhost:4502/etc/replication/treeactivation.html

Lock page
curl -u admin:admin -X POST -F cmd="lockPage" -F path="/content/path/to/page" -F "_charset_"="utf-8" http://localhost:4502/bin/wcmcommand

Unlock page
curl -u admin:admin -X POST -F cmd="unlockPage" -F path="/content/path/to/page" -F "_charset_"="utf-8" http://localhost:4502/bin/wcmcommand

Copy page
curl -u admin:admin -F cmd=copyPage -F destParentPath=/path/to/destination/parent -F srcPath=/path/to/source/locaiton http://localhost:4502/bin/wcmcommand

Further Resources:
http://cq-ops.tumblr.com/post/19017053665/useful-curl-commands
http://balawcm.wordpress.com/2013/02/13/curl-it-out-adobe-cq5-curl-commands-and-usage/



By aem4beginner

How to manage bundle using curl command

Get bundle Symbolic Name:
(You can use jsawk tool to parse this data as well https://github.com/micha/jsawk)

curl -u admin:admin http://localhost:4502/system/console/bundles</bundlenumber>.json

Start
curl -u admin:admin -F action=start http://localhost:4502/system/console/bundles/$bundle symbolic name

Stop
curl -u admin:admin -F action=stop http://localhost:4502/system/console/bundles/$bundle symbolic name

Update
curl -u admin:admin -F action=update http://localhost:4502/system/console/bundles/$bundle symbolic name

Refresh
curl -u admin:admin -F action=refresh http://localhost:4502/system/console/bundles/$bundle symbolic name

Unistall
curl -u admin:admin -F action=uninstall http://localhost:4502/system/console/bundles/$bundle symbolic name
Or
curl -XDELETE -u user:pass http://.../apps/${app}/install/${bundle-file-name}

Install
curl -X POST -v -F action=install -F bundlestart=start -F bundlestartlevel=20 -F bundlefile=/path/to/jar/file.jar http://admin:admin@localhost:4502/system/console/bundles
OR
curl -u admin:admin -F action=install -F bundlestartlevel=20 -F bundlefile=@"/path/of/jar" http://localhost:9002/system/console/bundles


Here is some example with jswak (Here is how you can install jswak on MAC)
http://www.macports.org/install.php
http://johnattebury.com/blog/2011/06/spidermonkey-jsawk-resty-on-snow-leopard

How to check if a CQ bundle is Active
curl -u admin:admin http://localhost:4502/system/console/bundles/<bundle number or symbolic name>.json | jsawk -n 'if(this.data[0].state=="Active")' | echo "Bundle is Active"

How to check if All bundles are active
curl -u admin:admin http://localhost:4502/system/console/bundles/<bundle number or symbolic name>.json | jsawk -n 'if(this.s[3] + this.s[4] > 0)' | echo "There is some problem not all bundle is active"

Find all Bundle having some problems
curl -u admin:admin http://localhost:4502/system/console/bundles.json | jsawk -n 'for(var i=0;i<this.data.length;i++) {if(this.data[i].state!="Active" && this.data[i].state!="Fragment") out("Bundle " + this.data[i].symbolicName+" is "+ this.data[i].state)}'


By aem4beginner

Using cURL with AEM

Administrators often need to automate or simplify common tasks within any system. In AEM for example, managing users, installing packages, and managing OSGi bundles are tasks that must be commonly done.

Because of the RESTful nature of the Sling framework upon which AEM is built, most tasks can be reduced to a URL call. cURL can be used to execute such URL calls and can be a useful tool for AEM administrators.

What is cURL
cURL is an open-source command-line tool used to perform URL manipulations. It supports a wide range of internet protocols including HTTP, HTTPS, FTP, FTPS, SCP, SFTP, TFTP, LDAP, DAP, DICT, TELNET, FILE, IMAP, POP3, SMTP, and RTSP.

cURL is a well-established and widely-used tool for getting or sending data using the URL syntax and was originally released in 1997. The name cURL originally meant "see URL."

Because of the RESTful nature of the Sling framework upon which AEM is built, most tasks can be reduced to a URL call, which can be executed with cURL. Content manipulation tasks such as activating pages, and starting workflows as well as operational tasks such as package management and managing users can be automated using cURL. In addition, you can create your own cURL commands for most tasks in AEM.

Note:
Any AEM command executed through cURL has to be authorized just as any user to AEM. All ACLs and access rights are respected when using cURL to execute an AEM command.

Downloading cURL
cURL is a standard part of macOS and some Linux distros. However, it is available for almost every operating system. The latest downloads can be found at https://curl.haxx.se/download.html.

cURL's source repository can be found on GitHub as well.

Building a cURL-Ready AEM Command
cURL commands can be built for most operations in AEM such as triggering workflows, checking OSGi configurations, triggering JMX commands, creating replication agents, and much more.

To find the exact command you need for your particular operation, you need to use the developer tools in your browser to capture the POST call to the server when you execute the AEM command.

The following steps describe how to do this using the creation of a new page within the Chrome browser as an example.

Prepare the action you wish to invoke within AEM. In this case, we have proceeded to the end of the Create Page wizard, but have not yet clicked Create.

Start the developer tools and select the Network tab. Click the Preserve log option before clearing the console.



Click Create in the Create Page wizard to actually create the workflow.

Right-click on the resulting POST action and select Copy -> Copy as cURL.

Copy the cURL command to a text editor and remove all headers from the command, which start with -H (highlighted in blue in the image below) and add the proper authentication parameter such as -u admin:admin.

Execute the cURL command via the command line and view the response.
Common Operational AEM cURL Commands

Here is a list of AEM cURL commands for common administrative and operational tasks.

Note:
The following examples assume that AEM is running on localhost on port 4502 and uses the user admin with password admin. Additional command placeholders are set in angle brackets.

Package Management
CREATE A PACKAGE

curl -u admin:admin -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/mycontent.zip?cmd=create -d packageName=<name> -d groupName=<name>

PREVIEW A PACKAGE
curl -u admin:admin -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/mycontent.zip?cmd=preview

LIST PACKAGE CONTENT
curl -u admin:admin -X POST http://localhost:4502/crx/packmgr/service/console.html/etc/packages/mycontent.zip?cmd=contents

BUILD A PACKAGE
curl -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/mycontent.zip?cmd=build

REWRAP A PACKAGE
curl -u admin:admin -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/mycontent.zip?cmd=rewrap

RENAME A PACKAGE
curl -u admin:admin -X POST -Fname=<New Name> http://localhost:4502/etc/packages/<Group Name>/<Package Name>.zip/jcr:content/vlt:definition

UPLOAD A PACKAGE
curl -u admin:admin -F cmd=upload -F force=true -F package=@test.zip http://localhost:4502/crx/packmgr/service/.json

INSTALL A PACKAGE
curl -u admin:admin -F cmd=install http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages/test.zip

UNINSTALL A PACKAGE
curl -u admin:admin -F cmd=uninstall http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages/test.zip

DELETE A PACKAGE
curl -u admin:admin -F cmd=delete http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages/test.zip

DOWNLOAD A PACKAGE
curl -u admin:admin http://localhost:4502/etc/packages/my_packages/test.zip

User Management
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 A 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 MEMBERSHIP
curl -u admin:admin -Fmembership=contributor -Fmembership=testgroup http://localhost:4502/home/users/t/testuser.rw.html

DELETE A USER
curl -u admin:admin -FdeleteAuthorizable= http://localhost:4502/home/users/t/testuser


DELETE A GROUP
curl -u admin:admin -FdeleteAuthorizable= http://localhost:4502/home/groups/t/testGroup

Backup
See Backup and Restore for details.

OSGi
STARTING A BUNDLE
curl -u admin:admin -Faction=start http://localhost:4502/system/console/bundles/<bundle-name>

STOPPING A BUNDLE
curl -u admin:admin -Faction=stop http://localhost:4502/system/console/bundles/<bundle-name>

Dispatcher
INVALIDATE THE CACHE
curl -H "CQ-Action: Activate" -H "CQ-Handle: /content/test-site/" -H "CQ-Path: /content/test-site/" -H "Content-Length: 0" -H "Content-Type: application/octet-stream" http://localhost:4502/dispatcher/invalidate.cache

EVICT THE CACHE
curl -H "CQ-Action: Deactivate" -H "CQ-Handle: /content/test-site/" -H "CQ-Path: /content/test-site/" -H "Content-Length: 0" -H "Content-Type: application/octet-stream" http://localhost:4502/dispatcher/invalidate.cache

Replication Agent
CHECK THE STATUS OF AN AGENT

curl -u admin:admin "http://localhost:4502/etc/replication/agents.author/publish/jcr:conten t.queue.json?agent=publish"
http://localhost:4502/etc/replication/agents.author/publish/jcr:content.queue.js on?agent=publish

DELETE AN AGENT
curl -X DELETE http://localhost:4502/etc/replication/agents.author/replication99 -u admin:admin

CREATE AN AGENT
curl -u admin:admin -F "jcr:primaryType=cq:Page" -F "jcr:content/jcr:title=new-replication" -F "jcr:content/sling:resourceType=/libs/cq/replication/components/agent" -F "jcr:content/template=/libs/cq/replication/templates/agent" -F "jcr:content/transportUri=http://localhost:4503/bin/receive?sling:authRequestLogin=1" -F "jcr:content/transportUser=admin" -F "jcr:content/transportPassword={DES}8aadb625ced91ac483390ebc10640cdf"http://localhost:4502/etc/replication/agents.author/replication99

PAUSE AN AGENT
curl -u admin:admin -F "cmd=pause" -F "name=publish" http://localhost:4502/etc/replication/agents.author/publish/jcr:content.queue.js on

CLEAR AN AGENT QUEUE
curl -u admin:admin -F "cmd=clear" -F "name=publish" http://localhost:4502/etc/replication/agents.author/publish/jcr:content.queue.js on

Communities
ASSIGN AND REVOKE BADGES
See Communities Scoring and Badges for details.
See Scoring and Badges Essentials for details.

MSRP REINDEXING
See MSRP - MongoDB Storage Resource Provider for details.

Security
ENABLING AND DISABLING CRX DE LITE
See Enabling CRXDE Lite in AEM for details.

Data Store Garbage Collection
See Data Store Garbage Collection for details.

Analytics and Target Integration
See Opting Into Adobe Analytics and Adobe Target for details.

Single Sign-On
SEND TEST HEADER
See Single Sign-On for details.

Common Content Manipulation AEM cURL Commands

Here is a list of AEM cURL commands for content manipulation.
Note:
The following examples assume that AEM is running on localhost on port 4502 and uses the user admin with password admin. Additional command placeholders are set in angle brackets.

Page Management
PAGE ACTIVATION
curl -u admin:admin -X POST -F path="/content/path/to/page" -F cmd="activate" http://localhost:4502/bin/replicate.json

PAGE DEACTIVATION
curl -u admin:admin -X POST -F path="/content/path/to/page" -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 http://localhost:4502/etc/replication/treeactivation.html

LOCK PAGE
curl -u admin:admin -X POST -F cmd="lockPage" -F path="/content/path/to/page" -F "_charset_"="utf-8" http://localhost:4502/bin/wcmcommand

UNLOCK PAGE
curl -u admin:admin -X POST -F cmd="unlockPage" -F path="/content/path/to/page" -F "_charset_"="utf-8" http://localhost:4502/bin/wcmcommand

COPY PAGE
curl -u admin:admin -F cmd=copyPage -F destParentPath=/path/to/destination/parent -F srcPath=/path/to/source/location http://localhost:4502/bin/wcmcommand

Workflows
See Interacting with Workflows Programmatically for details.

Sling Content
CREATE A FOLDER
curl -u admin:admin -F jcr:primaryType=sling:Folder http://localhost:4502/etc/test

DELETE A NODE
curl -u admin:admin -F :operation=delete http://localhost:4502/etc/test/test.properties

MOVE A NODE
curl -u admin:admin -F":operation=move" -F":applyTo=/sourceurl" -F":dest=/target/parenturl/" http://lcoalhost:4502/content

COPY A NODE
curl -u admin:admin -F":operation=copy" -F":applyTo=/sourceurl" -F":dest=/target/parenturl/" http://lcoalhost:4502/content

UPLOAD FILES USING SLING POSTSERVLET
curl -u admin:admin -F"*=@test.properties" http://localhost:4502/etc/test

UPLOAD FILES USING SLING POSTSERVLET AND SPECIFYING NODE NAME
curl -u admin:admin -F"test2.properties=@test.properties" http://localhost:4502/etc/test

UPLOAD FILES SPECIFYING A CONTENT TYPE
curl -u admin:admin -F "*=@test.properties;type=text/plain" http://localhost:4502/etc/test



By aem4beginner

AEM cURL Commands

Following are few useful cURL commands, categorized as below;
  1. User Management Commands
  2. Package Management Commands
  3. OSGi Bundle Management Commands
  4. JCR Query Builder Commands
  5. Backup Commands
  6. JCR Node Management Commands
  7. Replication Commands
  8. Page Management Commands
  9. Other useful commands
USER MANAGEMENT COMMANDS:
[code lang=’bash’ title=’Create a new User’]
$ curl -u admin:admin -FcreateUser= -FauthorizableId=skydevops-Frep:password=skydevops http://localhost:4502/libs/granite/security/post/authorizables
[/code]

[code lang=’bash’ title=’Create a new user under specified folder’]
$ curl -u admin:admin -FcreateUser= -FauthorizableId=testuser -Frep:password=testuser -FintermediatePath=”/home/users/test/” http://localhost:4502/libs/granite/security/post/authorizables
[/code]

[code lang=’bash’ title=’Create a new Group’]
$ curl -u admin:admin -FcreateGroup=testgroup -FauthorizableId=testGroup http://localhost:4502/libs/granite/security/post/authorizables
[/code]

[code lang=’bash’ title=’Add a Property to an existing User’]
$ curl -u admin:admin -Fprofile/age=30 http://localhost:4502/home/users/a/skydevops.rw.html
[/code]

[code lang=’bash’ title=’Create a User with a profile’]
$ curl -u admin:admin -FcreateUser=testuser -FauthorizableId=skydevopsa -Frep:password=skydevops -Fprofile/gender=male http://localhost:4502/libs/granite/security/post/authorizables
[/code]

[code lang=’bash’ title=’Create a new User as a member of a Group’]
$ curl -u admin:admin -FcreateUser=testuser -FauthorizableId=testuser -Frep:password=abcd123 -Fmembership=contributor http://localhost:4502/libs/granite/security/post/authorizables
[/code]

[code lang=’bash’ title=’Add User to a Group’]
$ curl -u admin:admin -FaddMembers=testuser http://localhost:4502/home/groups/t/testGroup.rw.html
[/code]

[code lang=’bash’ title=’Remove a User from a Group’]
$ curl -u admin:admin -FremoveMembers=testuser http://localhost:4502/home/groups/t/testGroup.rw.html
[/code]

[code lang=’bash’ title=’Set a User’s Group Memberships’]
$ curl -u admin:admin -Fmembership=contributor -Fmembership=testgroup http://localhost:4502/home/users/t/testuser.rw.html
[/code]

[code lang=’bash’ title=’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
[/code]

[code lang=’bash’ title=’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/shashi@skydevops.in
[/code]

PACKAGE MANAGEMENT COMMANDS:
[code lang=’bash’ title=’list of all the packages’]
$ curl -u admin:admin http://localhost:4502/crx/packmgr/service.jsp?cmd=ls
[/code]

[code lang=’bash’ title=’Build or Rebuild an existing package’]
$ curl -u admin:admin -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages/samplepackage.zip?cmd=build
[/code]

[code lang=’bash’ title=’Delete a package’]
$ curl -u admin:admin -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages/samplepackage.zip?cmd=delete
[/code]

[code lang=’bash’ title=’Install a package’]
$ curl -u admin:admin -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages/samplepackage.zip?cmd=install
[/code]

[code lang=’bash’ title=’Uninstall a package’]
$ curl -u admin:admin -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages/samplepackage.zip?cmd=uninstall
[/code]

[code lang=’bash’ title=’Download a package into local filesystem’]
$ curl -u admin:admin http://localhost:4502/etc/packages/my_packages/samplepackage.zip >
[/code]

[code lang=’bash’ title=’Upload but don’t install a 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
[/code]

[code lang=’bash’ title=’Upload and Install a 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
[/code]

OSGI BUNDLE MANAGEMENT:
[code lang=’bash’ title=’Build a Bundle using’]
$ 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
[/code]

[code lang=’bash’ title=’Start a Bundle using’]
$ curl -u admin:admin http://localhost:4502/system/console/bundles/com.day.sample -Faction=start
[/code]

[code lang=’bash’ title=’Stop a Bundle using’]
$ curl -u admin:admin http://localhost:4502/system/console/bundles/com.day.sample -Faction=stop
[/code]

[code lang=’bash’ title=’Install a Bundle from File system using’]
$ curl -u admin:admin -F action=install -F bundlestartlevel=20 -F bundlefile=@”” http://localhost:4502/system/console/bundles
[/code]

JCR QUERY BUILDER:
[code lang=’bash’ title=’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&#8221;
[/code]

BACKUP COMMANDS:
[code lang=’bash’ title=’Initiate backup’]
$ 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
[/code]

[code lang=’bash’ title=’Stop a running Backup’]
$ curl -u admin:admin -X POST http://localhost:4502/libs/granite/backup/content/admin/backups.cancel.html
[/code]

JCR NODE MANAGEMENT COMMANDS:
[code lang=’bash’ title=’Delete a Node’]
$ curl -X DELETE http://localhost:4502/content/geometrixx/en/products/jcr:content/par/flash -u admin:admin
[/code]

[code lang=’bash’ title=’Create or Add a Node’]
$ curl –data jcr:primaryType=nt:unstructured –user admin:admin http://localhost:4502/content/geometrixx/en/toolbar/testNode
[/code]

REPLICATION COMMANDS:
[code lang=’bash’ title=’Activate Page’]
$ curl -u admin:admin -X POST -F path=”/content/geometrixx/en/pag” -F cmd=”activate” http://localhost:4502/bin/replicate.json
[/code]

[code lang=’bash’ title=’Deactivate Page’]
$ curl -u admin:admin -X POST -F path=”/content/geometrixx/en/pag” -F cmd=”deactivate” http://localhost:4502/bin/replicate.json
[/code]

[code lang=’bash’ title=’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
[/code]

PAGE MANAGEMENT COMMANDS:
[code lang=’bash’ title=’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
[/code]

[code lang=’bash’ title=’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
[/code]

[code lang=’bash’ title=’Copy or 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
[/code]

OTHER USEFUL COMMANDS:

[code lang=’bash’ title=’Datastore Garbage Collection’]
$ curl -u admin:admin -X POST http://localhost:4502/system/console/jmx/com.adobe.granite:type=Repository/op/runDataStoreGarbageCollection/java.lang.Boolean
[/code]

[code lang=’bash’ title=’Tar Optimization’]
$ curl -u admin:admin -X POST http://localhost:4502/system/console/jmx/com.adobe.granite:type=Repository/op/startTarOptimization/
[/code]

[code lang=’bash’ title=’Flush Dispatcher Cache’]
$ 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
[/code]



By aem4beginner

January 2, 2021
Estimated Post Reading Time ~

Managing AEM Packages from the CLI

After the umpteenth time of having to check this excellent reference of the cURL commands for AEM to upload a package, I finally thought “this is silly”. So, I created a small script to make it easier to manage packages via the command line.

The AEM Package Manager is just that, a small script to help you manage scripts from the command line. This script is useful for many occasions, such as:
  • Exchanging content packages
  • Installing a dependency package outside the build
  • Or when you just want something quicker and easier than using the AEM web UI to upload a package
Using the script is as simple as:
  • Downloading the script from GitHub
  • Making it executable
  • Putting it in your system path
Once you have the script installed, you can use it as shown in the following examples:

List Packages
Lists all of the packages in the my_packages group.
danklco@EDS-Klco-MAC ~> aem-pkmgr list -g my_packages AVAILABLE PACKAGES ForLocalContent_062216 Description: Version: Group: my_packages Path: /etc/packages/my_packages/ForLocalContent_062216.zip TagsForLocal_071416 Description: Version: Group: my_packages Path: /etc/packages/my_packages/TagsForLocal_071416.zip tes Description: Version: tes Group: my_packages Path: /etc/packages/my_packages/tes-tes.zip

Download Package
Downloads the package /etc/packages/my_packages/TagsForLocal_071416.zip.
danklco@EDS-Klco-MAC ~> aem-pkmgr download -pk /etc/packages/my_packages/TagsForLocal_071416.zip DOWNLOADING PACKAGE /etc/packages/my_packages/TagsForLocal_071416.zip... % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 41.3M 100 41.3M 0 0 140M 0 --:--:-- --:--:-- --:--:-- 140M

Upload / Install Package
Uploads and installs the package TagsForLocal_071416.zip.
danklco@EDS-Klco-MAC ~> aem-pkmgr upload-install -pk TagsForLocal_071416.zip UPLOADING PACKAGE TagsForLocal_071416.zip... 
<crx version="1.2.2" user="admin" workspace="crx.default"> 
 <request> 
 <param name="file" value="TagsForLocal_071416.zip"/> 
 <param name="force" value="true"/> 
 <param name="install" value="true"/> 
 </request> <response> 
 <data> 
 <package> 
 <group>my_packages</group> 
 <name>TagsForLocal_071416</name> 
 <version></version> <downloadName>TagsForLocal_071416.zip</downloadName> <size>43330621</size> 
 <created>Wed, 20 Jul 2016 12:41:05 -0500</created> <createdBy>admin</createdBy> 
 <lastModified>Wed, 20 Jul 2016 12:40:26 -0500</lastModified> <lastModifiedBy>admin</lastModifiedBy> 
 <lastUnpacked>Wed, 20 Jul 2016 15:33:04 -0500</lastUnpacked> <lastUnpackedBy>admin</lastUnpackedBy> 
 </package> 
 <log> 
Installing content... 
Collecting import information... 
Installing node types... 
- rep -&gt; internal 
- mix -&gt; http://www.jcp.org/jcr/mix/1.0 
- nt -&gt; http://www.jcp.org/jcr/nt/1.0 
- sling -&gt; http://sling.apache.org/jcr/sling/1.0 
- cq -&gt; http://www.day.com/jcr/cq/1.0 
- sling:Folder 
- sling:Redirect 
- sling:Resource 
- cq:ReplicationStatus
 - cq:Tag 
- rep:RepoAccessControllable 
Installing privileges...
Importing content... - / 
- /etc 
- /etc/tags
 [... trim ...] 
saving approx 0 nodes...
 Package imported. 
Package installed in 55497ms. 
 </log> 
 </data> 
 <status code="200">ok</status> 
 </response> 
</crx>

Hopefully, this helps you manage AEM packages via the command line. You can find more detailed usage documentation on the GitHub site.


By aem4beginner

December 28, 2020
Estimated Post Reading Time ~

How to Generate Curl Command to Update OSGI Configurations

Micro-Frontend, written in ReactJS 16.14.0.

This tool helps generate a curl command used for updating OSGI configurations directly from the terminal, bash, or Window’s console. It’s a good idea to read the micro-front-end tool’s notes, described at the bottom of the page, before using the tool.
AEM Curl Generator for Updating OSGI Configs

This tool is free to use. The generated curl command and user inputs are never stored in any way from sourcedcode.com.reset fields


Generated Curl Command:
curl -u admin:admin 'http://localhost:4502/system/console/configMgr/com.day.cq.mailer.DefaultMailService' --data-raw 'apply=true&action=ajaxConfigManager&%24location=&smtp.host=smtp.gmail.com&propertylist=smtp.host'

OSGI Console Url:
http://localhost:4502/system/console/configMgr/com.day.cq.mailer.DefaultMailService

Notes:
  • This tool is free to use. The generated curl command and user inputs are never stored in any way from sourcedcode.com.
  • OSGI array configurations can be achieved by adding another keypair entry with the same key name as the previous key pair.
  • Unfortunately, you cannot update a single configuration key for a given OSGI configuration. All the properties need to be identified. If other OSGI configuration keys are not identified, then the curl command will actually wipe out all the missing configurations.
  • You can share the configurations with your colleagues by clicking on the “Get Above Sharable Configuration Url” button.
  • I created this tool to help my colleagues quickly generate curl commands to update the OSGI configuration to free each other’s time.
Source:


By aem4beginner

December 10, 2020
Estimated Post Reading Time ~

cURL execution from Java program

cURL is a tool to transfer data from or to a server, using one of the supported protocols (DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNETand TFTP). The command is designed to work without user interaction.

With AEM, you can use cURL commands to modify repository, download json, access OSGi information etc.

Snippet to download a json file via cURL:
While majority of the AEM’s content information can be downloaded via HTTP connection, cURL command can be used to download information from AEM’s OSGi console.

In the shared example, we have used cURL to get information about all the bundles installed in AEM.

package blog.techrevel.api;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

import org.apache.commons.codec.binary.Base64;

public class CurlExecutor {

public static void main(String[] args) {

String stringUrl = "http://localhost:4502/system/console/bundles.json";
URL url;
try {
url = new URL(stringUrl);
URLConnection uc;
uc = url.openConnection();

uc.setRequestProperty("X-Requested-With", "Curl");

String userpass = "admin" + ":" + "admin";
String basicAuth = "Basic " + new String(new Base64().encode(userpass.getBytes()));
uc.setRequestProperty("Authorization", basicAuth);

BufferedReader reader = new BufferedReader(new InputStreamReader(uc.getInputStream()));
StringBuilder builder = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
builder.append(line);
builder.append(System.getProperty("line.separator"));

}
String result = builder.toString();
System.out.println(result);
} catch (IOException e) {
e.printStackTrace();
}
}
}

Snippet to execute a cURL command:
The following snippet contains acURL command that has been converted in a format to be used in Java snippet.

The cURL command used here is meant to lock page “/content/geometrixx/en/toolbar/contacts” :

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

package blog.techrevel.api;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class CurlExecutor2 {

public static void main(String[] args) {

String username = "admin";
String password = "admin";
String url = "http://localhost:4502/bin/wcmcommand";
String path = "/content/geometrixx/en/toolbar/contacts";

//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

//Equivalent command conversion for Java execution
String[] command = { "curl", "-u", username + ":" + password, "-X", "POST", "-F", "cmd=unlockPage", "-F",
"path=" + path, "-F", "_charset_=utf-8", url };

ProcessBuilder process = new ProcessBuilder(command);
Process p;
try {
p = process.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
StringBuilder builder = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
builder.append(line);
builder.append(System.getProperty("line.separator"));
}
String result = builder.toString();
System.out.print(result);

} catch (IOException e) {
System.out.print("error");
e.printStackTrace();
}
}
}

For more samples of cURL commands, please refer to:


By aem4beginner

May 4, 2020
Estimated Post Reading Time ~

How to Delete a Node

One of my favorite things about AEM is how it really leverages the HTTP specification. This really comes in handy when you have a node buried deep in a large tree inside AEM which you want to delete, but the browser times out before CRX DELite can render the expanded folder. In such a case, you can directly delete the node by using the HTTP “DELETE” verb. For example:

curl -u admin:admin -X DELETE http://localhost:4502/path/to/node




By aem4beginner

May 3, 2020
Estimated Post Reading Time ~

Upload and install package via curl

It happened recently where I needed to install a package via curl because of UI issues and connection issues with a server. Here’s a fleshed-out command that will store the output to a file and show a progress bar: 

curl -u username:password -F file=@"./YourPackage.zip" -F name=“Package” -F force=true -F install=true http://localhost:4502/crx/packmgr/service.jsp --progress-bar -o upload.txt

This assumes you are executing this command *in the directory where the package is located*. Otherwise, you need to update the path in the file parameter.


By aem4beginner

April 27, 2020
Estimated Post Reading Time ~

Install Adobe Experience Manager(AEM) package through CURL command

curl -u <<User Name>>:<<Password>> -F file=@"<<Package Path>>" -F name="<<Package Name>>" -F force=true -F install=true http://<<Server Host Name>>:<<Port>>/crx/packmgr/service.jsp

e.g

curl -u admin:admin -F file=@"/appserver/package/package-1.0.1-SNAPSHOT.zip" -F name="package-1.0.1-SNAPSHOT" -F force=true -F install=true http://localhost:4502/crx/packmgr/service.jsp

If the Adobe Experience Manager(AEM) server is behind the proxy then execute the below command to set the proxy server

export http_proxy=http://<<Proxy Server Host Name>>:<<Port>>


By aem4beginner

April 26, 2020
Estimated Post Reading Time ~

Adobe AEM curl commands

Run JCR query builder API:

Find “all” page references for a given image/asset in a jcr path. The below command will return in JSON format:
curl -s -u ${username}:${password} -X GET http://localhost:4502/bin/querybuilder.json?path=/content/my-site&1_property=fileReference&1_property.value=/content/dam/my-site/image.jpg&p.limit=-1*Note: -1 in the p.limit will return all page references else prints only 10.

You can also specify the required number of page references; something like below which will return only 20-page references:
curl -s -u admin:admin “http://localhost:4502/bin/querybuilder.json?path=/var/eventing/jobs/anon&type=slingevent:Job&rangeproperty.property=event.job.retrycount&rangeproperty.lowerBound=1&#8221;

AEM Package Manager Commands:
Uninstall a bundle (use http://localhost:4502/system/console/bundles to access the Apache Felix web console)curl -u admin:admin -daction=uninstall http://localhost:4505/system/console/bundles/”name-of-bundle&#8221;

Upload a package AND installcurl -u admin:admin -F file=@”name of zip file” -F name=”name of package” -F force=true -F install=true http://localhost:4502/crx/packmgr/service.jsp

Upload a package DO NOT installcurl -u admin:admin -F file=@”name of zip file” -F name=”name of package” -F force=true -F install=false http://localhost:4502/crx/packmgr/service.jsp

Rebuild an existing package in CQcurl -u admin:admin -X POST http://localhost:4502:/crx/packmgr/service/.json/etc/packages/name_of_package.zip?cmd=build

Download a package:curl -u admin:admin http://localhost:4502/etc/packages/export/name_of_package.zip > name of local package file

Upload a packagecurl -u admin:admin -F package=@”name_of_package.zip” http://localhost:4502/crx/packmgr/service/.json/?cmd=upload
Install a package
curl -u admin:admin -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/export/name of package?cmd=install

List contents of a package
$ curl -u admin:admin -X POST http://localhost:4502/crx/packmgr/service/console.html/etc/packages/day/cq561/product/cq-content-5.6.1.20130606.zip?cmd=contents

AEM Bundle Manager Commands:
Install a bundlecurl -u admin:admin -F action=install -F bundlestartlevel=20 -F bundlefile=@”name of jar.jar” http://localhost:4502/system/console/bundles

Build a bundlecurl -u admin:admin -F bundleHome=/apps/ projects-A/bundles/name of bundle -F descriptor=/apps/projects-A/bundles/com.centrica.cq.wcm.core-bundle/name_of_bundle.bnd http://localhost:4502/libs/crxde/build

Stop a bundlecurl -u admin:admin http://localhost:4502/system/console/bundles/org.apache.sling.scripting.jsp -Faction=stop

Start a bundlecurl -u admin:admin http://localhost:4502/system/console/bundles/org.apache.sling.scripting.jsp -Faction=start

JCR Node Management:
Delete a node (hierarchy) – (this will delete any directory / node / site)curl -X DELETE http://localhost:4502/path/to/node/jcr:content/nodeName -u admin:admin

Create or add a JCR node:curl -u admin:admin -F”_charset_=utf-8″ -F”:nameHint=node” -F”jcr:primaryType=nt:unstructured” -F”sling:resourceType=project-A/components/abc-definition” -F”nodeReferenceName=ref-name1″ -F”jcr:createdBy=bala” -F”jcr:lastModifiedBy=bala” http://localhost:4502/content/geometrixx/en_GB/products/jcr:content/abc/

Create or add a JCR node along with some properties:curl -u admin:admin -F”_charset_=utf-8″ -F”:nameHint=var” -F”jcr:primaryType=nt:unstructured” -F”key=key1″ -F”value=key1-value” http://localhost:4502/content/geometrixx/en_GB/products/jcr:content/abc/variables/

CQ Replication Commands:
Tree Activationcurl -u admin:admin -F cmd=activate -F ignoredeactivated=true -F onlymodified=true -F path=/content/geometrixx http://localhost:4502/etc/replication/treeactivation.html

User & Group Administration
Get User Info:
curl -u admin:admin -FcreateUser= -FauthorizableId=testuser -Frep:password=abc123 http://localhost:4502/libs/granite/security/post/authorizables

Create Group:
curl -u admin:admin -FcreateGroup=group1 -FauthorizableId=testGroup1 http://localhost:4502/libs/granite/security/post/authorizables

Create user with Profile:
curl -u admin:admin -FcreateUser=testuser -FauthorizableId=testuser -Frep:password=abc123 -Fprofile/gender=male http://localhost:4502/libs/granite/security/post/authorizables

Set a Profile Property on an Existing User:
curl -u admin:admin -Fprofile/age=29 http://localhost:4502/home/users/t/testuser1.rw.html

Create a 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 a 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 an 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

Backup Commands:
Online Backup:curl -u admin:admin -X POST http://localhost:4502/system/console/jmx/com.adobe.granite:type=Repository/op/startBackup/java.lang.String?target=<PATH-TO-BACKUP>/12-feb-2013.zip

Online backup with delay in milli seconds:
curl -u admin:admin -X POST http://localhost:4502/system/console/jmx/com.adobe.granite:type=Repository/a/BackupDelay?value=<TIME-IN-MILISECOND&gt;
curl -u admin:admin –data “delay=TIME-IN-MILISECONDS&force=false&target=01-dec-2012.zip” http://localhost:4502/libs/granite/backup/content/admin/backups/

How to stop a running online backup:
Flush Dispatcher Cache:
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

April 19, 2020
Estimated Post Reading Time ~

Changing the CQ5 (AEM) Admin Password via Curl

Just so I don’t forget – a working curl command for changing the admin password is:

curl -u admin:theOldPassword -Fplain=theNewPassword -Fverify=theNewPassword -Fold=theOldPassword -FPath=/home/users/a/admin http://localhost:4502/crx/explorer/ui/setpassword.jsp


By aem4beginner

Changing User Passwords in AEM 6.1 via cURL

In AEM 6.1, there have been a number of changes make to the structure of users.  In older versions of AEM, users could be found under a directory structure based on thier user name.  For example the user admin, would be found at /home/users/a/admin, in AEM 6.1, this has been changed, likely to support a larger number of users without performance issues.  Unfortunately, the method used to create this path does not seem to be predictable, so the path for an individual user is not stable across different AEM instances.
Users in AEM 6.0
Users in AEM 6.1
Normally, this isn't an issue.  However, if you want to change the password on a user through cURL, this is a big issue as you need to know the path to the user.  Of course, this can be done by looking for the user in CRXDE Lite, however this generally eliminates the automation you're probably trying to accomplish.  Never fear!  Using the query builder, we can get the path to the user and then change the user's password.  This does assume you also have a recent version of ruby and ruby gems installed to parse JSON.
First, we'll call the Query Builder via cURL to get the path to the user:
curl -s -u admin:admin -X GET "http://localhost:4502/bin/querybuilder.json?path=/home/users&1_property=rep:authorizableId&1_property.value={USER_NAME}&p.limit=-1" > user.json
Next, we read the path from the JSON result:
USER_PATH=`ruby -rjson -e 'j = JSON.parse(File.read("user.json")); puts j["hits"][0]["path"]'`
Finally, the USER_PATH variable can be used to set the user's password:
curl -s -u admin:admin -Fplain={NEW_PASSWORD} -Fverify={NEW_PASSWORD}  -Fold={OLD_PASSWORD} -FPath=$USER_PATH http://localhost:4502/crx/explorer/ui/setpassword.jsp
Putting it all together, if I wanted to change the admin user's password I would call:
curl -s -u admin:admin -X GET "http://localhost:4502/bin/querybuilder.json?path=/home/users&1_property=rep:authorizableId&1_property.value=admin&p.limit=-1" > user.json
USER_PATH=`ruby -rjson -e 'j = JSON.parse(File.read("user.json")); puts j["hits"][0]["path"]'`
curl -s -u admin:admin -Fplain=admin1 -Fverify=admin1  -Fold=admin -FPath=$USER_PATH http://localhost:4502/crx/explorer/ui/setpassword.jsp
Hopefully, this helps anyone else stuck trying to script a user's password change!


By aem4beginner

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

April 14, 2020
Estimated Post Reading Time ~

Using curl to install CQ packages

CQ5 has a very good tradition of exposing APIs, which are accessible by simple HTTP (in some cases even RESTful APIs). This allows one to access data and processes from external and is also a good starting point for automation.

Especially the Package Manager API is well documented, so most steps to automate deployment steps really start here. A typical shell script to automate package installation might look like this:

ZIP = directory / to / the / package - 1.0.zip
FILENAME = `basename $ZIP`
CURL = curl - u admin: admin
HOST = http: //localhost:4502/crx/packmgr/service/.json

 $CURL - s - F package = @ZIP - F force = true $HOST ? cmd = upload
if test $ ? -ne 0;
echo“ failed on upload "
fi
$CURL - X POST - s $HOST / etc / packages / mypackages / $FILENAME ? cmd = install
if test $ ? -ne 0;
echo“ failed on install "
fi

As you see, it lacks any kind of sophisticated error handling. Introducing a good error handling is not convenient, as curl doesn’t return the HTTP status as a return code (but just if the request itself has been performed successfully), so you have a parse the complete output to decide if the server-side returned an HTTP 200 or something else. Any non-seasoned shell-script-developer will probably just omit this part and hope for the best …

And even then: When your package installation throws an error during deserialization of a node (maybe you have a typo in one of your hand-crafted .content.xml files), the system still returns an http 200 code. Which of course it shouldn’t.
(The reason for the 200 is, that the code streams the installation progress on each node and that the decision for the status code has to be done before all nodes are imported into the repository. Therefore the need for an internal status, which is one of the last lines of the result. Thanks, Toby for this missing piece!)

And of course, we still lack the checks if embedded bundles are starting up correctly …

So whenever you do such light-weight deployment automation, be aware of the limits of it. Good error handling, especially if the errors are inlined in some output, was never a primary focus of shell scripting, and most of the automation scripts I’ve seen in the wild (and written myself, to be honest) never really cared about it.
But if you want to have it automated, it must be reliable. So you can focus on your other work, and not on checking deployment process logs for obvious and non-obvious errors.

On AEMHub I will talk about the importance of such tools and why developers should care about such operation topics. And I hope that I can present the foundations of a small project aimed at proper CQ deployment automation.



By aem4beginner

April 11, 2020
Estimated Post Reading Time ~

Useful CURL commands in AEM

Note 1: The following CQ curl commands assumes a admin:admin username and password.
Note 2: For Windows/Powershell users: use two "" when doing a -F cURL command.
Example: -F"":operation=delete""
Note 3: Quotes around name of package (or name of zip file, or jar) should be included.

Uninstall a bundle (use http://localhost:4505/system/console/bundles to access the Apache Felix web console)
curl -u admin:admin -daction=uninstall http://localhost:4505/system/console/bundles/"name of bundle"

Install a bundle
curl -u admin:admin -F action=install -F bundlestartlevel=20 -F
bundlefile=@"name of jar.jar" http://localhost:4505/system/console/bundles

Build a bundle
curl -u admin:admin -F bundleHome=/apps/centrica/bundles/name of bundle -F
descriptor=/apps/centrica/bundles/com.centrica.cq.wcm.core-bundle/name_of_bundle.bnd
http://localhost:4505/libs/crxde/build

Stop a bundle
curl -u admin:admin http://localhost:4505/system/console/bundles/org.apache.sling.scripting.jsp
-F action=stop

Start a bundle
curl -u admin:admin http://localhost:4505/system/console/bundles/org.apache.sling.scripting.jsp
-F action=start

Delete a node (hierarchy) - (this will delete any directory / node / site)
curl -X DELETE http://localhost:4505/path/to/node/jcr:content/nodeName -u admin:admin

Upload a package AND install
curl -u admin:admin -F file=@"name of zip file" -F name="name of package"
-F force=true -F install=true http://localhost:4505/crx/packmgr/service.jsp

Upload a package DO NOT install
curl -u admin:admin -F file=@"name of zip file" -F name="name of package"
-F force=true -F install=false http://localhost:4505/crx/packmgr/service.jsp

Rebuild an existing package in CQ
curl -u admin:admin -X POST http://localhost:4505:/crx/packmgr/service/.json/etc/packages/name_of_package.zip?cmd=build

Download (the package)
curl -u admin:admin http://localhost:4505/etc/packages/export/name_of_package.zip > name of local package file

Upload a new package
curl -u admin:admin -F package=@"name_of_package.zip" http://localhost:4505/crx/packmgr/service/.json/?cmd=upload

Install an existing package
curl -u admin:admin -X POST http://localhost:4505/crx/packmgr/service/.json/etc/packages/export/name of package?cmd=install

Activate
curl -u admin:admin -X POST -F path="/content/path/to/page" -F cmd="activate" http://localhost:4502/bin/replicate.json

Deactivate
curl -u admin:admin -X POST -F path="/content/path/to/page" -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 http://localhost:4502/etc/replication/treeactivation.html

Lock page
curl -u admin:admin -X POST -F cmd="lockPage" -F path="/content/path/to/page" -F "_charset_"="utf-8" http://localhost:4502/bin/wcmcommand

Unlock page
curl -u admin:admin -X POST -F cmd="unlockPage" -F path="/content/path/to/page" -F "_charset_"="utf-8" http://localhost:4502/bin/wcmcommand

Copy page
curl -u admin:admin -F cmd=copyPage -F destParentPath=/path/to/destination/parent -F srcPath=/path/to/source/locaiton http://localhost:4502/bin/wcmcommand

Further Resources:
https://cq-ops.tumblr.com/post/19017053665/useful-curl-commands
https://balawcm.wordpress.com/2013/02/13/curl-it-out-adobe-cq5-curl-commands-and-usage/


By aem4beginner