[xwiki-devs] RESTful Create Page doesn't exist?
Hello everyone, I'm trying to automate Page generation in my client but I'm stuck on something. The way it works is a simple form on my client let's my users construct a Page Title to search for, so: .../xwiki/bin/view/Main/Whatever-Name-They've-Typed What I'm trying to do is if you get a 404 (and that page that says this doesn't exist, edit this to create) I create the page via REST commands and then direct them to the WYSIWYG editor for that new page - /xwiki/bin/edit/Main/Whatever-Name-They've-Typed - this works pretty much. The problem: The page doesn't seem to exist yet until they've clicked save and view on their editor. If I try to open the page I've just made via REST (at the aforementioned .../xwiki/bin/view/Main/Whatever-Name-They've-Typed) it says it still doesn't exist and edit this page to create. What gives? I'm doing all of this with XMLHTTPRequst and waiting for the 201 status after the page is supposedly successfully created then redirect them to the /edit/ page so they can start creating right away. -- View this message in context: http://xwiki.475771.n2.nabble.com/RESTful-Create-Page-doesn-t-exist-tp758418... Sent from the XWiki- Dev mailing list archive at Nabble.com.
Hi Zachary, in XWiki, a page does not exist until it has been saved at least once. A workaround you could try would be to create and save the page once, via REST, then send your user to that same page in edit mode. The user will actually be editing version 2.1 of the page. Would this work for you? Guillaume On Thu, Mar 7, 2013 at 8:03 PM, zacharykane <[email protected]> wrote:
Hello everyone, I'm trying to automate Page generation in my client but I'm stuck on something.
The way it works is a simple form on my client let's my users construct a Page Title to search for, so: .../xwiki/bin/view/Main/Whatever-Name-They've-Typed
What I'm trying to do is if you get a 404 (and that page that says this doesn't exist, edit this to create) I create the page via REST commands and then direct them to the WYSIWYG editor for that new page - /xwiki/bin/edit/Main/Whatever-Name-They've-Typed - this works pretty much.
The problem: The page doesn't seem to exist yet until they've clicked save and view on their editor. If I try to open the page I've just made via REST (at the aforementioned .../xwiki/bin/view/Main/Whatever-Name-They've-Typed) it says it still doesn't exist and edit this page to create. What gives?
I'm doing all of this with XMLHTTPRequst and waiting for the 201 status after the page is supposedly successfully created then redirect them to the /edit/ page so they can start creating right away.
-- View this message in context: http://xwiki.475771.n2.nabble.com/RESTful-Create-Page-doesn-t-exist-tp758418... Sent from the XWiki- Dev mailing list archive at Nabble.com. _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
Possibly, I don't think a version offset would matter. How do you save a page with the REST api? Modify it with the PUT method? -- View this message in context: http://xwiki.475771.n2.nabble.com/RESTful-Create-Page-doesn-t-exist-tp758418... Sent from the XWiki- Dev mailing list archive at Nabble.com.
Playing around with URLs I found a page (notice) that comes up using what appears to be a purposely hidden "save" action. /xwiki/bin/view/Main/newmcia?resubmit=%2Fxwiki%2Fbin%2Fsave%2FMain%2Fnewmcia%3Fsrid%3DVYMY1YRY&xback=%2Fxwiki%2Fbin%2Fview%2FMain%2Fnewmcia&xpage=resubmit The notification is a warning that tells me I might have left an editor open in another tab/window, my auth token has expired or this might be a hack. Confirm or Canel? And the form there submits to this: /xwiki/bin/save/Main/newmcia?srid=VYMY1YRY I'm betting XWiki generates that special identification for organizational/IA purposes and I'm not supposed to create those myself, right? -- View this message in context: http://xwiki.475771.n2.nabble.com/RESTful-Create-Page-doesn-t-exist-tp758418... Sent from the XWiki- Dev mailing list archive at Nabble.com.
Hi, you can just sent a PUT request to the following URI: /rest/wikis/YOURWIKI/spaces/THE_SPACE_WHERE_YOU_WANT_TO_CREATE_THE_PAGE/pages/THE_NAME_OF_THE_PAGE_YOU_WANT_TO_CREATE the body should be either an XML that follows the schema defined for the Page element here: https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwik... or a an application/x-www-form-urlencoded containing the relevant fields. The relevant fields that are taken into account are: title, content, syntax, parent. To be more clear suppose you want to create a page Foo in the Main space. You need to create an XML document like this: <page xmlns="http://www.xwiki.org"> <title>Foo</title> <content> I am foo! </content> </page> and send it, for example, by using curl: curl -u Admin:admin -H "Content-type: application/xml" -X PUT -d "@thefilecontainingthexmldocument.xml" http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/Foo Alternatively you can send application/x-www-form-urlencoded by specifying several -d parameters: curl -u Admin:admin -X PUT -d "content=this is Foo" -d "title=Foo" http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/Foo Of course the same can be achieved by writing some Java code and using HttpClient, or in any programming language or scripting language that has an HTTP library. Finally, it's just HTTP Hope this helps, Fabio On Fri, Mar 8, 2013 at 3:40 PM, zacharykane <[email protected]> wrote:
Possibly, I don't think a version offset would matter.
How do you save a page with the REST api? Modify it with the PUT method?
-- View this message in context: http://xwiki.475771.n2.nabble.com/RESTful-Create-Page-doesn-t-exist-tp758418... Sent from the XWiki- Dev mailing list archive at Nabble.com. _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
Well I think I figured out what wasn't working.. Here's what I'm trying to do with a "thin client" JavaScript application. var create = 'https://domain/xwiki/rest/wikis/XWiki/spaces/Main/pages/' + reportType + ' – ' + reportDate + 'T' + reportTime + 'P' + reportPeriod + '?method=PUT'; httpRequest.open('POST', create); httpRequest.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); httpRequest.send('title=' + reportType + ' – ' + reportDate + 'T' + reportTime + 'P' + reportPeriod + '&content=' + reportType + ' – ' + reportDate + 'T' + reportTime + 'P' + reportPeriod + '&parent=Main.WebHome'); What I've discovered is that I want my Page created based upon a template, that exists already. So I want to add &template=Main.MyTemplate to the request which doesn't seem to be allowed. If I view Document Index (/AllDocs) of my wiki I see that the page is listed but has no Last Author, which I thought was weird. So leaving that off and creating the Page with only the bare necessities, it works however I cannot now specify the &template query param on the /edit/ URL to open the document with a template, since it already exists with content. So is there a way to create a page in this way with a template for content? -- View this message in context: http://xwiki.475771.n2.nabble.com/RESTful-Create-Page-doesn-t-exist-tp758418... Sent from the XWiki- Dev mailing list archive at Nabble.com.
On Tue, Mar 12, 2013 at 7:08 PM, zacharykane <[email protected]> wrote:
Well I think I figured out what wasn't working.. Here's what I'm trying to do with a "thin client" JavaScript application.
var create = 'https://domain/xwiki/rest/wikis/XWiki/spaces/Main/pages/' + reportType + ' – ' + reportDate + 'T' + reportTime + 'P' + reportPeriod + '?method=PUT';
httpRequest.open('POST', create); httpRequest.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); httpRequest.send('title=' + reportType + ' – ' + reportDate + 'T' + reportTime + 'P' + reportPeriod + '&content=' + reportType + ' – ' + reportDate + 'T' + reportTime + 'P' + reportPeriod + '&parent=Main.WebHome');
I don't know why are you complicating things like this... You can direcly du a PUT request instead of doing a POST to an URI saying that actually it's a PUT :)
What I've discovered is that I want my Page created based upon a template, that exists already. So I want to add &template=Main.MyTemplate to the request which doesn't seem to be allowed. If I view Document Index (/AllDocs) of my wiki I see that the page is listed but has no Last Author, which I thought was weird.
So leaving that off and creating the Page with only the bare necessities, it works however I cannot now specify the &template query param on the /edit/ URL to open the document with a template, since it already exists with content. So is there a way to create a page in this way with a template for content?
The REST page resource doesn't accept any parameter called template. /edit URIs are a total different things with respect to the REST API URIs. -Fabio
-- View this message in context: http://xwiki.475771.n2.nabble.com/RESTful-Create-Page-doesn-t-exist-tp758418... Sent from the XWiki- Dev mailing list archive at Nabble.com. _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
Right, I just wanted to play it safe - I wasn't sure what the XmlHttpRequest object would allow as far as verbs. It works as intended. Also, sure the rest doesn't accept templates - that's a shame but oh well. I'm trying now to get the template content into a created page. I've figured I can fetch the content of the template page, using a GET, and put that <content> element's content into the parameter of the create page arguments. Current tests seem to work out - haven't tried more complicated templates but header images and subtitles come across. I mentioned the /edit/ URLs in passing that if you do put certain parameters (?template= in this case) it will put the template into the WYSIWYG editor of the specified Page, very slick. Anyway, if anyone knows of a way to "create pages with templates" that sounds better than what I described above I'd love to hear it! -- View this message in context: http://xwiki.475771.n2.nabble.com/RESTful-Create-Page-doesn-t-exist-tp758418... Sent from the XWiki- Dev mailing list archive at Nabble.com.
Hi Zachary 2013/3/13 zacharykane <[email protected]>
Right, I just wanted to play it safe - I wasn't sure what the XmlHttpRequest object would allow as far as verbs. It works as intended.
Also, sure the rest doesn't accept templates - that's a shame but oh well. I'm trying now to get the template content into a created page. I've figured I can fetch the content of the template page, using a GET, and put that <content> element's content into the parameter of the create page arguments. Current tests seem to work out - haven't tried more complicated templates but header images and subtitles come across.
I mentioned the /edit/ URLs in passing that if you do put certain parameters (?template= in this case) it will put the template into the WYSIWYG editor of the specified Page, very slick.
There is 2 options to avoid this behaviour. - First: just add "?editor=inline" in the URL. - Or, use a class sheet binding if your document is supposed to have an object (you can see: http://extensions.xwiki.org/xwiki/bin/view/Extension/Sheet+Module)
Anyway, if anyone knows of a way to "create pages with templates" that sounds better than what I described above I'd love to hear it!
I hope what I proposed help you. Louis-Marie
participants (4)
-
Fabio Mancinelli -
Guillaume "Louis-Marie" Delhumeau -
Guillaume Lerouge -
zacharykane