cURL: Is it possible to add filter for packaging a specific content path | Adobe Higher Education
Skip to main content
bharathie812677
Level 2
December 28, 2015
Beantwortet

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

  • December 28, 2015
  • 7 Antworten
  • 53739 Ansichten

 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

Dieses Thema wurde für Antworten geschlossen.
Beste Antwort von edubey

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.

7 Antworten

smacdonald2008
Level 10
December 28, 2015

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. 

edubey
edubeyAntwort
Level 10
December 28, 2015

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.

Kunal_Gaba_
December 28, 2015

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'

RashidJorvee
Level 4
February 17, 2022

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"}

RashidJorvee
Level 4
February 17, 2022

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

prohira
Level 3
December 28, 2015

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"

Himanshu_Singhal
Community Advisor
Community Advisor
August 31, 2016

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=build echo "Package Built" '\n' echo "end"

This script is well tested.
Hope it works!

Level 3
March 2, 2022

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

smacdonald2008
Level 10
August 31, 2016

Thxs for posting

September 16, 2022

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.


https://gist.github.com/nateyolles/dd4ebe0a6b83c369029b?permalink_comment_id=2329947#gistcomment-2329947