Jahia in English > How use REST-API...

0 (0 Good)
0 (0 Bad)

How use REST-API to create content like UI "Document Manager" and "Content Manager" locations.

by  cachavez »  2013/11/21 23:58

Hello all.

I want to use REST API to create content in the repositories where the "Document Manager" and "Content Manager" put content items, but I did not find the correct path to get those location.

any idea onn how I can access those location using REST API?

 

  • How use REST-API to create content like UI "Document Manager" and "Content Manager" locations.
    2013/11/21 23:58

    cachavez <p> Hello all.</p> <p> I want to use REST API to create content in the repositories where the &quot;Document Manager&quot; and &quot;Content Manager&quot; put content items, but I did not find the correct path to get those location.</p> <p> any idea onn how I can access those location using REST API?</p> <p> &nbsp;</p>

  • Number of messages  32
    Registration date Nov 21, 2013
    0 (0 Good)
    0 (0 Bad)

    Re: How use REST-API to create content like UI "Document Manager" and "Content Manager" locations.

    by  cachavez »  2013/11/22 06:38

    Hi all.

    I found that the correct path to the "Content Manager" is: /cms/render/default/en/sites/<site key>/contents and for the "Document Manager" is: /cms/render/default/en/sites/<site key>/files/ .

    I'm able to create content items in those path using REST API, but i'm trying to upload files to /cms/render/default/en/sites/<site key>/files/, but without success: I'm doing with HttpClient from apache commons, the code looks like:

     

            //Configure post with the path to the content type parent to insert new child content types.
            final HttpPost httPost = new HttpPost(url);
            //Set content type post.
            httPost.setHeader("Content-Type", "multipart/form-data; boundary=-------file-------");
            //Set response type. Need as JSON the response.
            httPost.setHeader("Accept", "application/json");
            httPost.setHeader("X-Requested-With", "XMLHttpRequest");

            final MultipartEntityBuilder builder = MultipartEntityBuilder.create();
            builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
            builder.addBinaryBody("file", file, ContentType.APPLICATION_OCTET_STREAM, file.getName());
            builder.addTextBody("jcrNodeType", "jnt:file", ContentType.TEXT_PLAIN);
            builder.addTextBody("jcr:mixinTypes", "jmix:document", ContentType.TEXT_PLAIN);
            builder.addTextBody("jcrNormalizeNodeName", "true", ContentType.TEXT_PLAIN);
            builder.addTextBody("jcrNodeName", file.getName(), ContentType.TEXT_PLAIN);
            builder.addTextBody("jcrTargetDirectory", path, ContentType.TEXT_PLAIN);

            httPost.setEntity(builder.build());

            httpClient.execute(httPost);

     

     

    but Jahia always response as: HTTP/1.1 400 Bad Request

     

    any hint about the issue?

     

  • Re: How use REST-API to create content like UI "Document Manager" and "Content Manager" locations.
    2013/11/22 06:38

    cachavez <p> Hi all.</p> <p> I found that the correct path to the &quot;Content Manager&quot; is: /cms/render/default/en/sites/&lt;site key&gt;/contents and for the &quot;Document Manager&quot; is: /cms/render/default/en/sites/&lt;site key&gt;/files/ .</p> <p> I&#39;m able to create content items in those path using REST API, but i&#39;m trying to upload files to /cms/render/default/en/sites/&lt;site key&gt;/files/, but without success: I&#39;m doing with HttpClient from apache commons, the code looks like:</p> <p> &nbsp;</p> <p> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Configure post with the path to the content type parent to insert new child content types.<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; final HttpPost httPost = new HttpPost(url);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Set content type post.<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; httPost.setHeader(&quot;Content-Type&quot;, &quot;multipart/form-data; boundary=-------file-------&quot;);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Set response type. Need as JSON the response.<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; httPost.setHeader(&quot;Accept&quot;, &quot;application/json&quot;);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; httPost.setHeader(&quot;X-Requested-With&quot;, &quot;XMLHttpRequest&quot;);<br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; final MultipartEntityBuilder builder = MultipartEntityBuilder.create();<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; builder.addBinaryBody(&quot;file&quot;, file, ContentType.APPLICATION_OCTET_STREAM, file.getName());<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; builder.addTextBody(&quot;jcrNodeType&quot;, &quot;jnt:file&quot;, ContentType.TEXT_PLAIN);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; builder.addTextBody(&quot;jcr:mixinTypes&quot;, &quot;jmix:document&quot;, ContentType.TEXT_PLAIN);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; builder.addTextBody(&quot;jcrNormalizeNodeName&quot;, &quot;true&quot;, ContentType.TEXT_PLAIN);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; builder.addTextBody(&quot;jcrNodeName&quot;, file.getName(), ContentType.TEXT_PLAIN);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; builder.addTextBody(&quot;jcrTargetDirectory&quot;, path, ContentType.TEXT_PLAIN);<br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; httPost.setEntity(builder.build());</p> <p> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; httpClient.execute(httPost);</p> <p> &nbsp;</p> <p> &nbsp;</p> <p> but Jahia always response as: HTTP/1.1 400 Bad Request</p> <p> &nbsp;</p> <p> any hint about the issue?</p> <p> &nbsp;</p>

  • Number of messages  32
    Registration date Nov 22, 2013
    0 (0 Good)
    0 (0 Bad)

    Re: Re: How use REST-API to create content like UI "Document Manager" and "Content Manager" locations.

    by  cachavez »  2013/11/22 08:36

    Hi All.

    I found the issue, i removed fromt the post the "Content-Type" header and jcrTargetDirectory as well, then the file was uploaded correctly.

    I indicate in the post url the path where i want to put the file.

     

  • Re: Re: How use REST-API to create content like UI "Document Manager" and "Content Manager" locations.
    2013/11/22 08:36

    cachavez <p> Hi All.</p> <p> I found the issue, i removed fromt the post the &quot;Content-Type&quot; header and jcrTargetDirectory as well, then the file was uploaded correctly.</p> <p> I indicate in the post url the path where i want to put the file.</p> <p> &nbsp;</p>

  • Number of messages  32
    Registration date Nov 22, 2013
    0 (0 Good)
    0 (0 Bad)

    Re: Re: Re: How use REST-API to create content like UI "Document Manager" and "Content Manager" locations.

    by  faissah »  2013/11/25 22:57

    Thank you for posting it, we're glad you solved your issue!

    Fabrice  (faissah)

    Number of messages  264
    Registration date
    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