Jahia in English > Restful JCR Access...

1 (1 Good)
0 (0 Bad)

Restful JCR Access - examples for the correct json body for DELETE

by  hchingwong@gmail.com »  2016/05/09 15:45

Hi,
I half figured out the problem already, trying a few different things. But stil, I couldn't come up with the correct way to do deletionsss.
I tried a few different thing for the data in the DELETE request, the error I'm getting is "400 Bad Request..... errorMissing body"

$.ajax({
        data: "??????????"
}
 

Following are what I did for the "Fun with Jahia Restful API" tutorial but using ajax and new API
(https://www.jahia.com/fr/communaute/extend/technicalblog/funwithjahiasrestapitutoria)

GET (working):

            function refreshList() {
              $("#contentList").html("Loading...");
              $.ajax({
                url: "/modules/api/jcr/v1/live/en/paths/sites/systemsite/contents?includeFullChildren",
                cache: false
              }).done(function (json) {
                var listNode = $("#contentList");
                var listHTML = '<table class="table table-striped">';
                listHTML += "<thead><tr><th>Node name</th><th>Type</th><th>Text</th></tr></thead>"
                if (json.children != null) {
                  $.each(json.children, function (index, data) {
                    var text = data.properties.text;
                    if (text != null)
                      text = text.value;
                    listHTML += '<tr>' +
                      '<td>' + data['name'] + '</td>' +
                      '<td>' + data['type'] + '</td>' +
                      '<td>' + text + '</td>' +
                      // '<td>' + data['properties']['text']['value'] + '</td>' +
                      '<td><a href="#" class="delete-node btn mini red-stripe" role="button"' +
                      'name="' + data['name'] + '"' +
                      'data-id="' + index + '"' +
                      '>Delete</a></td>' +
                      '</tr>';
                  });
                }
                listHTML += '</table>';
                listNode.html(listHTML);
              });
            }

 

PUT (working):

            $('#btnCreateNewNode').click(function(){
                alert("creating new node");
                $.ajax({
                  type: "PUT",
                  url: '/modules/api/jcr/v1/live/en/paths/sites/systemsite/contents/children/' + $("#name").val(),
                  success: function() {
                    alert('Content created successfully');
                    refreshList();
                  },
                  error: function(xhr, status, error) {
                    alert(status + xhr.responseText);
                  },
                  contentType: "application/json; charset=utf-8",
                  data: '{ "type": "jnt:text",                                       ' +
                        '  "properties": {                                           ' +
                        '      "text": "' + $("#text").val() + '"                    ' +
                        '   }                                                        ' +
                        '}                                                           '
                });
            });

 

DELETE (not working devil):

            $('#contentList').on('click', '.delete-node', function(e) {
             
              var name = $(this).attr('name');
              alert("deleting node: " + name);
              
              $.ajax({
                type: "DELETE",
                url: '/modules/api/jcr/v1/live/en/paths/sites/systemsite/contents/children',
                success: function() {
                  alert('Content successfully deleted');
                  refreshList();
                },
                error: function(xhr, status, error) {
                  alert(status + xhr.responseText);
                },
                contentType: "application/json; charset=utf-8",
                data: '???????????????????????????????????????????????????????/??'
              });
            });

I did tried a few things, might even be something stupid like typo, I also has api's source code with me but if someone can have a look for me here it would be really appreciated.

'["nodeToBeDeleted"]'?
'{["nodeToBeDeleted"]}'?
'[{nodeToBeDeleted}]'?

  • Restful JCR Access - examples for the correct json body for DELETE
    2016/05/10 20:43

    hchingwong@gmail.com <p>Hi,<br /> I half figured out the problem already, trying a few different things. But stil, I couldn&#39;t come up with the correct way to do deletionsss.<br /> I tried a few different thing for the data in the DELETE request, the error I&#39;m getting is &quot;400 Bad Request..... errorMissing body&quot;</p> <p>$.ajax({<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; data: &quot;??????????&quot;<br /> }<br /> &nbsp;</p> <p>Following are what I did for the &quot;Fun with Jahia Restful API&quot; tutorial but using ajax and new API<br /> (https://www.jahia.com/fr/communaute/extend/technicalblog/funwithjahiasrestapitutoria)</p> <p><strong>GET (working):</strong></p> <blockquote> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; function refreshList() {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(&quot;#contentList&quot;).html(&quot;Loading...&quot;);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $.ajax({<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; url: &quot;/modules/api/jcr/v1/live/en/paths/sites/systemsite/contents?includeFullChildren&quot;,<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cache: false<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }).done(function (json) {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var listNode = $(&quot;#contentList&quot;);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var listHTML = &#39;&lt;table class=&quot;table table-striped&quot;&gt;&#39;;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; listHTML += &quot;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Node name&lt;/th&gt;&lt;th&gt;Type&lt;/th&gt;&lt;th&gt;Text&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&quot;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (json.children != null) {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $.each(json.children, function (index, data) {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var text = data.properties.text;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (text != null)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; text = text.value;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; listHTML += &#39;&lt;tr&gt;&#39; +<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#39;&lt;td&gt;&#39; + data[&#39;name&#39;] + &#39;&lt;/td&gt;&#39; +<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#39;&lt;td&gt;&#39; + data[&#39;type&#39;] + &#39;&lt;/td&gt;&#39; +<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#39;&lt;td&gt;&#39; + text + &#39;&lt;/td&gt;&#39; +<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // &#39;&lt;td&gt;&#39; + data[&#39;properties&#39;][&#39;text&#39;][&#39;value&#39;] + &#39;&lt;/td&gt;&#39; +<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#39;&lt;td&gt;&lt;a href=&quot;#&quot; class=&quot;delete-node btn mini red-stripe&quot; role=&quot;button&quot;&#39; +<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#39;name=&quot;&#39; + data[&#39;name&#39;] + &#39;&quot;&#39; +<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#39;data-id=&quot;&#39; + index + &#39;&quot;&#39; +<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#39;&gt;Delete&lt;/a&gt;&lt;/td&gt;&#39; +<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#39;&lt;/tr&gt;&#39;;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; listHTML += &#39;&lt;/table&gt;&#39;;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; listNode.html(listHTML);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> </blockquote> <p>&nbsp;</p> <p><strong>PUT (working):</strong></p> <blockquote> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(&#39;#btnCreateNewNode&#39;).click(function(){<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert(&quot;creating new node&quot;);<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $.ajax({<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; type: &quot;PUT&quot;,<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; url: &#39;/modules/api/jcr/v1/live/en/paths/sites/systemsite/contents/children/&#39; + $(&quot;#name&quot;).val(),<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; success: function() {<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert(&#39;Content created successfully&#39;);<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; refreshList();<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; },<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; error: function(xhr, status, error) {<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert(status + xhr.responseText);<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; },<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#39;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; });</p> </blockquote> <p>&nbsp;</p> <p><strong>DELETE (not working <img alt="devil" height="23" src="https://www.jahia.com/modules/ckeditor/javascript/plugins/smiley/images/devil_smile.png" title="devil" width="23" />):</strong></p> <blockquote> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(&#39;#contentList&#39;).on(&#39;click&#39;, &#39;.delete-node&#39;, function(e) {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var name = $(this).attr(&#39;name&#39;);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert(&quot;deleting node: &quot; + name);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $.ajax({<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; type: &quot;DELETE&quot;,<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; url: &#39;/modules/api/jcr/v1/live/en/paths/sites/systemsite/contents/children&#39;,<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; success: function() {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert(&#39;Content successfully deleted&#39;);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; refreshList();<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; },<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; error: function(xhr, status, error) {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert(status + xhr.responseText);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; },<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; contentType: &quot;application/json; charset=utf-8&quot;,<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; data: &#39;???????????????????????????????????????????????????????/??&#39;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });</p> </blockquote> <p>I did tried a few things, might even be something stupid like typo, I also has api&#39;s source code with me but if someone can have a look for me here it would be really appreciated.</p> <p>&#39;[&quot;nodeToBeDeleted&quot;]&#39;?<br /> &#39;{[&quot;nodeToBeDeleted&quot;]}&#39;?<br /> &#39;[{nodeToBeDeleted}]&#39;?</p>

  • Number of messages  7
    Registration date May 9, 2016
    0 (0 Good)
    0 (0 Bad)

    Re: Restful JCR Access - examples for the correct json body for DELETE

    by  claprun »  2016/05/10 20:43

    Hi,

    Following are what I did for the "Fun with Jahia Restful API" tutorial but using ajax and new API
    (https://www.jahia.com/fr/communaute/extend/technicalblog/funwithjahiasrestapitutoria)

    Please note that this blog post uses the legacy REST API, while you are trying to use the new JCR RESTful API. You can find more details regarding this new API and how to use it at https://www.jahia.com/community/extend/developers-techwiki/content-manipulation/restful-jcr-access

    That said, the reason why your DELETE is not working is because you don't specify which element you want to delete in the URL. You would need to use the URL: /modules/api/jcr/v1/live/en/paths/sites/systemsite/contents/children/<name of the node to delete> in order to delete the node without passing any body to the request. Note also that you need to be using the 1.1 or above version of the API to be able to delete a node by its path. Your question also made me realize that the by-path API is not on par with the by-id API when it comes to node deletion as passing a list of nodes via an array of node names in the body of the request (["node1", "node2"]) is not currently supported. I've opened a ticket to add this feature to a future version of the API: https://jira.jahia.org/browse/BACKLOG-6523

    Thank you for your question. I hope this helps.

    Best,

    Chris

     

  • Re: Restful JCR Access - examples for the correct json body for DELETE
    2016/05/10 20:43

    claprun <p>Hi,</p> <blockquote> <p>Following are what I did for the &quot;Fun with Jahia Restful API&quot; tutorial but using ajax and new API<br /> (https://www.jahia.com/fr/communaute/extend/technicalblog/funwithjahiasrestapitutoria)</p> </blockquote> <p>Please note that this blog post uses the legacy REST API, while you are trying to use the new JCR RESTful API. You can find more details regarding this new API and how to use it at&nbsp;<a href="https://www.jahia.com/community/extend/developers-techwiki/content-manipulation/restful-jcr-access">https://www.jahia.com/community/extend/developers-techwiki/content-manipulation/restful-jcr-access</a></p> <p>That said, the reason why your DELETE is not working is because you don&#39;t specify which element&nbsp;you want to delete in the URL. You would need to use the URL:&nbsp;<span style="font-family: Georgia, Times, 'Times New Roman', serif; font-style: italic;">/modules/api/jcr/v1/live/en/paths/sites/systemsite/contents/children/&lt;name of the node to delete&gt; </span>in order to delete the node without passing any body to the request. Note also that you need to be using the 1.1 or above version of the API to be able to delete a node by its path. Your question also made me realize that the by-path API is not on par with the by-id API when it comes to node deletion as passing a list of nodes via an array of node names in the body of the request ([&quot;node1&quot;, &quot;node2&quot;]) is not currently supported. I&#39;ve opened a ticket to add this feature to a future version of the API:&nbsp;<a href="https://jira.jahia.org/browse/BACKLOG-6523">https://jira.jahia.org/browse/BACKLOG-6523</a></p> <p>Thank you for your question. I hope this helps.</p> <p>Best,</p> <p>Chris</p> <p>&nbsp;</p>

  • Number of messages  5
    Registration date May 10, 2016
    Contact
    Share
    Feedback

    Get in touch

    Whether you are a current user or if you are just evaluating Jahia, we are here to help.

    Contact us

    Share this page