Creating a wiki using the REST API

I’m investigating the ability of XWiki to automate instantiating new subwikis. I figured it might be a good use case for the REST API. I was able to run some basic tests with the API like page creations and blog post creations. I noticed this section for wikimanager

/wikimanager (This resource is only available when using the multi-wiki feature)

    HTTP Method: POST
        Accepted Media types:
            application/xml (Wiki element)
        Media types:
            application/xml (Wiki element)
        Query parameters
            template  - the wiki template to be used for initializing the wiki.
            history={RESET/REPLACE/ADD} - history importing
        Description: create a new wiki.
        Status codes:
            200: If the request was successful.

on this page https://www.xwiki.org/xwiki/bin/view/Documentation/UserGuide/Features/XWikiRESTfulAPI#HXWikiRESTfulAPIDocumentation, which sounds like what I would want. I have the Wiki Application installed (running XWiki 10.6 in a test Docker instance) but not seeing anything meaningful when I hit this basic endpoint http://localhost:8080/rest/wikimanager — just a Not Found page.

40%20PM

Am I missing something or did the documentation get cutoff? Looking at the accepted media types, I was trying to figure out how a curl URL could be assembled but not seeing which XML properties correspond to creating new subwikis.

Is there a better way to automate subwiki instantiation? Any help would be greatly appreciated.

According to the docs you may be missing a “xwiki” in the URL, except you installed as ROOT application.

By defaut all the resources of the RESTful API are rooted at the following URI: http://server:port/xwiki/rest/ (depending on where your XWiki is running)

My particular test XWiki installation was installed with the publicly available XWiki Docker images so yes, it is ROOT (in Tomcat). The REST API is working only when I leave out the “xwiki” even though I have a main wiki “xwiki” and a subwiki “second”.

Maybe this:

HTTP Method: POST

Which suggests that it supports only POST method/action, while if you simply access http://localhost:8080/rest/wikimanager from the browser the method is GET. Have you tried doing a POST?

1 Like

I breezed through and passed this crucial detail. Will test a little later today and update the answer. Thanks!

Not having luck.

What I tried in cURL:

curl -u TestUser:password -X POST --data-binary "@newwiki.xml" -H "Content-Type: application/xml" http://0.0.0.0:8080/rest/wikimanager

And the “newwiki.xml” file has the following contents

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<wiki xmlns="http://www.xwiki.org">
  <id>testwiki</id>
  <name>testwiki</name>
  <description>A test wiki made by the REST API</description>
  <owner>TestUser</owner>
</wiki>

and also did the same thing in Postman.

The result I see is

{"code":404,"contactEmail":null,"description":"The server has not found anything matching the request URI","homeRef":"/","reasonPhrase":"Not Found","uri":"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.5"}

It seems that the module that provides the /rest/wikimanager REST resource is not bundled by default in XWiki Standard. @tmortagne, @gdelhumeau is this expected?

But even if you install it from the Wiki Administration > Extensions > Advanced Search using org.xwiki.platform:xwiki-patform-wiki-rest-default as extension id it still doesn’t seem to work. I get:

Error 405 HTTP method POST is not supported by this URL

I checked the code and it seems that the @POST annotation has been put on the resource implementation class rather than on the resource interface. Maybe that’s the problem?

That should not be a problem (what we give to Restlet is the implementation, not the interface which is only used by the client) but it’s possible you need to install it at root level.

@eban5 can you try to install org.xwiki.platform:xwiki-patform-wiki-rest-default on farm using Wiki Administration > Extensions > Advanced Search (the version should match your XWiki version, which is 10.6 I believe). And you may need to restart XWiki afterwards, I remember there was an issue with REST resources registered when an extension is installed, I don’t know if it was fixed.

It’s supposed to since 9.8 (I hope so :slight_smile:) but yeah just in case…

Thanks. I’ll give this a shot tonight and report back here.

Hi,

I have the same behavior, and unfortunately, I’m not able to find org.xwiki.platform:xwiki-patform-wiki-rest-default on the Advanced Search.

I’m using a 10.7 version.

Any more information?

Many thanks.

org.xwiki.platform:xwiki-patform-wiki-rest-default version 10.7 is available (see http://maven.xwiki.org/releases/org/xwiki/platform/xwiki-platform-wiki-rest-default/10.7/ ) so you should be able to find it with the Advanced Search from the Extension Manager administration section. Are there any related messages on the server logs when you do the search?