0

I'm trying to create a node using the sling api in AEM 6.0. Now I know I can easily create a node using a curl call like this

curl -u admin:admin -F"jcr:primaryType= sling:Mapping" http://localhost:4502/content/mynode

But what if I need to get fancy and try to create a resource mapping node with a name like this /etc/map.publish.prd/http/prd.rb.mysite.ca

Now the following curl call does not work anymore because part of the url is treated as selectors

curl -u admin:admin -F"jcr:primaryType= sling:Mapping"  http://localhost:4502/etc/map.publish.prd/http/prd.rb.mysite.com

So how would I go about avoiding this issue?

I also tried using the name property to limit the complexity of the url like this.

curl -u admin:admin -F"jcr:primaryType=sling:Mapping" -F"name=prd.rb.mysite.com" http://localhost:4502/etc/map.publish.prd/http

But I think sling still gets confused by map.publish.prd

Any help will be much appreciated Thanks

-Alain

2 Answers2

0

The trick is to post to /etc/* which causes the :name parameter to be used as is for the new node's path:

  curl -u admin:admin \
  -F"jcr:primaryType=sling:Mapping" \
  -F:name=./map.publish.prd/http/prd.rb.mysite.ca \
  http://localhost:4502/etc/*

This only works if /etc/map.publish.prd does not exist yet, but otherwise you can use the same trick further down the tree.

Bertrand Delacretaz
  • 6,100
  • 19
  • 24
  • Thanks for the answer Bertrand. For my particular use case, I will need to create multiple nodes under map.publish.prd . ex. prd.rb.mysite.ca, prd.rb.yoursite.ca etc. I guess I could take an approach where I would use a first call to create the node under the /tmp node and then move it under map.publish.prd with a second call. What do you think? – Alain Laniel Jun 17 '15 at 11:39
  • Hello Bertrand, Here is how I worked around the issue. – Alain Laniel Jun 17 '15 at 12:32
  • Bertrand, Here is the workaround we found. The script uses a first call to create the node under /tmp like this `curl -X POST -u admin:admin -F"jcr:primaryType=sling:Mapping" -F":name=" http://localhost:4502/tmp/my-temp-site`. From there it can add additional nodes under my-temp-site as needed with more calls. When the script is done with the my-temp-site node it then moves it to it's final resting place with this `curl -X POST -u admin:admin -F":operation=move" -F":dest=/etc/map.publish.prd/http/prd.rb.mysite.ca" http://localhost:4502/tmp/my-tmp-site`. I've tested it and so far it works us. – Alain Laniel Jun 17 '15 at 12:42
  • There is an error in the create call above. it should read `curl -X POST -u admin:admin -F"jcr:primaryType=sling:Mapping" http://localhost:4502/tmp/my-temp-site`. The -F":name=" is not needed there – Alain Laniel Jun 17 '15 at 12:53
  • Your workaround looks good to me - just make sure to use a unique name for the temporary node. – Bertrand Delacretaz Jun 17 '15 at 15:03
0

Here is the workaround we found. The script uses a first call to create the node under /tmp like this

curl -X POST -u admin:admin -F"jcr:primaryType=sling:Mapping" http://localhost:4502/tmp/my-temp-site.

From there the script can add additional nodes under my-temp-site as needed with more curl calls. When the script is done tinkering with the my-temp-site node it then moves it to it's final resting place with this

curl -X POST -u admin:admin -F":operation=move" -F":dest=/etc/map.publish.prd/http/prd.rb.mysite.ca" http://localhost:4502/tmp/my-tmp-site

We've tested it and so far it works us.

Like @bertrand mentioned we will add a timestamp to the name of the /tmp/my-temp-site node to make it unique and avoid conflicts

-Alain