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
Solved! Go to Solution.
Reference: http://hashimkhan.in/aem-adobecq5-code-templates/curl-aem-commands/
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:
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.
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:
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.
Reference: http://hashimkhan.in/aem-adobecq5-code-templates/curl-aem-commands/
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:
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.
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'
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"}
This curl command worked on CURL window(Cygwin terminal). Thank you!
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"
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!
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
Thxs for posting
For AEM 6.3 and above, please follow the below method for adding filters as the curl to http://localhost:4502/crx/packmgr/update.jsp is giving 404.
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies