Jahia DX > Jahia Forum Component...

0 (0 Good)
0 (0 Bad)

Jahia Forum Component : how to use REST API to insert data to the forum?

by  kamran »  2011/07/20 14:21

Hi,

I saw in the documentation that it is possible to use REST API to insert datas to a forum (https://www.jahia.com/community/documentation/jahiapedia/jahia-modules/rest.html)

My idea is to create a script that will parse my old forum content (that is not using Jahia) and to use the REST POST method to insert new content to my Jahia Forum Component.

The example displayed on the above link, is not very clear because it seems to use Jahia variables. In my case I will be "outside" jahia application.

Do you know where I can find more documentation about the REST API and the Jahia Forum API ?

Thanks

Kamran

  (kamran)

Number of messages  31
Registration date
0 (0 Good)
0 (0 Bad)

Re: Jahia Forum Component : how to use REST API to insert data to the forum?

by  poiuytrez »  2011/07/21 14:14

Hi,

I saw in the documentation that it is possible to use REST API to insert datas to a forum (https://www.jahia.com/community/documentation/jahiapedia/jahia-modules/rest.html)

My idea is to create a script that will parse my old forum content (that is not using Jahia) and to use the REST POST method to insert new content to my Jahia Forum Component.

The example displayed on the above link, is not very clear because it seems to use Jahia variables. In my case I will be "outside" jahia application.

Do you know where I can find more documentation about the REST API and the Jahia Forum API ?

Thanks

Kamran

Hello Kamran,


Yes, you are right, the jahia variables are confusing.

I have an example to add "dog" objects on jahia. I think you can adapt this example to add forum posts using rest :

<html>
    <body>
        <form action="/cms/render/default/en/sites/ACME/home/better-dogs/dogarea/*" method="post">
                <input type="hidden" name="nodeType" value="jnt:dog"/>

            <input type="hidden" name="jcrNodeType" value="jnt:dog"/>
                jcr title :
                <input value="superdog" name="jcr:title" type="text"  /><br />
                Dog Name :
                <input name="dogName" type="text"></textarea><br />
                Dog Biography :
                <textarea rows="7" cols="35" name="dogBio" ></textarea><br />

                <input type="reset" value="Reset" /><br />

                <input type="submit" value="Submit" />
        </form>
    </body>
</html>
 

I hope it helps.

poiuytrez

  • Re: Jahia Forum Component : how to use REST API to insert data to the forum?
    2011/08/02 07:53

    poiuytrez <blockquote> <p> Hi,</p> <p> I saw in the documentation that it is possible to use REST API to insert datas to a forum (https://www.jahia.com/community/documentation/jahiapedia/jahia-modules/rest.html)</p> <p> My idea is to create a script that will parse my old forum content (that is not using Jahia) and to use the REST POST method to insert new content to my Jahia Forum Component.</p> <p> The example displayed on the above link, is not very clear because it seems to use Jahia variables. In my case I will be &quot;outside&quot; jahia application.</p> <p> Do you know where I can find more documentation about the REST API and the Jahia Forum API ?</p> <p> Thanks</p> <p> Kamran</p> </blockquote> <p> Hello Kamran,</p> <p> <br /> Yes, you are right, the jahia variables are confusing.<br /> <br /> I have an example to add &quot;dog&quot; objects on jahia. I think you can adapt this example to add forum posts using rest :</p> <p> &lt;html&gt;<br /> &nbsp;&nbsp; &nbsp;&lt;body&gt;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&lt;form action=&quot;/cms/render/default/en/sites/ACME/home/better-dogs/dogarea/*&quot; method=&quot;post&quot;&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<strike>&nbsp; &nbsp;&lt;input type=&quot;hidden&quot; name=&quot;nodeType&quot; value=&quot;jnt:dog&quot;/&gt;</strike></p> <p> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;input type=&quot;hidden&quot; name=&quot;jcrNodeType&quot; value=&quot;jnt:dog&quot;/&gt;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jcr title :<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&lt;input value=&quot;superdog&quot; name=&quot;jcr:title&quot; type=&quot;text&quot;&nbsp; /&gt;&lt;br /&gt;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;Dog Name :<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&lt;input name=&quot;dogName&quot; type=&quot;text&quot;&gt;&lt;/textarea&gt;&lt;br /&gt;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;Dog Biography :<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&lt;textarea rows=&quot;7&quot; cols=&quot;35&quot; name=&quot;dogBio&quot; &gt;&lt;/textarea&gt;&lt;br /&gt;<br /> <br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&lt;input type=&quot;reset&quot; value=&quot;Reset&quot; /&gt;&lt;br /&gt;<br /> <br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&lt;input type=&quot;submit&quot; value=&quot;Submit&quot; /&gt;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&lt;/form&gt;<br /> &nbsp;&nbsp; &nbsp;&lt;/body&gt;<br /> &lt;/html&gt;<br /> &nbsp;</p> <p> I hope it helps.</p> <p> poiuytrez</p>

  • Number of messages  16
    Registration date Jul 21, 2011
    0 (0 Good)
    0 (0 Bad)

    Re: Re: Jahia Forum Component : how to use REST API to insert data to the forum?

    by  kamran »  2011/07/27 15:03

    Hello Kamran,


    Yes, you are right, the jahia variables are confusing.

    I have an example to add "dog" objects on jahia. I think you can adapt this example to add forum posts using rest :

    <html>
        <body>
            <form action="/cms/render/default/en/sites/ACME/home/better-dogs/dogarea/*" method="post">
                <input type="hidden" name="nodeType" value="jnt:dog"/>
                    jcr title :
                    <input value="superdog" name="jcr:title" type="text"  /><br />
                    Dog Name :
                    <input name="dogName" type="text"></textarea><br />
                    Dog Biography :
                    <textarea rows="7" cols="35" name="dogBio" ></textarea><br />

                    <input type="reset" value="Reset" /><br />

                    <input type="submit" value="Submit" />
            </form>
        </body>
    </html>

    I hope it helps.

    poiuytrez

    I think I have some difficulties to understand how works the forum with the REST API :-/

    I did something like :

    <html>
    <head>
    </head>
    <body>
        <form action="http://localhost:9080/cms/render/live/en/sites/ACME/home/forum/r/s/*" method="post">
            <input type="hidden" value="jnt:post" name="jcrNodeType"/>
            <input type="hidden" value="/cms/render/live/en/sites/ACME/home/forum/r/s.forum-newTopic" name="jcrRedirectTo">
            <input type="hidden" value="html" name="jcrNewNodeOutputFormat">
            <fieldset>
                <p>
                    jcr:title: <input value="" type="text" size="35" name="jcr:title" tabindex="1"/>
                </p>
                <p>
                    content: <textarea rows="7" cols="35" name="content" tabindex="2"></textarea>
                </p>
                <p>
                    <input type="reset" value="Reset" tabindex="3"/>
                    <input type="submit" value="Submit" tabindex="4"/>
                </p>
            </fieldset>
        </form>
    </body>
    </html>

    And the result is that it creates a jnt:post that is directly attached to the section (and not to a topic) :-/

    It doesn't create any jnt:node element.

    Any idea ?

      (kamran)

    Number of messages  31
    Registration date
    0 (0 Good)
    0 (0 Bad)

    Re: Re: Re: Jahia Forum Component : how to use REST API to insert data to the forum?

    by  kamran »  2011/07/28 15:27

    I have just discovered one thing quite important : I have to put my html file that contains the form with the REST request "inside" Jahia, for exemple in a module like for test example ! (and not outside jahia, somewhere in my computer, for example).

    Like this I can insert new topics to my forum, I can also set the author of the post using the field "pseudo".

    BUT I CAN NOT modify the date of the post by using "jcr:created" : I have the following error :

    javax.jcr.nodetype.ConstraintViolationException: Unable to perform operation. Node is protected : /site/ACME/home/forum/r/s/toto5/toto5/jcr:created

    Do you know how I can modify the jcr:created date of a content ?

    Thanks

     

    Marc

      (kamran)

    Number of messages  31
    Registration date

    by  cflond »  2011/08/02 07:51

    Hi Kamran,

     

    1- I just reply to y our other post which is about the same subject. :

    http://www.jahia.com/cms/home/community/forum/jahia-user/jahia-65/how-to-change-jcrcreated--value.html

    I let you continue the discution on this dedicated topic.

     

    2- I just correct a mistake in the code provided on this topic. The property "nodeType" is no more supported by the REST API (it was an old attribtue used on BETA versions). It is now jcrNodeType. You can see the related online documentation here :http://www.jahia.com/community/documentation/jahiapedia/jahia-modules/rest.html

     

    3- For your remarks :

    "I have just discovered one thing quite important : I have to put my html file that contains the form with the REST request "inside" Jahia, for exemple in a module like for test example ! (and not outside jahia, somewhere in my computer, for example)."

    This is because you used jQuery and so Ajax to perform your HTTP calls. Browser security policy imposes AJAX calls to be done on the same domain. So if Jahia use localhost:8080, you need to put your file in Tomcat to have the same domain. If you use synchronous HTTP calls (like with JMeter), you don't have this problem. You can bypass this kind of restriction with XMLHTTPRequest Proxy on server side !

     

    4- Please let me know if you still need help to play with the REST API ;-)

     

    Regards,

    Charles

  • 2011/08/02 07:57

    cflond <p> Hi Kamran,</p> <p> &nbsp;</p> <div style="font-family: Arial, Verdana, sans-serif; font-size: 12px; color: rgb(34, 34, 34); background-color: rgb(255, 255, 255); "> <p> 1- I just reply to y our other post which is about the same subject.&nbsp;:</p> <p> <a href="http://www.jahia.com/cms/home/community/forum/jahia-user/jahia-65/how-to-change-jcrcreated--value.html">http://www.jahia.com/cms/home/community/forum/jahia-user/jahia-65/how-to-change-jcrcreated--value.html</a></p> <p> I let you continue the discution on this dedicated topic.</p> <p> &nbsp;</p> <p> 2- I just correct a mistake in the code provided on this topic.&nbsp;The property &quot;nodeType&quot; is no more supported by the REST API (it was an old attribtue used on BETA versions). It is now jcrNodeType.&nbsp;You can see the related online documentation here :<a href="http://www.jahia.com/community/documentation/jahiapedia/jahia-modules/rest.html">http://www.jahia.com/community/documentation/jahiapedia/jahia-modules/rest.html</a></p> <p> &nbsp;</p> <p> 3- For your remarks :</p> <p> &quot;I have just discovered one thing quite important : I have to put my html file that contains the form with the REST request &quot;inside&quot; Jahia, for exemple in a module like for test example ! (and not outside jahia, somewhere in my computer, for example).&quot;</p> <p> This is because you used jQuery and so Ajax to perform your HTTP calls. Browser security policy imposes AJAX calls to be done on the same domain. So if Jahia use localhost:8080, you need to put your file in Tomcat to have the same domain. If you use synchronous HTTP calls (like with JMeter), you don&#39;t have this problem. You can bypass this kind of restriction with XMLHTTPRequest Proxy on server side !</p> <p> &nbsp;</p> <p> 4- Please let me know if you still need help to play with the REST API ;-)</p> <p> &nbsp;</p> <p> Regards,</p> <p> Charles</p> </div>

  • Number of messages  42
    Registration date Aug 2, 2011
    0 (0 Good)
    0 (0 Bad)

    Sollte man Vakuumbeutel auch für Essen verwenden

    by  BrendaTrevy »  2017/06/19 15:54

    Hallo ihr Lieben, ich habe die Problematik ob ein Vakuumbeutel im Koffer mehr Platz schafft Nebensächlich interessiert mich auch wie viel und was ich rein in einen Vakuumbeutel hinpacken kann. Ich habe darüber 'ne Seite gefunden, aus der man aber nicht schlau wird. Vielen Dank für die Hilfe
    BrendaTrevy
    Number of messages  1
    Not registered
    0 (0 Good)
    0 (0 Bad)

    NFL Game Live Online Free

    by  Jaspertix »  2017/08/22 19:19

    Jaspertix
    Number of messages  1
    Not registered
    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