Expand my Community achievements bar.

SOLVED

cURL: Is it possible to add filter for packaging a specific content path

Avatar

Level 2

 Im using cURL in windows. Add filters is not working for me. Please help me to resolve the issue

 

# create package
curl -u admin:admin -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages/testpackage?cmd=create -d packageName=testpackage -d groupName=my_packages

 

# add filters

curl -u admin:admin -X POST http://localhost:4502/crx/packmgr/update.jsp -F path=/etc/packages/my_packages/testpackage.zip -F packageName=testpackage -F groupName=my_packages -F 'filter=[{'root':'/content/dam/pdf/sample/pdffiles'}]' -F '_charset_=UTF-8'

# build package

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

1 Accepted Solution

Avatar

Correct answer by
Level 10

Referencehttp://hashimkhan.in/aem-adobecq5-code-templates/curl-aem-commands/

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

22

  • While clicking on Start keep a watch at the POST call from the Firebug Console>Network.

11

  • In every functionality you will see a call to server: either a POST or GET. Here you will find a POST call to the
  • After observing these values you can write your cURL command as:
     
1
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.

View solution in original post

10 Replies

Avatar

Level 10

If you want to work with packages that use filters via CUrl - the best thing to do is set the package and filter definition in Package Manager and then use Curl to rebuild the package. See:

Curl Commands

You can then rebuild an existing package:

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

There does not seem to be a build command that supports filters. 

Avatar

Correct answer by
Level 10

Referencehttp://hashimkhan.in/aem-adobecq5-code-templates/curl-aem-commands/

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

22

  • While clicking on Start keep a watch at the POST call from the Firebug Console>Network.

11

  • In every functionality you will see a call to server: either a POST or GET. Here you will find a POST call to the
  • After observing these values you can write your cURL command as:
     
1
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.

Avatar

Employee Advisor

In your command, the rules definition are missing as well as the quotation marks are not used correctly in the filter parameter. Try the following curl command and it should work- 

curl -u admin:admin -X POST http://localhost:4502/crx/packmgr/update.jsp -F'path=/etc/packages/my_packages/testpackage.zip' -F'packageName=testpackage' -F'groupName=my_packages' -F'filter=[{"root":"/content/dam/pdf/sample/pdffiles","rules":[]}]' -F'_charset_=UTF-8'

Avatar

Level 5

When I am running this command I am seeing this error. I am using Windows powershell to execute the cURL. Any idea what is wrong happening here?

 

curl.exe -u admin:admin -X POST http://localhost:4502/crx/packmgr/update.jsp -F'path=/etc/packages/my_packages/abc.zip' -F'packageName=abc' -F'groupName=my_packages' -F'filter=[{"root":"/content/geometrixx/en","rules":[]}]' -F'_charset_=UTF-8'


{"success":false,"msg":"Could not modify package. Missing value. at character 7 of [{root:/content/geometrixx/en,rules:[]}]","path":"/etc/packages/my_packages/abc.zip"}

Avatar

Level 5

This curl command worked on CURL window(Cygwin terminal). Thank you!

Avatar

Level 4

Below script is well tested on my servers:

echo "Starting" '\n'

curl -u admin:admin -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages/testpackage3?cmd=create \
-d packageName=testpackage3 \
-d groupName=my_packages

echo '\n'

echo "Package Created" '\n'

# add filters
curl -u admin:admin -X POST http://localhost:4502/crx/packmgr/update.jsp \
-F path=/etc/packages/my_packages/testpackage3.zip -F packageName=testpackage3 \
-F groupName=my_packages \
-F filter="[{\"root\" : \"/etc/tags\", \"rules\": [{\"modifier\" : \"include\", \"pattern\" : \"/.*\"}]}]" \
-F '_charset_=UTF-8'

echo '\n'

echo "Filters Added" '\n'

# build package
curl -u admin:admin -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages/testpackage3.zip?cmd=build

echo '\n'

echo "Package Built" '\n'

echo "end"

Avatar

Community Advisor

To add single/multiple filters to create a package, best way could be, create a text file and add all the filter paths in text file. 

Afterwards, create a script to create, add filter and build package with the help of curl command.

I've created a script which reads filter paths from text file then iterate over that file, add filters then build the package.

Code:

 

#!/bin/bash file=/home/shengcun/Desktop/path.txt echo "Starting" '\n' curl -u admin:admin -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages/content_package?cmd=create -d packageName=conten$ echo "Package Created" '\n' #RootPath variable to add filters rootpath= # add filters while IFS= read -r line do # echo line is stored in $line path='{"root":"'$line'","rules":[]}' if [ -z "$rootpath" ]; then rootpath=${path} else rootpath=${rootpath},${path} fi done < "$file" curl -u admin:admin -X POST http://localhost:4502/crx/packmgr/update.jsp -F'path=/etc/packages/my_packages/content_package.zip' -F'packageName=content_package' -F'groupName=my_packages' -F'filter=['$rootpath']' -F'_charset_=UTF-8' echo "Filters Added" '\n' # build package curl -u admin:admin -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages/content_package.zip?cmd=bui... echo "Package Built" '\n' echo "end"

This script is well tested.
Hope it works!

Avatar

Level 3

Hello Himanshu, is the format of text file just tab/return separated relative paths?

 

/home/shengcun/Desktop/path.txt

 I want to try this on our 6.5.10 env