Wiki source code of REST API

Last modified by Thomas Mortagne on 2024/03/12

Show last authors
1 {{box cssClass="floatinginfobox" title="**Contents**"}}
2 {{toc depth="2"/}}
3 {{/box}}
4
5 XWiki provides fine-grain access to virtually every element through an API that is based on HTTP semantics, i.e., a RESTful API. In this page you will find all the details to take advantage of this API and the instructions to use it at its full potential.
6
7 = Accessing the service =
8
9 By defaut the XWiki RESTful API entrypoint is rooted at the following URI:
10
11 {{code}}
12
13 http://host:port/xwiki/rest
14
15 {{/code}}
16
17 All the resource references described in the [[XWiki RESTful API Documentation>>#HXWikiRESTfulAPIDocumentation]] should be intended relative to this URL.
18
19 For example the ##/wikis## resources on a server running on ##localhost## on port ##8080## can be retrieved using the following URL : ##http:~/~/localhost:8080/xwiki/rest/wikis##
20
21 In addition to retrieving content in XML format, you can also retrieve it in JSON format by adding the parameter ##?media=json## in the URL. For example: ##http:~/~/localhost:8080/xwiki/rest/wikis?media=json##
22
23 = Dataset =
24
25 This section contains a brief and high-level description of the XWiki data set that should serve as a basis for presenting resources and their associated operations.
26
27 XWiki has **pages** organized in **spaces**. Each **page** is available in multiple **versions** (its **history**) and **translations**. Translated pages have their own **versions** and **history** which are independent. Each page might have **attachments**. Each attachment has its own **history**. Attachments are shared among all the different translations of a page (i.e., the same set of attachments is the same regardless of the page language). Pages can have one or more **objects**. Objects are instances of a **class** that contains a set of **properties**. Some objects might be directly exposed as first class entities, such as **comments** and **tags**. Objects, as attachments, are shared among all page translations.
28
29 = Understanding resources and representations =
30
31 "An important concept in REST is the existence of resources (sources of specific information), each of which is referenced with a global identifier (e.g., an URI in HTTP). In order to manipulate these resources, components of the network (user agents and origin servers) communicate via a standardized interface (e.g., HTTP) and exchange representations of these resources (the actual documents conveying the information)." ([[Wikipedia>>http://en.wikipedia.org/wiki/Representational_State_Transfer#Central_principle]])
32
33 Resources in XWiki are pages, attachments, objects, properties, spaces, and all the //things// we described in the previous section. XWiki has a default way of conveying the information about these resources, i.e., by providing well defined XML representations that contain all the information associated to the resource in an XML format. This format is described using an [[XML Schema Definition file>>https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwiki-platform-rest/xwiki-platform-rest-model/src/main/resources/xwiki.rest.model.xsd]].
34
35 Of course the same resource can be represented in many different ways. This is yet to be documented.
36
37 Another important aspect of representations is that they contain useful information for linking related resources. This is a realization of the //Hypermedia As The Engine Of The Application State (HATEOAS)// principle. In XML representations this information is conveyed through the ##<link>## tag. This tag has two important parameters: **rel** and **href**. **rel** specifies the "semantics" of the link, while **href** is the URI of the linked resource.
38
39 For example, in the representation of a page, we can have links to the comments, tags, attachments which are independent resources associated to the current page. These links are provided in the XML representation of a page and allow a client to navigate to related resources... Like we do every day when we click on a link in a web page.
40
41 [[image:representation||height="430"]]
42
43 == Relations ==
44
45 The available relations that you might find in the XML resource representations are the following:
46
47 |=Rel|=Semantics
48 |{{{http://www.xwiki.org/rel/wikis}}}|The representation containing the list of virtual wikis.
49 |{{{http://www.xwiki.org/rel/spaces}}}|The representation containing the list of spaces in a wiki.
50 |{{{http://www.xwiki.org/rel/pages}}}|The representation containing the list of pages in a space.
51 |{{{http://www.xwiki.org/rel/translation}}}|The representation containing a translation of a page.
52 |{{{http://www.xwiki.org/rel/page}}}|The representation for a page.
53 |{{{http://www.xwiki.org/rel/space}}}|The representation for a space.
54 |{{{http://www.xwiki.org/rel/parent}}}|The representation for the page that is parent of the current resource.
55 |{{{http://www.xwiki.org/rel/home}}}|The representation for the page that is the home of the current resource.
56 |{{{http://www.xwiki.org/rel/attachmentData}}}|The representation of the actual attachment data.
57 |{{{http://www.xwiki.org/rel/comments}}}|The representation of the list of comments associated to the current resource.
58 |{{{http://www.xwiki.org/rel/attachments}}}|The representation of the list of attachments associated to the current resource.
59 |{{{http://www.xwiki.org/rel/objects}}}|The representation of the list of objects associated to the current resource.
60 |{{{http://www.xwiki.org/rel/object}}}|The representation for an object.
61 |{{{http://www.xwiki.org/rel/classes}}}|The representation of the list of classes associated to the current resource.
62 |{{{http://www.xwiki.org/rel/history}}}|The representation of the list of history information associated to the current resource.
63 |{{{http://www.xwiki.org/rel/class}}}|The representation for a class.
64 |{{{http://www.xwiki.org/rel/property}}}|The representation for a property.
65 |{{{http://www.xwiki.org/rel/propertyValues}}}|The representation for the list of property values.
66 |{{{http://www.xwiki.org/rel/properties}}}|The representation of the list of properties associated to the current resource.
67 |{{{http://www.xwiki.org/rel/modifications}}}|The representation of the list of modifications associated to the current resource.
68 |{{{http://www.xwiki.org/rel/children}}}|The representation of the list of children associated to the current resource.
69 |{{{http://www.xwiki.org/rel/tags}}}|The representation of the list of tags associated to the current resource.
70 |{{{http://www.xwiki.org/rel/tag}}}|The representation of a tag.
71 |{{{http://www.xwiki.org/rel/search}}}|The representation for a search resource.
72 |{{{http://www.xwiki.org/rel/syntaxes}}}|The representation for a syntax resource.
73
74 Relations are defined as URIs in order to provide a sort of namespace. Currently these URIs are not links to real web pages but, in the future, they might point to descriptions of their semantics on actual web pages (or other kinds of representations).
75
76 == The "HATEOAS" Graph ==
77
78 In order to better understand the relations among resources you might have a look at this [[graph>>attach:XWikiHATEOAS.pdf]] that pictures all the resources available in the XWiki RESTful API and the relations among them. In this graph, nodes are [[URI templates>>http://code.google.com/p/uri-templates/]] representing classes of resources. Edges are the possible links that you might find in a representation of a given resource, and their associated relations.
79
80 This graph shows that by starting from the API entry-point a client can navigate and discover all the resources just by following the links provided in representations (and by knowing their semantics). This was exactly the way how this graph was generated.
81
82 = Interacting with the XWiki RESTful API =
83
84 The XWiki RESTful API is accessible through HTTP so, in principle, you can use every client that is capable of "speaking" HTTP in order to interact with it. Even a web browser!
85 If you want to write more complex programs you might download an HTTP library for your favorite language (e.g., [[http://hc.apache.org/]]), see [[this post>>xwiki:Blog.Use the Apache HTTP library to interact with the XWiki RESTful API]] by [[Mohamed Boussaa>>xwiki:XWiki.mouhb]].
86
87 Java users might take advantage of the [[JAXB>>http://jaxb.java.net/]] framework and its [[XJC binding compiler>>http://jaxb.java.net/2.2.4/docs/xjc.html]] in order to generate domain object models directly from the [[XML Schema Definition>>https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwiki-platform-rest/xwiki-platform-rest-model/src/main/resources/xwiki.rest.model.xsd]], and use them for serializing and de-serializing XML representations.
88
89 If you use this approach (Apache HTTP Client + JAXB) you will find yourself writing some code like this:
90
91 {{code language="java"}}
92 import javax.xml.bind.JAXBContext;
93 import javax.xml.bind.Unmarshaller;
94
95 import org.apache.commons.httpclient.HttpClient;
96 import org.apache.commons.httpclient.methods.GetMethod;
97 import org.xwiki.rest.model.jaxb.Page;
98
99 ...
100 HttpClient httpClient = new HttpClient();
101 JAXBContext context = JAXBContext.newInstance("org.xwiki.rest.model.jaxb");
102 Unmarshaller unmarshaller = context.createUnmarshaller();
103
104 GetMethod getMethod = new GetMethod("http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/WebHome");
105 getMethod.addRequestHeader("Accept", "application/xml");
106 httpClient.executeMethod(getMethod);
107
108 Page page = (Page) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
109 {{/code}}
110
111 And you will have all the information about the Main.WebHome page in the Page object, without the need of handling XML directly.
112
113 Because of the wide variety of HTTP frameworks available we don't provide a full tutorial about using them. However, in order to show you how to interact with the XWiki RESTful API, we will use [[curl>>http://curl.haxx.se]]: a standard command line HTTP client that provides an interface to all the functionalities of the HTTP protocol.
114
115 By using curl, the previous example would have been:
116
117 {{code language="xml"}}
118 $ curl http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/WebHome
119
120 <page xmlns="http://www.xwiki.org">
121 <link rel="http://www.xwiki.org/rel/space" href="http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main"/>
122 ...
123 {{/code}}
124
125 == Authentication ==
126
127 The XWiki RESTful API supports several types of authentication:
128
129 * **HTTP BASIC Auth**: You provide your credentials using the Authorization HTTP header
130 * **XWiki session**: If you are logged in XWiki and you use the cookies provided by the authentication mechanism, you will also be authenticated to the XWiki RESTful API. This is useful, for example, when you are interacting with the API using the XMLHttpRequest object of a browser using Javascript.
131 * **Custom authentication methods:** if you have setup a custom authenticator on your wiki (such as [[OIDC>>extensions:Extension.OpenID Connect.WebHome]], or [[Trusted authentication>>extensions:Extension.Trusted authentication framework]] or even your own custom ones), additional authentication methods may be available for the RESTful API, provided by these authenticators.
132
133 If you don't provide any credentials the XWiki RESTful API will recognize you as a XWiki.Guest user.
134
135 So if you have, let's say a Main.PrivatePage, and you try to do:
136
137 {{code language="none"}}
138 $ curl -v http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/PrivatePage
139 ...
140 < HTTP/1.1 401 Unauthorized
141 ...
142 {{/code}}
143
144 You will get an Unauthorized empty response.
145
146 On the contrary, by specifying Admin credentials you gain access to the actual page:
147
148 {{code language="xml"}}
149 $ curl -u Admin:admin http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/PrivatePage
150
151 <page xmlns="http://www.xwiki.org">
152 <link rel="http://www.xwiki.org/rel/space" href="http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main"/>
153 ...
154 <content>Only admin can see this</content>
155 </page>
156 {{/code}}
157
158 === CSRF Token ===
159
160 {{version since="14.10.8,15.2"}}
161 When using a ##POST## request with a content type of ##text/plain##, ##multipart/form-data## or ##application/www-form-urlencoded##, a form token needs to be sent in the header ##XWiki-Form-Token## to prevent cross-site request forgery. The form token is provided in every response in the same header so a ##GET## request to any supported endpoint can be used to obtain a form token. If the form token is missing or wrong, a response with status code 403 and "Invalid or missing form token." as body of type ##text/plain## is sent. As of XWiki 15.2, the form token will stay the same for a user until the server is restarted. As server restarts might happen at any time, API clients should handle this response code and re-try the request with the form token that is returned in the error response. When the form token is provided in a request where it isn't necessary, it won't be checked for validity so it doesn't hurt to just send the token in every request.
162
163 It cannot be excluded that in the future, the form token might depend on the user's session. Therefore, for compatibility with future versions, it might be a good idea to store and send cookies.
164
165 When using the REST API in JavaScript code from within XWiki's UI, the form token is automatically sent in every same-origin request initiated through ##fetch## or ##XMLHttpRequest##. Therefore, no special steps should be needed for REST requests to the current XWiki instance.
166 {{/version}}
167
168 == Sending representations ==
169
170 Many resources are modifiable, so you can send representations in order to change the state of those resources (e.g., pages).
171 All modifiable resources accept XML representations that conform to the [[XML Schema Definition>>https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwiki-platform-rest/xwiki-platform-rest-model/src/main/resources/xwiki.rest.model.xsd]]. However, some other representations might be accepted as well (see the following sections).
172
173 Resource update is usually done by using the PUT method, while resource creation is done via PUT or POST.
174
175 For example, in order to create a page you might do the following:
176
177 {{code language="xml"}}
178 $ curl -u Admin:admin -X PUT --data-binary "@newpage.xml" -H "Content-Type: application/xml" http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/NewPage
179
180 <page xmlns="http://www.xwiki.org">
181 <link rel="http://www.xwiki.org/rel/space" href="http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main"/>
182 ...
183 <version>1.1</version>
184 <majorVersion>1</majorVersion>
185 <minorVersion>1</minorVersion>
186 <created>2009-03-21+01:00</created>
187 <creator>XWiki.Admin</creator>
188 <modified>2009-03-21+01:00</modified>
189 <modifier>XWiki.Admin</modifier>
190 <content>This is a new page</content>
191 </page>
192 {{/code}}
193
194 Where newpage.xml is an XML file containing
195
196 {{code language="xml"}}
197
198 <page xmlns="http://www.xwiki.org">
199 <title>Hello world</title>
200 <syntax>xwiki/2.0</syntax>
201 <content>This is a new page</content>
202 </page>
203 {{/code}}
204
205 The page has been created and is accessible. Subsequent PUT requests to the page URI will modify its content.
206
207 You can specify a subset of the three elements {{{title}}}, {{{syntax}}}, and {{{content}}} in the XML when updating/creating a page.
208 For example, if you just want to change the title, it is sufficient to specify only the {{{title}}} element. The current content and the syntax of the page will be left unchanged.
209
210 == Overcoming browser limitations ==
211
212 As said before, it could be useful to send information by using browser's XmlHttpRequest objects. However, currently many browsers only support GET and POST methods, so it is impossible to send, for example, PUT requests. In order to overcome this limitation you can override the HTTP Method by specifying a ##method## parameter in the URI query string.
213
214 In the previous example, if you send a POST request to the ##http:~/~/localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/NewPage?method=PUT## it will be interpreted as if it were an actual PUT request.
215
216 This overriding mechanism allows the interaction with the XWiki RESTful API by using any kind of browser.
217
218 == PUT vs POST ==
219
220 In the following sections you will see that sometimes resources are created by using PUT and sometimes by using POST. The general principle is that if the client is responsible for choosing the resource URI then PUT is used. If it's the server that bears this responsibility, then POST is used.
221
222 To be clearer, when a client wants to create a page it knows **where** that page should go, so it is able to communicate the server the target URI. PUT is used.
223
224 A client, on the contrary, cannot know beforehand what will be the URI of a comment, since comment URIs contains the ID of the comment and this information is generated by the server. In this case the client will do a POST and the server, in response, will communicate the URI it generated for the newly created comment.
225
226 == Headers ==
227
228 The response of the REST requests always contain some custom headers that might be useful:
229
230 * ##xwiki-version##: contains the representation of the version of XWiki defined in ##version.properties## (e.g. 14.4.6)
231 * ##xwiki-user##: contains the reference of the user used to perform the request (e.g. xwiki:XWiki.JohnDoe). If the request is performed as guest, the header won't be present.
232
233 = XWiki RESTful API Documentation =
234
235 In this section you will find the documentation of the whole XWiki RESTful API.
236
237 **application/xml** representations refers to the [[XML Schema Definition>>https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwiki-platform-rest/xwiki-platform-rest-model/src/main/resources/xwiki.rest.model.xsd]].
238
239 Resource URIs are specified using [[URI templates>>http://code.google.com/p/uri-templates/]]. Bracketed elements are formal parameters and should be instantiated to actual values in order to retrieve the associated resource.
240
241 == Root resources ==
242
243 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)
244
245 === / ===
246
247 * **HTTP Method:** GET
248 ** **Media types:**
249 *** application/xml (XWiki element)
250 ** **Description:** Retrieves the entry root description containing information about the server (currently returns the XWiki product Version).
251 ** **Status codes:**
252 *** 200: If the request was successful.
253
254 === /syntaxes ===
255
256 * **HTTP Method:** GET
257 ** **Media types:**
258 *** application/xml (Syntaxes element)
259 ** **Description:** The list of syntaxes supported by the XWiki instance.
260 ** **Status codes:**
261 *** 200: If the request was successful.
262
263 === /wikis ===
264
265 * **HTTP Method:** GET
266 ** **Media types:**
267 *** application/xml (Wikis element)
268 ** **Description:** The list of wikis available on the XWiki instance. Unless the wiki is configured to be a wiki farm, this list is usually made of a single element 'xwiki'.
269 ** **Status codes:**
270 *** 200: If the request was successful.
271
272 === /wikis/query?q~={query}&wikis~=wikiList[&distinct~={true,false}][&order~={asc,desc}][&start~=n][&number~=n][&prettyNames~={true,false}] ===
273
274 * **HTTP Method:** GET
275 ** **Media types:**
276 *** application/xml (SearchResults element)
277 ** **Description:** Search resources (pages and attachments):
278 *** [since 6.4] using a SOLR query (handled by the [[SOLR Query module>>extensions:Extension.Solr Search Query API]]) on the wikis that are specified as a comma separated list in the //wikis// parameter.
279 *** [before 6.4] using a Lucene query (handled by the [[Lucene Plugin>>extensions:Extension.Lucene Plugin]]) on the wikis that are specified as a comma separated list in the //wikis// parameter.
280 ** **Status codes:**
281 *** 200: If the request was successful.
282
283 === /wikis/{wikiName} ===
284
285 * **HTTP Method:** GET
286 ** **Media types:**
287 *** application/xml (Wiki element)
288 ** **Description:** information about the wiki
289 ** **Status codes:**
290 *** 200: If the request was successful.
291
292 * **HTTP Method:** POST
293 ** **Accepted Media types:**
294 *** octet/stream (A XAR file)
295 ** **Media types:**
296 *** application/xml (Wiki element)
297 ** **Query parameters**
298 *** backup={true/false} - import XAR as a backup XAR
299 *** history={RESET/REPLACE/ADD} - history importing
300 ** **Description:** import a XAR in a wiki.
301 ** **Status codes:**
302 *** 200: If the request was successful.
303
304 === /wikis/{wikiName}/search?q~={keywords}~[~[&scope~={name,content,title,objects}...]&start~=n][&number~=n][&orderField~=field&order~={asc,desc}][distinct~={true,false}][&prettyNames~={true,false}] ===
305
306 * **HTTP Method:** GET
307 ** **Media types:**
308 *** application/xml (SearchResults element)
309 ** **Description:** Returns the list of pages and objects that contain the {keywords} in the specified {scope}s. Multiple scopes can be specified. Search results are relative to the whole {wikiName} and are obtained via a HQL query.
310 ** **Status codes:**
311 *** 200: If the request was successful.
312
313 === /wikis/{wikiName}/query?q~={query}&type~={hql,xwql,lucene,solr}[&distinct~={true,false}]~~[&order~={asc,desc}][&start~=n][&number~=n][&prettyNames~={true,false}][&className~=className] ===
314
315 * **HTTP Method:** GET
316 ** **Media types:**
317 *** application/xml (SearchResults element)
318 ** **Description:** Allow to execute HQL, XWQL, Lucene or SOLR queries on the given {wikiName}. The //q// parameter contains the corresponding query. See [[HQL Query Examples in Velocity>>Documentation.DevGuide.Scripting.velocityHqlExamples]], [[XWiki Query Language Specification>>dev:Design.XWiki Query Language Specification]], [[Lucene Plugin>>extensions:Extension.Lucene Plugin]] and [[SOLR query API>>extensions:Extension.Solr Search Query API]] examples of the queries that can be specified in this parameter. If type is //hql// or //xwql// and //className// is specified, the result will also contain the data for the first object of the corresponding class.
319 ** **Status codes:**
320 *** 200: If the request was successful.
321
322 === /wikimanager (This resource is only available when using the [[multi-wiki>>extensions:Extension.Wiki Application]] feature) ===
323
324 * **HTTP Method:** POST
325 ** **Accepted Media types:**
326 *** application/xml (Wiki element)
327 ** **Media types:**
328 *** application/xml (Wiki element)
329 ** **Query parameters**
330 *** template - the wiki template to be used for initializing the wiki.
331 *** history={RESET/REPLACE/ADD} - history importing
332 ** **Description:** create a new wiki.
333 ** **Status codes:**
334 *** 200: If the request was successful.
335
336 == Space resources ==
337
338 === /wikis/{wikiName}/spaces[?start~=offset&number~=n] ===
339
340 * **HTTP Method:** GET
341 ** **Media types:**
342 *** application/xml (Spaces element)
343 ** **Description:** Retrieves the list of spaces available in the {wikiName} wiki.
344 ** **Status codes:**
345 *** 200: If the request was successful.
346
347 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/search?q~={keywords}~[~[&scope~={name,content,title,objects}...]&number~=n] ===
348
349 * **HTTP Method:** GET
350 ** **Media types:**
351 *** application/xml (Search results element)
352 ** **Description:** The list of pages and objects that contain the {keywords} in the specified {scope}s. Multiple scopes can be specified. Search results are relative to space {spaceName}
353 ** **Status codes:**
354 *** 200: If the request was successful.
355 *** 401: If the user is not authorized.
356
357 == Page resources ==
358
359 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages[?start~=offset&number~=n] ===
360
361 * **HTTP Method:** GET
362 ** **Media types:**
363 *** application/xml (Pages element)
364 ** **Description:** The list of pages in the space {spaceName}
365 ** **Status codes:**
366 *** 200: If the request was successful.
367 *** 401: If the user is not authorized.
368
369 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}[?prettyNames~={true,false}&objects~={true,false}&class~={true,false}&attachments~={true,false}&minorRevision~={true,false}] ===
370
371 * **HTTP Method:** GET
372 ** **Media types:**
373 *** application/xml (Page element)
374 ** **Query parameters**
375 *** ##prettyNames##: also return the pretty name for various document information (like the author display name, etc). Disabled by default.
376 *** ##objects##: //[since 7.3M1]// also return the objects. Disabled by default.
377 *** ##class##: //[since 7.3M1]// also return the class. Disabled by default.
378 *** ##attachments##: //[since 7.3M1]// also return the attachments metadatas. Disabled by default.
379 ** **Description:**
380 ** **Status codes:**
381 *** 200: If the request was successful.
382 *** 401: If the user is not authorized.
383
384 * **HTTP Method:** PUT
385 ** **Accepted Media types:**
386 *** application/xml (Page element)
387 *** text/plain (Only page content)
388 *** application/x-www-form-urlencoded (allowed field names: title, parent, hidden //[since 7.3]//, content)
389 ** **Media types:**
390 *** application/xml (Page element)
391 ** **Query parameters**
392 *** ##minorRevision## ({{info}}Since 9.11.4 & 10.2RC1{{/info}}): Create a minor revision for the page. Disabled by default.
393 ** **Description:** Create or updates a page.
394 ** **Status codes:**
395 *** 201: If the page was created.
396 *** 202: If the page was updated.
397 *** 304: If the page was not modified.
398 *** 401: If the user is not authorized.
399
400 * **HTTP Method:** DELETE
401 ** **Media types:**
402 *** application/xml (Page element)
403 ** **Description:** Delete the page.
404 ** **Status codes:**
405 *** 204: If the request was successful.
406 *** 401: If the user is not authorized.
407
408 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/history[?start~=offset&number~=n] ===
409
410 * **HTTP Method:** GET
411 ** **Media types:**
412 *** application/xml (History element)
413 ** **Description:** The list of all the versions of the given page.
414 ** **Status codes:**
415 *** 200: If the request was successful.
416 *** 401: If the user is not authorized.
417
418 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/history/{version} ===
419
420 * **HTTP Method:** GET
421 ** **Media types:**
422 *** application/xml (Page element)
423 ** **Description:** The page at version {version}
424 ** **Status codes:**
425 *** 200: If the request was successful.
426 *** 401: If the user is not authorized.
427
428 ==== /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/translations[?start~=offset&number~=n] ====
429
430 * **HTTP Method:** GET
431 ** **Media types:**
432 *** application/xml (Translations element)
433 ** **Description:** The list of available translation for the page
434 ** **Status codes:**
435 *** 200: If the request was successful.
436 *** 401: If the user is not authorized.
437
438 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/translations/{language}[?minorRevision~={true,false}] ===
439
440 * **HTTP Method:** GET
441 ** **Media types:**
442 *** application/xml (Page element)
443 ** **Description:** The page at in the given {language}.
444 ** **Status codes:**
445 *** 200: If the request was successful.
446 *** 401: If the user is not authorized.
447
448 * **HTTP Method:** PUT
449 ** **Accepted Media types:**
450 *** application/xml (Page element)
451 *** text/plain (Only page content)
452 *** application/x-www-form-urlencoded (allowed field names: title, parent, content)
453 ** **Media types:**
454 *** application/xml (Page element)
455 ** **Query parameters**
456 *** ##minorRevision## ({{info}}Since 9.11.4 & 10.2RC1{{/info}}): Create a minor revision for the page. Disabled by default.
457 ** **Description:** Create or updates a page translation.
458 ** **Status codes:**
459 *** 201: If the page was created.
460 *** 202: If the page was updated.
461 *** 304: If the page was not modified.
462 *** 401: If the user is not authorized.
463
464 * **HTTP Method:** DELETE
465 ** **Media types:**
466 *** application/xml (Page element)
467 ** **Description:** Delete the page translation.
468 ** **Status codes:**
469 *** 204: If the request was successful.
470 *** 401: If the user is not authorized.
471
472 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/translations/{language}/history ===
473
474 * **HTTP Method:** GET
475 ** **Media types:**
476 *** application/xml (History element)
477 ** **Description:** The list of all the available revisions of the page in a given {language}.
478 ** **Status codes:**
479 *** 200: If the request was successful.
480 *** 401: If the user is not authorized.
481
482 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/translations/{lang}/history/{version} ===
483
484 * **HTTP Method:** GET
485 ** **Media types:**
486 *** application/xml (Page element)
487 ** **Description:** A page at a given {version} in a given {language}.
488 ** **Status codes:**
489 *** 200: If the request was successful.
490 *** 401: If the user is not authorized.
491
492 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/children ===
493
494 * **HTTP Method:** GET
495 ** **Media types:**
496 *** application/xml (Pages element)
497 ** **Description:** The list of the children of a given page.
498 ** **Status codes:**
499 *** 200: If the request was successful.
500 *** 401: If the user is not authorized.
501
502 === /wikis/{wikiName}/pages[?name~=paneName&space~=spaceName&author~=authorName] ===
503
504 * **HTTP Method:** GET
505 ** **Media types:**
506 *** application/xml (Pages element)
507 ** **Description:** The list of pages in the wiki {wikiName}. Filters can be set for the name, space and/or author to include only pages that match the given filters. This resource can be used to search for pages in a wiki.
508 ** **Status codes:**
509 *** 200: If the request was successful.
510 *** 401: If the user is not authorized.
511
512 == Tag resources ==
513
514 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/tags[?minorRevision~={true,false}] ===
515
516 * **HTTP Method:** GET
517 ** **Media types:**
518 *** application/xml (Tags element)
519 ** **Description:** List page tags.
520 ** **Status codes:**
521 *** 200: If the request was successful.
522 *** 401: If the user is not authorized.
523
524 * **HTTP Method:** PUT
525 ** **Accepted Media types:**
526 *** application/xml (Tag element)
527 *** text/plain
528 *** application/x-www-form-urlencoded (allowed field names: tag)
529 ** **Media types:**
530 *** application/xml (Tags element)
531 ** **Query parameters**
532 *** ##minorRevision## ({{info}}Since 9.11.4 & 10.2RC1{{/info}}): Create a minor revision for the page. Disabled by default.
533 ** **Description:** Add a tag to the page.
534 ** **Status codes:**
535 *** 202: If the request was successful.
536 *** 401: If the user is not authorized.
537
538 === /wikis/{wikiName}/tags ===
539
540 * **HTTP Method:** GET
541 ** **Media types:**
542 *** application/xml (Tags element)
543 ** **Description:** The list of all available tags
544 ** **Status codes:**
545 *** 200: If the request was successful.
546 *** 401: If the user is not authorized.
547
548 === /wikis/{wikiName}/tags/{tag1}[,{tag2},{tag3}...][?start~=offset&number~=n] ===
549
550 * **HTTP Method:** GET
551 ** **Media types:**
552 *** application/xml (Pages element)
553 ** **Description:** The list of pages having the specified tags.
554 ** **Status codes:**
555 *** 200: If the request was successful.
556 *** 401: If the user is not authorized.
557
558 == Comments resources ==
559
560 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/comments[?start~=offset&number~=n] ===
561
562 * **HTTP Method:** GET
563 ** **Media types:**
564 *** application/xml (Comments element)
565 ** **Description:** The list of comments on a given page.
566 ** **Status codes:**
567 *** 200: If the request was successful.
568 *** 401: If the user is not authorized.
569
570 * **HTTP Method:** POST
571 ** **Accepted Media types:**
572 *** application/xml (Comment element)
573 *** text/plain
574 *** application/x-www-form-urlencoded - allowed field names: ##text##, ##replyTo## (object number of the replied comment, since XE 2.3)
575 ** **Media types:**
576 *** application/xml (Comment element)
577 ** **Description:** Create a comment on the given page.
578 ** **Status codes:**
579 *** 201: If the comment was created. (The Location header will contain the URI where the comment has been created.)
580 *** 401: If the user is not authorized.
581
582 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/comments/{commentId} ===
583
584 * **HTTP Method:** GET
585 ** **Media types:**
586 *** application/xml (Comment element)
587 ** **Description:** A specific comment on a page
588 ** **Status codes:**
589 *** 200: If the request was successful.
590 *** 401: If the user is not authorized.
591
592 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/history/{version}/comments ===
593
594 * **HTTP Method:** GET
595 ** **Media types:**
596 *** application/xml (Comments element)
597 ** **Description:** The list of comments at a specific page {version}.
598 ** **Status codes:**
599 *** 200: If the request was successful.
600 *** 401: If the user is not authorized.
601
602 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/history/{version}/comments/{commentId} ===
603
604 * **HTTP Method:** GET
605 ** **Media types:**
606 *** application/xml (Comment element)
607 ** **Description:** A comment at a specific page {version}.
608 ** **Status codes:**
609 *** 200: If the request was successful.
610 *** 401: If the user is not authorized.
611
612 == Attachments resources ==
613
614 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/attachments[?start~=offset&number~=n] ===
615
616 * **HTTP Method:** GET
617 ** **Media types:**
618 *** application/xml (Attachments element)
619 ** **Description:** The list of attachments of a given page.
620 ** **Status codes:**
621 *** 200: If the request was successful.
622 *** 401: If the user is not authorized.
623
624 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/attachments/{attachmentName} ===
625
626 * **HTTP Method:** GET
627 ** **Media types:**
628 *** The same of the attachment media type.
629 ** **Description:** The attachment identified by {attachmentName} on a given page.
630 ** **Status codes:**
631 *** 200: If the request was successful.
632 *** 401: If the user is not authorized.
633
634 * **HTTP Method:** PUT
635 ** **Accepted media types:**
636 *** **/**
637 ** **Media types:**
638 *** application/xml (AttachmentSummary element)
639 ** **Description:** Create an attachment identified by {attachmentName} on a given page.
640 ** **Status codes:**
641 *** 201: If the attachment was created.
642 *** 202: If the attachment was updated.
643 *** 401: If the user is not authorized.
644
645 * **HTTP Method:** DELETE
646 ** **Media types:**
647 ** **Description:** Delete the attachment identified by {attachmentName} on a given page.
648 ** **Status codes:**
649 *** 204: If the attachment was deleted.
650 *** 401: If the user is not authorized.
651
652 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/history/{version}/attachments[?start~=offset&number~=n] ===
653
654 * **HTTP Method:** GET
655 ** **Media types:**
656 *** application/xml (Attachments element)
657 ** **Description:** The list of attachments at a given page {version}.
658 ** **Status codes:**
659 *** 200: If the request was successful.
660 *** 401: If the user is not authorized.
661
662 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/history/{version}/attachments/{attachmentName} ===
663
664 * **HTTP Method:** GET
665 ** **Media types:**
666 *** The same of the attachment media type.
667 ** **Description:** The attachment identified by {attachmentName} on a given page {version}.
668 ** **Status codes:**
669 *** 200: If the request was successful.
670 *** 401: If the user is not authorized.
671
672 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/attachments/{attachmentName}/history ===
673
674 * **HTTP Method:** GET
675 ** **Media types:**
676 *** application/xml (Attachments element)
677 ** **Description:** The list of available version for the {attachmentName}
678 ** **Status codes:**
679 *** 200: If the request was successful.
680 *** 401: If the user is not authorized.
681
682 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/attachments/{attachmentName}/history/{version} ===
683
684 * **HTTP Method:** GET
685 ** **Media types:**
686 *** The same of the attachment media type.
687 ** **Description:** The {attachmentName} at a given {version}
688 ** **Status codes:**
689 *** 200: If the request was successful.
690 *** 401: If the user is not authorized.
691
692 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/attachments[?name~=attachmentName&page~=pageName&author~=authorName&types~=attachmentTypeList&start~=offset&number~=n] ===
693
694 * **HTTP Method:** GET
695 ** **Media types:**
696 *** application/xml (Attachments element)
697 ** **Description:** The list of attachments of pages located in a given {spaceName}. Filters can be set for the name, page, author and/or types (comma separated list of strings) to include only attachments that match the given filters. This resource can be used to search for attachments in a space.
698 ** **Status codes:**
699 *** 200: If the request was successful.
700 *** 401: If the user is not authorized.
701
702 === /wikis/{wikiName}/attachments[?name~=attachmentName&page~=pageName&space~=spaceName&author~=authorName&types~=attachmentTypeList&start~=offset&number~=n] ===
703
704 * **HTTP Method:** GET
705 ** **Media types:**
706 *** application/xml (Attachments element)
707 ** **Description:** The list of attachments in a given {wikiName}. Filters can be set for the name, page, space, author and/or type (comma separated list of strings) to include only attachments that match the given filters. This resource can be used to search for attachments in a wiki.
708 ** **Status codes:**
709 *** 200: If the request was successful.
710 *** 401: If the user is not authorized.
711
712 == Object resources ==
713
714 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/objects[?start~=offset&number~=n] ===
715
716 * **HTTP Method:** GET
717 ** **Media types:**
718 *** application/xml (Objects element)
719 ** **Description:** The list of objects associated to a page.
720 ** **Status codes:**
721 *** 200: If the request was successful.
722 *** 401: If the user is not authorized.
723
724 * **HTTP Method:** POST
725 ** **Accepted media types:**
726 *** application/xml (Object element)
727 *** application/x-www-form-urlencoded (a set of property#name=value pairs representing properties and a field className)
728 **** e.g. {{code language="none"}}className=XWiki.XWikiUsers&property#first_name=John&property#last_name=Doe{{/code}}
729 ** **Media types:**
730 *** application/xml (Object element)
731 ** **Description:** Create a new object.
732 ** **Status codes:**
733 *** 201: If the object was created (The Location header will contain the URI associated to the newly created object).
734 *** 401: If the user is not authorized.
735
736 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/objects/{className}[?start~=offset&number~=n] ===
737
738 * **HTTP Method:** GET
739 ** **Media types:**
740 *** application/xml (Objects element)
741 ** **Description:** The list of objects of a given {className} associated to a page.
742 ** **Status codes:**
743 *** 200: If the request was successful.
744 *** 401: If the user is not authorized.
745
746 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/objects/{className}/{objectNumber}[?minorRevision~={true,false}] ===
747
748 * **HTTP Method:** GET
749 ** **Media types:**
750 *** application/xml (Object element)
751 ** **Description:** The object of type {className} identified by {objectNumber} associated to the given page.
752 ** **Status codes:**
753 *** 200: If the request was successful.
754 *** 401: If the user is not authorized.
755
756 * **HTTP Method:** PUT
757 ** **Accepted media types:**
758 *** application/xml (Object element)
759 *** application/x-www-form-urlencoded (a set of property#name=value pairs representing properties)
760 ** **Media types:**
761 *** application/xml (Object element)
762 ** **Query parameters**
763 *** ##minorRevision## ({{info}}Since 9.11.4 & 10.2RC1{{/info}}): Create a minor revision for the page. Disabled by default.
764 ** **Description:** Modify the object properties.
765 ** **Status codes:**
766 *** 202: If the object was updated.
767 *** 401: If the user is not authorized.
768
769 * **HTTP Method:** DELETE
770 ** **Media types:**
771 ** **Description:** Delete the object.
772 ** **Status codes:**
773 *** 204: If the object was deleted.
774 *** 401: If the user is not authorized.
775
776 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/objects/{className}/{objectNumber}/properties ===
777
778 * **HTTP Method:** GET
779 ** **Media types:**
780 *** application/xml (Properties element)
781 ** **Description:** The properties of the object of type {className} identified by {objectNumber} associated to the given page.
782 ** **Status codes:**
783 *** 200: If the request was successful.
784 *** 401: If the user is not authorized.
785
786 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/objects/{className}/{objectNumber}/properties/{propertyName}[?minorRevision~={true,false}] ===
787
788 * **HTTP Method:** GET
789 ** **Media types:**
790 *** application/xml (Properties element)
791 ** **Description:** The property {propertyname} of the object of type {className} identified by {objectNumber} associated to the given page.
792 ** **Status codes:**
793 *** 200: If the request was successful.
794 *** 401: If the user is not authorized.
795
796 * **HTTP Method:** PUT
797 ** **Accepted media types:**
798 *** application/xml (Property element)
799 *** text/plain
800 *** application/x-www-form-urlencoded (a field property#name=value pairs representing a property)
801 ** **Media types:**
802 *** application/xml (Property element)
803 ** **Query parameters**
804 *** ##minorRevision## ({{info}}Since 9.11.4 & 10.2RC1{{/info}}): Create a minor revision for the page. Disabled by default.
805 ** **Description:** Modify the object properties.
806 ** **Status codes:**
807 *** 202: If the object was updated.
808 *** 401: If the user is not authorized.
809
810 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/history/{version}/objects[?start~=offset&number~=n] ===
811
812 * **HTTP Method:** GET
813 ** **Media types:**
814 *** application/xml (Objects element)
815 ** **Description:** The list of objects associated to a page at a given {version}.
816 ** **Status codes:**
817 *** 200: If the request was successful.
818 *** 401: If the user is not authorized.
819
820 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/history/{version}/objects/{className}/{objectNumber} ===
821
822 * **HTTP Method:** GET
823 ** **Media types:**
824 *** application/xml (Object element)
825 ** **Description:** The object of type {className} identified by {objectNumber} associated to the given page at a given {version}.
826 ** **Status codes:**
827 *** 200: If the request was successful.
828 *** 401: If the user is not authorized.
829
830 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/history/{version}/objects/{className}/{objectNumber}/properties ===
831
832 * **HTTP Method:** GET
833 ** **Media types:**
834 *** application/xml (Properties element)
835 ** **Description:** The properties of the object of type {className} identified by {objectNumber} associated to the given page at a given {version}.
836 ** **Status codes:**
837 *** 200: If the request was successful.
838 *** 401: If the user is not authorized.
839
840 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/history/{version}/objects/{className}/{objectNumber}/properties/{propertyName} ===
841
842 * **HTTP Method:** GET
843 ** **Media types:**
844 *** application/xml (Properties element)
845 ** **Description:** The property {propertyName} of the object of type {className} identified by {objectNumber} associated to the given page at a given {version}.
846 ** **Status codes:**
847 *** 200: If the request was successful.
848 *** 401: If the user is not authorized.
849
850 === /wikis/{wikiName}/classes/{className}/objects[?start~=offset&number~=n] ===
851
852 * **HTTP Method:** GET
853 ** **Media types:**
854 *** application/xml (Objects element)
855 ** **Description:** The list of all the objects of a given {className}.
856 ** **Status codes:**
857 *** 200: If the request was successful.
858 *** 401: If the user is not authorized.
859
860 == Class resources ==
861
862 === /wikis/{wikiName}/classes[?start~=offset&number~=n] ===
863
864 * **HTTP Method:** GET
865 ** **Media types:**
866 *** application/xml (Classes element)
867 ** **Description:** The list of all the classes defined in the wiki {wikiName}
868 ** **Status codes:**
869 *** 200: If the request was successful.
870 *** 401: If the user is not authorized.
871
872 === /wikis/{wikiName}/classes/{className} ===
873
874 * **HTTP Method:** GET
875 ** **Media types:**
876 *** application/xml (Class element)
877 ** **Description:** The {className} definition
878 ** **Status codes:**
879 *** 200: If the request was successful.
880 *** 401: If the user is not authorized.
881
882 === /wikis/{wikiName}/classes/{className}/properties ===
883
884 * **HTTP Method:** GET
885 ** **Media types:**
886 *** application/xml (Properties element)
887 ** **Description:** The properties of the class {className}.
888 ** **Status codes:**
889 *** 200: If the request was successful.
890 *** 401: If the user is not authorized.
891
892 === /wikis/{wikiName}/classes/{className}/properties/{propertyName} ===
893
894 * **HTTP Method:** GET
895 ** **Media types:**
896 *** application/xml (Property element)
897 ** **Description:** The property {propertyName} of the class {className}.
898 ** **Status codes:**
899 *** 200: If the request was successful.
900 *** 401: If the user is not authorized.
901
902 === /wikis/{wikiName}/classes/{className}/properties/{propertyName}/values {{info}}Since 9.8RC1{{/info}} ===
903
904 Request parameters:
905
906 |=Name|=Description|
907 |limit|Limit the number of values returned. Zero or a negative number means no limit.
908 |fp|Filter parameters, used to filter the returned values. You can pass multiple filter values by repeating the query string parameter. The way in which the property values are filtered depends on the property type.
909
910 * **HTTP Method:** GET
911 ** **Media types:**
912 *** application/xml (Property element)
913 ** **Description:** The list of values for the property {propertyName} of the class {className}. At the moment only Database List properties are supported.
914 ** **Status codes:**
915 *** 200: If the request was successful.
916 *** 401: If the user is not authorized to view the specified property.
917 *** 404: If the specified property doesn't exist.
918
919 == Job resources ==
920
921 A job is identified by an ID (##jobId##) which is a list of strings. In the REST URL, you have to represent the ID with a list of strings separated by ##/##. (eg: ##refactoring/delete/11451##).
922
923 === /jobstatus/{jobId} {{info}}Since 7.2M3{{/info}} ===
924
925 Request parameters:
926
927 |=Name|=Required|=Values|=Default|=Description|=Version
928 |##request##|no|##true~|false##|##false##|Return also the job request|9.1RC1
929 |##progress##|no|##true~|false##|##true##|Return also the job progress|9.1RC1
930 |##log##|no|##true~|false##|##false##|Return also the job log|9.1RC1
931 |##log_fromLevel##|no|##error~|warn~|info~|debug~|trace##| |Indicate the level from which to return logs|9.1RC1
932
933 * **HTTP Method:** GET
934 ** **Media types:**
935 *** application/xml (JobStatus element)
936 ** **Description:** status of a job
937 ** **Status codes:**
938 *** 200: If the request was successful.
939 *** 404: If the job status has not been found
940
941 === /joblog/{jobId} {{info}}Since 7.2M3{{/info}} ===
942
943 Request parameters:
944
945 |=Name|=Required|=Values|=Default|=Description|=Version
946 |##level##|no|##error~|warn~|info~|debug~|trace##| |Indicate the exact level for which to return logs|7.2M3
947 |##fromLevel##|no|##error~|warn~|info~|debug~|trace##| |Indicate the level from which to return logs|7.2M3
948
949 * **HTTP Method:** GET
950 ** **Media types:**
951 *** application/xml (JobLog element)
952 ** **Description:** log of a job
953 ** **Status codes:**
954 *** 200: If the request was successful.
955 *** 404: If the job status has not been found
956
957 === /jobs {{info}}Since 9.1RC1{{/info}} ===
958
959 Request parameters:
960
961 |=Name|=Required|=Values|=Default|=Description|=Version
962 |##jobType##|yes| | |The type of the job to pass to the Job Executor|9.1RC1
963 |##async##|no|##true~|false##|##true##|If false, return the response only when the job is done|9.1RC1
964
965 This API is designed to be a REST clone of the JobExecutor Java API (the only real difference right now being way to deal with asynchronous jobs) documented on http://extensions.xwiki.org/xwiki/bin/view/Extension/Job+Module#HUseanexistingjob so the concepts (job type, job request) are the same and the exact information to put in the job request depends on the job you want to run and are usually documented in the extension this job is coming from (extension module, refactoring, etc.).
966
967 * **HTTP Method:** PUT
968 ** **Input:**
969 *** Media Types: ##application/xml## or ##application/json##
970 *** Input body: ##JobRequest## element
971 ** **Output:**
972 *** Media Types: ##application/xml## or ##application/json##
973 *** Response body: ##JobStatus## element
974 ** **Description:** Start a new job synchronously or asynchronously
975 ** **Status codes:**
976 *** 200: If the job was successfully executed
977 *** 401: If the user is not authorized (i.e. doesn't have Programming Rights)
978 *** 500: Failing jobs with ##async=false## return an error 500 (Since 9.7RC1)
979
980 Jobs started through the REST API automatically get their runtime context injected with the following REST HTTP request context properties:
981
982 * current wiki
983 * current user
984 * request URL and parameters
985
986 There is JAXB objects provided to make easy to create a request for Java and other JVM based clients. For other use cases the hard part is generally generating the XML to send as content and you can either:
987
988 * ask for the status of an existing job to have an hint of how the XML/JSON should look like (see [[jobstatus section>>#H2Fjobstatus2F7BjobId7D]])
989 * generate this XML in a script in a wiki page, you can look at the following example to help with that: https://snippets.xwiki.org/xwiki/bin/view/Extension/Generate%20Refactoring%20Job%20REST%20request%20XML/
990
991 === Example of Extension Manager installJob ===
992
993 Using the attach:installjobrequest.xml file you can use a request like the following one to ask for the installation of an extension (in this example the XWiki OIDC module version 1.28):
994
995 {{code language="none"}}
996 curl -i --user "Admin:admin" -X PUT -H "Content-Type: text/xml" "http://localhost:8080/xwiki/rest/jobs?jobType=install&async=false" --upload-file installjobrequest.xml
997 {{/code}}
998
999 == Localization resources ==
1000
1001 For more details see the [[Localization Module documentation>>extensions:Extension.Localization.WebHome]].
1002
1003 {{version since="13.3RC1"}}
1004 === /wikis/{wikiName}/localization/translations[?locale~=l&prefix~=p[&key~=k]*] ===
1005
1006 * **HTTP Method**: GET
1007 ** **Media Types:** ##application/xml## or ##application/json##
1008 ** **Description: **The list of translations of the requested keys in a given locale
1009 ** **Query Parameters:**
1010 *** **locale:** (optional) the locale of the returned translation, if missing the locale is resolved from the context
1011 *** **prefix:** (optional) a common prefix concatenated to all the provided keys.
1012 *** **key:** (multiple) a list of translation keys
1013 ** **Status Code:**
1014 *** 200: if the request was successful
1015 ** **Response:**
1016 *** a list of translation objects, each containing the translation key (concatenated with the prefix) and the resolved raw sources (the translation values without the parameters resolved).
1017 {{/version}}
1018
1019 == Icon Theme resources ==
1020
1021 For more details see the [[extensions:Extension.Icon Theme Application.WebHome]].
1022
1023 {{version since="13.3RC1"}}
1024 === /wikis/{wikiName}/iconThemes/icons[?[name~=n]*] ===
1025
1026 * **HTTP Method**: GET
1027 ** **Media Types:** ##application/xml## or ##application/json##
1028 ** **Description: **Provides the metadata of the icons of the current icon theme in a given ##{wikiName}## wiki
1029 ** **Query Parameters:**
1030 *** **name:** (multiple) the name of the requested icons
1031 ** **Status Code:**
1032 *** 200: if the request was successful
1033 ** **Response:**
1034 *** An object with two attributes: ##icon## is a list of the requested icons metadata, and ##missingIcons## an array of names of requested icons that couldn't be found in the current theme.
1035
1036
1037 === /wikis/{wikiName}/iconThemes/{iconTheme}/icons[?[name~=n]*] ===
1038
1039 * **HTTP Method**: GET
1040 ** **Media Types:** ##application/xml## or ##application/json##
1041 ** **Description: **Provides the metadata of the icons of the ##{iconTheme}## icon theme in a given ##{wikiName}## wiki
1042 ** **Query Parameters:**
1043 *** **name:** (multiple) the name of the requested icons
1044 ** **Status Code:**
1045 *** 200: if the request was successful
1046 ** **Response:**
1047 *** An object with two attributes: ##icon## is a list of the requested icons metadata, and ##missingIcons## an array of names of requested icons that couldn't be found in the requested theme.
1048 {{/version}}
1049
1050 == Other resources ==
1051
1052 === /wikis/{wikiName}/modifications[?start~=offset&number~=n&date~=t] ===
1053
1054 * **HTTP Method:** GET
1055 ** **Media types:**
1056 *** application/xml (Modifications element)
1057 ** **Description:** The list of the latest modification made to the wiki {wikiName} starting from time t (t is expressed in milliseconds from 1970 of the starting date)
1058 ** **Status codes:**
1059 *** 200: If the request was successful.
1060 *** 401: If the user is not authorized.
1061
1062 = Custom resources =
1063
1064 == In Wiki Pages ==
1065
1066 If you can't find an existing REST endpoint for your needs, you can create your own own by creating a wiki page and putting script in it. For example let's imagine you'd like to get a list of all pages under a given space. You could write a page, say ##GetChildren## with the following content:
1067
1068 {{code language="velocity"}}
1069 {{velocity}}
1070 #if ("$!request.space" != '')
1071 #set ($discard = $response.setContentType('text/xml'))
1072
1073 <pages>
1074 #set ($query = $services.query.xwql("select doc.fullName from Document doc where ((doc.space like :spacelike escape '!') or (doc.space = :space)) and language='' order by doc.date desc"))
1075 #set ($spaceReferenceString = $request.space)
1076 #set ($spaceLike = $spaceReferenceString.replaceAll('([%_!])', '!$1').concat('.%'))
1077 #set ($query = $query.bindValue('spacelike', $spaceLike))
1078 #set ($query = $query.bindValue('space', $spaceReferenceString))
1079 #foreach ($item in $query.execute())
1080 <page>$item</page>
1081 #end
1082 </pages>
1083 #end
1084 {{/velocity}}
1085 {{/code}}
1086
1087 The calling it for example with the following URL ##http:~/~/localhost:8080/xwiki/bin/get/GetChildren/?space=Sandbox&xpage=plain&outputSyntax=plain## would give something like:
1088
1089 {{code language="none"}}
1090 <pages>
1091 <page>Sandbox.Test.WebHome</page>
1092 <page>Sandbox.TestPage2</page>
1093 <page>Sandbox.ApplicationsPanelEntry</page>
1094 <page>Sandbox.TestPage3</page>
1095 <page>Sandbox.TestPage1</page>
1096 <page>Sandbox.WebPreferences</page>
1097 <page>Sandbox.WebHome</page>
1098 </pages>
1099 {{/code}}
1100
1101 == In Java ==
1102
1103 It's possible to easily add any REST resource by registering a ##org.xwiki.rest.XWikiResource## java component on your wiki (see [[Component guide>>Documentation.DevGuide.Tutorials.WritingComponents]] for more details).
1104
1105 {{code language="java"}}
1106 package org.xwiki.contrib.rest;
1107
1108 import javax.ws.rs.DefaultValue;
1109 import javax.ws.rs.GET;
1110 import javax.ws.rs.Path;
1111
1112 import org.xwiki.component.annotation.Component;
1113 import org.xwiki.rest.XWikiResource;
1114
1115 @Component("org.xwiki.contrib.rest.HelloWorldResource")
1116 @Path("/myresources/{myresourcename}")
1117 public class HelloWorldResource extends XWikiResource {
1118 @GET
1119 public String get(@PathParam("myresourcename") @DefaultValue("world") String myresourcename)
1120 {
1121 return "Hello " + myresourcename;
1122 }
1123 }
1124 {{/code}}
1125
1126 The name of the component has to be the class FQN.
1127
1128 You can find more examples on [[this page>>https://github.com/xwiki/xwiki-platform/tree/master/xwiki-platform-core/xwiki-platform-rest/xwiki-platform-rest-server/src/main/java/org/xwiki/rest]].
1129
1130 The resource is expected to follow JAX-RS 1 specifications before XWiki 16.2.0 and JAX-RS 2.1 starting with XWiki 16.2.0.
1131
1132 Starting from release 4.3M2, the RESTful API modules have been refactored so that now resource declarations are available in a separate module.
1133 This means that all the information about resources, i.e., URI Paths, supported methods, query parameters, and so on, are available to module developers without having to include the big REST Server module.
1134
1135 Clients willing to access/use the REST API can then declare a dependency on xwiki-platform-rest-api and have all this information available for interacting with it. There are two use cases for this:
1136
1137 * Another platform module that wants to generate responses with links to existing resources.
1138 * HTTP clients that wants to make requests to the RESTful API.
1139
1140 The xwiki-platform-rest-api module can be also seen as an authoritative reference for the REST API.
1141
1142 = Generate a REST URL for a resource =
1143
1144 If you need to generate a REST URL as String for a resource inside a script, you can use the REST script services:
1145
1146 {{code language="velocity"}}
1147 ## Return a relative URL String unless the reference wiki is different from the current wiki
1148 $services.rest.url($entityReference)
1149
1150 ## Force returning an external form URL String, false as second parameter would have the same effect that the previous call
1151 $services.rest.url($entityReference, true)
1152
1153 ## String parameter automaticallly converter to entity reference
1154 $services.rest.url('MySpace.MyPage')
1155 $services.rest.url('document:MySpace.MyPage')
1156 $services.rest.url('space:MySpace')
1157 {{/code}}
1158
1159 Where ##$entityReference## could be:
1160
1161 * a ##DocumentReference##
1162 * a ##SpaceReference##
1163
1164 We plan to add more supported entities in the future (ObjectReference, ClassReference, etc...).
1165
1166 = Using the RESTful API =
1167
1168 {{info}}
1169 The examples below are using the ##~-~-data## (##-d##) parameter of the curl command to provide the data sent with the request, which may do some alteration on the content being actually sent (newlines, character set, etc.)
1170 There may be cases where you may need / want to use the ##~-~-data-binary## parameter, in order to send the data as-is, especially when manipulating page content, in which the newlines are relevant.
1171 {{/info}}
1172
1173 == Tutorial ==
1174
1175 See [[this tutorial>>http://blog.fabio.mancinelli.me/2011/03/07/XWikis_RESTful_API.html]] by Fabio Mancinelli.
1176
1177 == Creating an XWiki Object ==
1178
1179 In this example we will use the [[curl>>http://curl.haxx.se/]] utility as the HTTP client.
1180
1181 Imagine that you want to create on the page Test.Test a new object of the class XWiki.TestClass, supposing that the class has a property called ##text##.
1182
1183 So, on the command line, you have to do the following:
1184
1185 {{code}}
1186 $ curl -u Admin:admin
1187 -X POST
1188 -H "Content-type: application/xml"
1189 -H "Accept: application/xml"
1190 -d "@test.xml"
1191 http://localhost/xwiki/rest/wikis/xwiki/spaces/Test/pages/Test/objects
1192 {{/code}}
1193
1194 where ##test.xml## is:
1195
1196 {{code language="xml"}}
1197 <object xmlns="http://www.xwiki.org">
1198 <className>XWiki.TestClass</className>
1199 <property name="text">
1200 <value>Whatever you want to put here</value>
1201 </property>
1202 </object>
1203 {{/code}}
1204
1205 Alternatively you can use the less verbose ##application/x-www-form-urlencoded format##:
1206
1207 {{code}}
1208 $ curl -u Admin:admin
1209 -X POST
1210 -H "Content-type: application/x-www-form-urlencoded"
1211 -H "Accept: application/xml"
1212 -d "@test.txt"
1213 http://localhost/xwiki/rest/wikis/xwiki/spaces/Test/pages/Test/objects
1214 {{/code}}
1215
1216 where ##test.txt## contains something like:
1217
1218 {{code}}
1219 className=XWiki.TestClass&property#test=Whatever+you+want
1220 {{/code}}
1221
1222 Or, better, you can use directly curl to specify these parameters
1223 using multiple ##-d## switches:
1224
1225 {{code}}
1226 $ curl -u Admin:admin
1227 -X POST -H "Content-type: application/x-www-form-urlencoded"
1228 -H "Accept: application/xml"
1229 -d "className=XWiki.TestClass"
1230 -d "property#test=Whatever you want"
1231 http://localhost/xwiki/rest/wikis/xwiki/spaces/Test/pages/Test/objects
1232 {{/code}}
1233
1234 The advantage of the second approach is that curl will take care of url-encode your content, while if you send a file you are responsible for this.
1235
1236 === Remarks: ===
1237
1238 * In the ##application/x-www-form-urlencoded## format the "property#" is a standard immutable prefix that is used to distinguish attributes referring to property values from the attributes referring to the object. For example if we had ##className=XYZ&Text=FOO## we would have had an ambiguity on ##className## because we couldn't understand if ##className## is a property of the object to be set to XYZ or an attribute that describes the object itself (i.e., its metadata like the ##className##). By having the ##property### prefix this ambiguity is resolved.
1239
1240 * The information you get back when you retrieve an object (i.e., all
1241 the ##<attribute>## elements) are useful when clients need to understand the type of data contained in an object (e.g., when they want to display it). They are not necessary when creating an object because the system already has this information. That's why the XML to be sent is smaller. Actually the only information needed is the ##<className>## and a set of ##<property name="..."><value>## elements.
1242
1243 * How do you know what kind of information you can send with the XML? You can discover it by using the class description URI. If you go to ##http:~/~/localhost:8080/xwiki/rest/wikis/xwiki/classes ## you will get a list of all the classes defined in the Wiki. By looking at this you will understand what are the properties defined by each class, their types and attributes. In that way you will know what you're allowed to put in the ##<property><value>## elements of the XML you send.
1244
1245 == Formats of files ==
1246
1247 A XSD schema exists for XWiki (look [[here>>https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwiki-platform-rest/xwiki-platform-rest-model/src/main/resources/xwiki.rest.model.xsd]] for the source).
1248
1249 However, you may not know exactly how to write the XML files to use when using the PUT method. First thing to know, you may try to get examples by using ##GET## HTTP request to the REST service using cURL or similar tools.
1250
1251 But in order to help you, you'll find below the different formats that you can use. Note that the following XML files are exhaustive files but not all the elements are required.
1252
1253 === Example of a file for a ##wiki## ===
1254
1255 {{code language="xml"}}
1256
1257 <wiki xmlns="http://www.xwiki.org">
1258 <id>xwiki</id>
1259 <name>xwiki</name>
1260 <description>Some description of the wiki</description>
1261 <owner>Admin</owner>
1262 </wiki>
1263 {{/code}}
1264
1265 === Example of a file for a ##space## ===
1266
1267 {{code language="xml"}}
1268
1269 <space xmlns="http://www.xwiki.org">
1270 <id>xwiki:Main</id>
1271 <wiki>xwiki</wiki>
1272 <name>Main</name>
1273 <home>xwiki:Main.WebHome</home>
1274 <xwikiRelativeUrl>http://localhost:8080/xwiki/bin/view/Main/</xwikiRelativeUrl>
1275 <xwikiAbsoluteUrl>http://localhost:8080/xwiki/bin/view/Main/</xwikiAbsoluteUrl>
1276 </space>
1277 {{/code}}
1278
1279 === Example of a file for a ##page## ===
1280
1281 {{code language="xml"}}
1282
1283 <page xmlns="http://www.xwiki.org">
1284 <id>xwiki:Main.WebHome</id>
1285 <fullName>Main.WebHome</fullName>
1286 <wiki>xwiki</wiki>
1287 <space>Main</space>
1288 <name>WebHome</name>
1289 <title>Home</title>
1290 <parent></parent>
1291 <parentId></parentId>
1292 <version>1.1</version>
1293 <author>XWiki.Admin</author>
1294 <authorName>Administrator</authorName>
1295 <xwikiRelativeUrl>http://localhost:8080/xwiki/bin/view/Main/</xwikiRelativeUrl>
1296 <xwikiAbsoluteUrl>http://localhost:8080/xwiki/bin/view/Main/</xwikiAbsoluteUrl>
1297 <translations></translations>
1298 <syntax>xwiki/2.0</syntax>
1299 <language></language>
1300 <majorVersion>1</majorVersion>
1301 <minorVersion>1</minorVersion>
1302 <hidden>false</hidden>
1303 <created>2009-09-09T02:00:00+02:00</created>
1304 <creator>XWiki.Admin</creator>
1305 <creatorName>Administrator</creatorName>
1306 <modified>2015-10-29T11:19:02+01:00</modified>
1307 <modifier>XWiki.Admin</modifier>
1308 <modifierName>Administrator</modifierName>
1309 <comment>Imported from XAR</comment>
1310 <content>{{include reference="Dashboard.WebHome" context="new"/}}</content>
1311 </page>
1312 {{/code}}
1313
1314 === Example of a file for a ##tag## ===
1315
1316 {{code language="xml"}}
1317 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1318 <tags xmlns="http://www.xwiki.org">
1319 <tag name="food"></tag>
1320 </tags>
1321 {{/code}}
1322
1323 === Example of a file for a ##comment## ===
1324
1325 {{code language="xml"}}
1326 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1327 <comments xmlns="http://www.xwiki.org">
1328 <comment>
1329 <id>0</id>
1330 <pageId>xwiki:Main.WebHome</pageId>
1331 <author>XWiki.Admin</author>
1332 <authorName>Administrator</authorName>
1333 <date>2015-11-13T18:20:51.936+01:00</date>
1334 <highlight></highlight>
1335 <text>This is a comment</text>
1336 <replyTo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"></replyTo>
1337 </comment>
1338 </comments>
1339 {{/code}}
1340
1341 === Example of a file for an ##object## ===
1342
1343 {{code language="xml"}}
1344 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1345 <object xmlns="http://www.xwiki.org">
1346 <id>xwiki:Main.WebHome:c170a0a8-cc17-41cd-aa1e-6f6faf1d9f28</id>
1347 <guid>c170a0a8-cc17-41cd-aa1e-6f6faf1d9f28</guid>
1348 <pageId>xwiki:Main.WebHome</pageId>
1349 <pageVersion>1.1</pageVersion>
1350 <wiki>xwiki</wiki>
1351 <space>Main</space>
1352 <pageName>WebHome</pageName>
1353 <pageAuthor>XWiki.superadmin</pageAuthor>
1354 <className>XWiki.EditModeClass</className>
1355 <number>0</number>
1356 <headline>edit</headline>
1357 <property name="defaultEditMode" type="String">
1358 <attribute name="name" value="defaultEditMode"></attribute>
1359 <attribute name="prettyName" value="Default Edit Mode"></attribute>
1360 <attribute name="unmodifiable" value="0"></attribute>
1361 <attribute name="disabled" value="0"></attribute>
1362 <attribute name="size" value="15"></attribute>
1363 <attribute name="number" value="1"></attribute>
1364 <value>edit</value>
1365 </property>
1366 </object>
1367 {{/code}}
1368
1369 === Example of a file for a ##property## ===
1370
1371 {{code language="xml"}}
1372 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1373 <property xmlns="http://www.xwiki.org" name="defaultEditMode" type="String">
1374 <attribute name="name" value="defaultEditMode"></attribute>
1375 <attribute name="prettyName" value="Default Edit Mode"></attribute>
1376 <attribute name="unmodifiable" value="0"></attribute>
1377 <attribute name="disabled" value="0"></attribute>
1378 <attribute name="size" value="15"></attribute>
1379 <attribute name="number" value="1"></attribute>
1380 <value>edit</value>
1381 </property>
1382 {{/code}}
1383
1384 = Examples =
1385
1386 == Getting the list of users ==
1387
1388 Since Users are stored as Objects, you can do a search of the type ##XWiki.XWikiUsers##. For example:
1389
1390 {{code}}
1391 http://<server>/xwiki/rest/wikis/query?q=object:XWiki.XWikiUsers
1392 {{/code}}
1393
1394 == Getting the list of users using XWQL ==
1395
1396 Using the parameter "className" the result includes the data for the first object of the ##XWiki.XWikiUsers##:
1397
1398 {{code}}
1399 http://<server>/xwiki/rest/wikis/xwiki/query?q=,doc.object(XWiki.XWikiUsers) as obj&type=xwql&className=XWiki.XWikiUsers
1400 {{/code}}

Get Connected