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?

 

  (cachavez)

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

 

  (cachavez)

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

 

  (cachavez)

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