Wiki source code of REST API

Version 94.1 by Michael Hamann on 2023/03/22

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>>platform:Features.XWikiRESTfulAPI#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 two 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
132 If you don't provide any credentials the XWiki RESTful API will recognize you as a XWiki.Guest user.
133
134 So if you have, let's say a Main.PrivatePage, and you try to do:
135
136 {{code language="none"}}
137 $ curl -v http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/PrivatePage
138 ...
139 < HTTP/1.1 401 Unauthorized
140 ...
141 {{/code}}
142
143 You will get an Unauthorized empty response.
144
145 On the contrary, by specifying Admin credentials you gain access to the actual page:
146
147 {{code language="xml"}}
148 $ curl -u Admin:admin http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/PrivatePage
149
150 <page xmlns="http://www.xwiki.org">
151 <link rel="http://www.xwiki.org/rel/space" href="http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main"/>
152 ...
153 <content>Only admin can see this</content>
154 </page>
155 {{/code}}
156
157 {{version since="14.10.8,15.2"}}
158 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.
159
160 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.
161
162 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.
163 {{/version}}
164
165 == Sending representations ==
166
167 Many resources are modifiable, so you can send representations in order to change the state of those resources (e.g., pages).
168 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).
169
170 Resource update is usually done by using the PUT method, while resource creation is done via PUT or POST.
171
172 For example, in order to create a page you might do the following:
173
174 {{code language="xml"}}
175 $ 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
176
177 <page xmlns="http://www.xwiki.org">
178 <link rel="http://www.xwiki.org/rel/space" href="http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main"/>
179 ...
180 <version>1.1</version>
181 <majorVersion>1</majorVersion>
182 <minorVersion>1</minorVersion>
183 <created>2009-03-21+01:00</created>
184 <creator>XWiki.Admin</creator>
185 <modified>2009-03-21+01:00</modified>
186 <modifier>XWiki.Admin</modifier>
187 <content>This is a new page</content>
188 </page>
189 {{/code}}
190
191 Where newpage.xml is an XML file containing
192
193 {{code language="xml"}}
194
195 <page xmlns="http://www.xwiki.org">
196 <title>Hello world</title>
197 <syntax>xwiki/2.0</syntax>
198 <content>This is a new page</content>
199 </page>
200 {{/code}}
201
202 The page has been created and is accessible. Subsequent PUT requests to the page URI will modify its content.
203
204 You can specify a subset of the three elements {{{title}}}, {{{syntax}}}, and {{{content}}} in the XML when updating/creating a page.
205 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.
206
207 == Overcoming browser limitations ==
208
209 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.
210
211 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.
212
213 This overriding mechanism allows the interaction with the XWiki RESTful API by using any kind of browser.
214
215 == PUT vs POST ==
216
217 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.
218
219 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.
220
221 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.
222
223 == Headers ==
224
225 The response of the REST requests always contain some custom headers that might be useful:
226
227 * ##xwiki-version##: contains the representation of the version of XWiki defined in ##version.properties## (e.g. 14.4.6)
228 * ##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.
229
230 = XWiki RESTful API Documentation =
231
232 In this section you will find the documentation of the whole XWiki RESTful API.
233
234 **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]].
235
236 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.
237
238 == Root resources ==
239
240 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)
241
242 === / ===
243
244 * **HTTP Method:** GET
245 ** **Media types:**
246 *** application/xml (XWiki element)
247 ** **Description:** Retrieves the entry root description containing information about the server (currently returns the XWiki product Version).
248 ** **Status codes:**
249 *** 200: If the request was successful.
250
251 === /syntaxes ===
252
253 * **HTTP Method:** GET
254 ** **Media types:**
255 *** application/xml (Syntaxes element)
256 ** **Description:** The list of syntaxes supported by the XWiki instance.
257 ** **Status codes:**
258 *** 200: If the request was successful.
259
260 === /wikis ===
261
262 * **HTTP Method:** GET
263 ** **Media types:**
264 *** application/xml (Wikis element)
265 ** **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'.
266 ** **Status codes:**
267 *** 200: If the request was successful.
268
269 === /wikis/query?q~={query}&wikis~=wikiList[&distinct~={true,false}][&order~={asc,desc}][&start~=n][&number~=n][&prettyNames~={true,false}] ===
270
271 * **HTTP Method:** GET
272 ** **Media types:**
273 *** application/xml (SearchResults element)
274 ** **Description:** Search resources (pages and attachments):
275 *** [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.
276 *** [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.
277 ** **Status codes:**
278 *** 200: If the request was successful.
279
280 === /wikis/{wikiName} ===
281
282 * **HTTP Method:** GET
283 ** **Media types:**
284 *** application/xml (Wiki element)
285 ** **Description:** information about the wiki
286 ** **Status codes:**
287 *** 200: If the request was successful.
288
289 * **HTTP Method:** POST
290 ** **Accepted Media types:**
291 *** octet/stream (A XAR file)
292 ** **Media types:**
293 *** application/xml (Wiki element)
294 ** **Query parameters**
295 *** backup={true/false} - import XAR as a backup XAR
296 *** history={RESET/REPLACE/ADD} - history importing
297 ** **Description:** import a XAR in a wiki.
298 ** **Status codes:**
299 *** 200: If the request was successful.
300
301 === /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}] ===
302
303 * **HTTP Method:** GET
304 ** **Media types:**
305 *** application/xml (SearchResults element)
306 ** **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.
307 ** **Status codes:**
308 *** 200: If the request was successful.
309
310 === /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] ===
311
312 * **HTTP Method:** GET
313 ** **Media types:**
314 *** application/xml (SearchResults element)
315 ** **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>>platform:DevGuide.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.
316 ** **Status codes:**
317 *** 200: If the request was successful.
318
319 === /wikimanager (This resource is only available when using the [[multi-wiki>>extensions:Extension.Wiki Application]] feature) ===
320
321 * **HTTP Method:** POST
322 ** **Accepted Media types:**
323 *** application/xml (Wiki element)
324 ** **Media types:**
325 *** application/xml (Wiki element)
326 ** **Query parameters**
327 *** template - the wiki template to be used for initializing the wiki.
328 *** history={RESET/REPLACE/ADD} - history importing
329 ** **Description:** create a new wiki.
330 ** **Status codes:**
331 *** 200: If the request was successful.
332
333 == Space resources ==
334
335 === /wikis/{wikiName}/spaces[?start~=offset&number~=n] ===
336
337 * **HTTP Method:** GET
338 ** **Media types:**
339 *** application/xml (Spaces element)
340 ** **Description:** Retrieves the list of spaces available in the {wikiName} wiki.
341 ** **Status codes:**
342 *** 200: If the request was successful.
343
344 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/search?q~={keywords}~[~[&scope~={name,content,title,objects}...]&number~=n] ===
345
346 * **HTTP Method:** GET
347 ** **Media types:**
348 *** application/xml (Search results element)
349 ** **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}
350 ** **Status codes:**
351 *** 200: If the request was successful.
352 *** 401: If the user is not authorized.
353
354 == Page resources ==
355
356 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages[?start~=offset&number~=n] ===
357
358 * **HTTP Method:** GET
359 ** **Media types:**
360 *** application/xml (Pages element)
361 ** **Description:** The list of pages in the space {spaceName}
362 ** **Status codes:**
363 *** 200: If the request was successful.
364 *** 401: If the user is not authorized.
365
366 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}[?prettyNames~={true,false}&objects~={true,false}&class~={true,false}&attachments~={true,false}&minorRevision~={true,false}] ===
367
368 * **HTTP Method:** GET
369 ** **Media types:**
370 *** application/xml (Page element)
371 ** **Query parameters**
372 *** ##prettyNames##: also return the pretty name for various document information (like the author display name, etc). Disabled by default.
373 *** ##objects##: //[since 7.3M1]// also return the objects. Disabled by default.
374 *** ##class##: //[since 7.3M1]// also return the class. Disabled by default.
375 *** ##attachments##: //[since 7.3M1]// also return the attachments metadatas. Disabled by default.
376 ** **Description:**
377 ** **Status codes:**
378 *** 200: If the request was successful.
379 *** 401: If the user is not authorized.
380
381 * **HTTP Method:** PUT
382 ** **Accepted Media types:**
383 *** application/xml (Page element)
384 *** text/plain (Only page content)
385 *** application/x-www-form-urlencoded (allowed field names: title, parent, hidden //[since 7.3]//, content)
386 ** **Media types:**
387 *** application/xml (Page element)
388 ** **Query parameters**
389 *** ##minorRevision## ({{info}}Since 9.11.4 & 10.2RC1{{/info}}): Create a minor revision for the page. Disabled by default.
390 ** **Description:** Create or updates a page.
391 ** **Status codes:**
392 *** 201: If the page was created.
393 *** 202: If the page was updated.
394 *** 304: If the page was not modified.
395 *** 401: If the user is not authorized.
396
397 * **HTTP Method:** DELETE
398 ** **Media types:**
399 *** application/xml (Page element)
400 ** **Description:** Delete the page.
401 ** **Status codes:**
402 *** 204: If the request was successful.
403 *** 401: If the user is not authorized.
404
405 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/history[?start~=offset&number~=n] ===
406
407 * **HTTP Method:** GET
408 ** **Media types:**
409 *** application/xml (History element)
410 ** **Description:** The list of all the versions of the given page.
411 ** **Status codes:**
412 *** 200: If the request was successful.
413 *** 401: If the user is not authorized.
414
415 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/history/{version} ===
416
417 * **HTTP Method:** GET
418 ** **Media types:**
419 *** application/xml (Page element)
420 ** **Description:** The page at version {version}
421 ** **Status codes:**
422 *** 200: If the request was successful.
423 *** 401: If the user is not authorized.
424
425 ==== /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/translations[?start~=offset&number~=n] ====
426
427 * **HTTP Method:** GET
428 ** **Media types:**
429 *** application/xml (Translations element)
430 ** **Description:** The list of available translation for the page
431 ** **Status codes:**
432 *** 200: If the request was successful.
433 *** 401: If the user is not authorized.
434
435 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/translations/{language}[?minorRevision~={true,false}] ===
436
437 * **HTTP Method:** GET
438 ** **Media types:**
439 *** application/xml (Page element)
440 ** **Description:** The page at in the given {language}.
441 ** **Status codes:**
442 *** 200: If the request was successful.
443 *** 401: If the user is not authorized.
444
445 * **HTTP Method:** PUT
446 ** **Accepted Media types:**
447 *** application/xml (Page element)
448 *** text/plain (Only page content)
449 *** application/x-www-form-urlencoded (allowed field names: title, parent, content)
450 ** **Media types:**
451 *** application/xml (Page element)
452 ** **Query parameters**
453 *** ##minorRevision## ({{info}}Since 9.11.4 & 10.2RC1{{/info}}): Create a minor revision for the page. Disabled by default.
454 ** **Description:** Create or updates a page translation.
455 ** **Status codes:**
456 *** 201: If the page was created.
457 *** 202: If the page was updated.
458 *** 304: If the page was not modified.
459 *** 401: If the user is not authorized.
460
461 * **HTTP Method:** DELETE
462 ** **Media types:**
463 *** application/xml (Page element)
464 ** **Description:** Delete the page translation.
465 ** **Status codes:**
466 *** 204: If the request was successful.
467 *** 401: If the user is not authorized.
468
469 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/translations/{language}/history ===
470
471 * **HTTP Method:** GET
472 ** **Media types:**
473 *** application/xml (History element)
474 ** **Description:** The list of all the available revisions of the page in a given {language}.
475 ** **Status codes:**
476 *** 200: If the request was successful.
477 *** 401: If the user is not authorized.
478
479 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/translations/{lang}/history/{version} ===
480
481 * **HTTP Method:** GET
482 ** **Media types:**
483 *** application/xml (Page element)
484 ** **Description:** A page at a given {version} in a given {language}.
485 ** **Status codes:**
486 *** 200: If the request was successful.
487 *** 401: If the user is not authorized.
488
489 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/children ===
490
491 * **HTTP Method:** GET
492 ** **Media types:**
493 *** application/xml (Pages element)
494 ** **Description:** The list of the children of a given page.
495 ** **Status codes:**
496 *** 200: If the request was successful.
497 *** 401: If the user is not authorized.
498
499 === /wikis/{wikiName}/pages[?name~=paneName&space~=spaceName&author~=authorName] ===
500
501 * **HTTP Method:** GET
502 ** **Media types:**
503 *** application/xml (Pages element)
504 ** **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.
505 ** **Status codes:**
506 *** 200: If the request was successful.
507 *** 401: If the user is not authorized.
508
509 == Tag resources ==
510
511 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/tags[?minorRevision~={true,false}] ===
512
513 * **HTTP Method:** GET
514 ** **Media types:**
515 *** application/xml (Tags element)
516 ** **Description:** List page tags.
517 ** **Status codes:**
518 *** 200: If the request was successful.
519 *** 401: If the user is not authorized.
520
521 * **HTTP Method:** PUT
522 ** **Accepted Media types:**
523 *** application/xml (Tag element)
524 *** text/plain
525 *** application/x-www-form-urlencoded (allowed field names: tag)
526 ** **Media types:**
527 *** application/xml (Tags element)
528 ** **Query parameters**
529 *** ##minorRevision## ({{info}}Since 9.11.4 & 10.2RC1{{/info}}): Create a minor revision for the page. Disabled by default.
530 ** **Description:** Add a tag to the page.
531 ** **Status codes:**
532 *** 202: If the request was successful.
533 *** 401: If the user is not authorized.
534
535 === /wikis/{wikiName}/tags ===
536
537 * **HTTP Method:** GET
538 ** **Media types:**
539 *** application/xml (Tags element)
540 ** **Description:** The list of all available tags
541 ** **Status codes:**
542 *** 200: If the request was successful.
543 *** 401: If the user is not authorized.
544
545 === /wikis/{wikiName}/tags/{tag1}[,{tag2},{tag3}...][?start~=offset&number~=n] ===
546
547 * **HTTP Method:** GET
548 ** **Media types:**
549 *** application/xml (Pages element)
550 ** **Description:** The list of pages having the specified tags.
551 ** **Status codes:**
552 *** 200: If the request was successful.
553 *** 401: If the user is not authorized.
554
555 == Comments resources ==
556
557 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/comments[?start~=offset&number~=n] ===
558
559 * **HTTP Method:** GET
560 ** **Media types:**
561 *** application/xml (Comments element)
562 ** **Description:** The list of comments on a given page.
563 ** **Status codes:**
564 *** 200: If the request was successful.
565 *** 401: If the user is not authorized.
566
567 * **HTTP Method:** POST
568 ** **Accepted Media types:**
569 *** application/xml (Comment element)
570 *** text/plain
571 *** application/x-www-form-urlencoded - allowed field names: ##text##, ##replyTo## (object number of the replied comment, since XE 2.3)
572 ** **Media types:**
573 *** application/xml (Comment element)
574 ** **Description:** Create a comment on the given page.
575 ** **Status codes:**
576 *** 201: If the comment was created. (The Location header will contain the URI where the comment has been created.)
577 *** 401: If the user is not authorized.
578
579 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/comments/{commentId} ===
580
581 * **HTTP Method:** GET
582 ** **Media types:**
583 *** application/xml (Comment element)
584 ** **Description:** A specific comment on a page
585 ** **Status codes:**
586 *** 200: If the request was successful.
587 *** 401: If the user is not authorized.
588
589 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/history/{version}/comments ===
590
591 * **HTTP Method:** GET
592 ** **Media types:**
593 *** application/xml (Comments element)
594 ** **Description:** The list of comments at a specific page {version}.
595 ** **Status codes:**
596 *** 200: If the request was successful.
597 *** 401: If the user is not authorized.
598
599 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/history/{version}/comments/{commentId} ===
600
601 * **HTTP Method:** GET
602 ** **Media types:**
603 *** application/xml (Comment element)
604 ** **Description:** A comment at a specific page {version}.
605 ** **Status codes:**
606 *** 200: If the request was successful.
607 *** 401: If the user is not authorized.
608
609 == Attachments resources ==
610
611 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/attachments[?start~=offset&number~=n] ===
612
613 * **HTTP Method:** GET
614 ** **Media types:**
615 *** application/xml (Attachments element)
616 ** **Description:** The list of attachments of a given page.
617 ** **Status codes:**
618 *** 200: If the request was successful.
619 *** 401: If the user is not authorized.
620
621 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/attachments/{attachmentName} ===
622
623 * **HTTP Method:** GET
624 ** **Media types:**
625 *** The same of the attachment media type.
626 ** **Description:** The attachment identified by {attachmentName} on a given page.
627 ** **Status codes:**
628 *** 200: If the request was successful.
629 *** 401: If the user is not authorized.
630
631 * **HTTP Method:** PUT
632 ** **Accepted media types:**
633 *** **/**
634 ** **Media types:**
635 *** application/xml (AttachmentSummary element)
636 ** **Description:** Create an attachment identified by {attachmentName} on a given page.
637 ** **Status codes:**
638 *** 201: If the attachment was created.
639 *** 202: If the attachment was updated.
640 *** 401: If the user is not authorized.
641
642 * **HTTP Method:** DELETE
643 ** **Media types:**
644 ** **Description:** Delete the attachment identified by {attachmentName} on a given page.
645 ** **Status codes:**
646 *** 204: If the attachment was deleted.
647 *** 401: If the user is not authorized.
648
649 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/history/{version}/attachments[?start~=offset&number~=n] ===
650
651 * **HTTP Method:** GET
652 ** **Media types:**
653 *** application/xml (Attachments element)
654 ** **Description:** The list of attachments at a given page {version}.
655 ** **Status codes:**
656 *** 200: If the request was successful.
657 *** 401: If the user is not authorized.
658
659 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/history/{version}/attachments/{attachmentName} ===
660
661 * **HTTP Method:** GET
662 ** **Media types:**
663 *** The same of the attachment media type.
664 ** **Description:** The attachment identified by {attachmentName} on a given page {version}.
665 ** **Status codes:**
666 *** 200: If the request was successful.
667 *** 401: If the user is not authorized.
668
669 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/attachments/{attachmentName}/history ===
670
671 * **HTTP Method:** GET
672 ** **Media types:**
673 *** application/xml (Attachments element)
674 ** **Description:** The list of available version for the {attachmentName}
675 ** **Status codes:**
676 *** 200: If the request was successful.
677 *** 401: If the user is not authorized.
678
679 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/attachments/{attachmentName}/history/{version} ===
680
681 * **HTTP Method:** GET
682 ** **Media types:**
683 *** The same of the attachment media type.
684 ** **Description:** The {attachmentName} at a given {version}
685 ** **Status codes:**
686 *** 200: If the request was successful.
687 *** 401: If the user is not authorized.
688
689 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/attachments[?name~=attachmentName&page~=pageName&author~=authorName&types~=attachmentTypeList&start~=offset&number~=n] ===
690
691 * **HTTP Method:** GET
692 ** **Media types:**
693 *** application/xml (Attachments element)
694 ** **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.
695 ** **Status codes:**
696 *** 200: If the request was successful.
697 *** 401: If the user is not authorized.
698
699 === /wikis/{wikiName}/attachments[?name~=attachmentName&page~=pageName&space~=spaceName&author~=authorName&types~=attachmentTypeList&start~=offset&number~=n] ===
700
701 * **HTTP Method:** GET
702 ** **Media types:**
703 *** application/xml (Attachments element)
704 ** **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.
705 ** **Status codes:**
706 *** 200: If the request was successful.
707 *** 401: If the user is not authorized.
708
709 == Object resources ==
710
711 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/objects[?start~=offset&number~=n] ===
712
713 * **HTTP Method:** GET
714 ** **Media types:**
715 *** application/xml (Objects element)
716 ** **Description:** The list of objects associated to a page.
717 ** **Status codes:**
718 *** 200: If the request was successful.
719 *** 401: If the user is not authorized.
720
721 * **HTTP Method:** POST
722 ** **Accepted media types:**
723 *** application/xml (Object element)
724 *** application/x-www-form-urlencoded (a set of property#name=value pairs representing properties and a field className)
725 **** e.g. {{code language="none"}}className=XWiki.XWikiUsers&property#first_name=John&property#last_name=Doe{{/code}}
726 ** **Media types:**
727 *** application/xml (Object element)
728 ** **Description:** Create a new object.
729 ** **Status codes:**
730 *** 201: If the object was created (The Location header will contain the URI associated to the newly created object).
731 *** 401: If the user is not authorized.
732
733 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/objects/{className}[?start~=offset&number~=n] ===
734
735 * **HTTP Method:** GET
736 ** **Media types:**
737 *** application/xml (Objects element)
738 ** **Description:** The list of objects of a given {className} associated to a page.
739 ** **Status codes:**
740 *** 200: If the request was successful.
741 *** 401: If the user is not authorized.
742
743 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/objects/{className}/{objectNumber}[?minorRevision~={true,false}] ===
744
745 * **HTTP Method:** GET
746 ** **Media types:**
747 *** application/xml (Object element)
748 ** **Description:** The object of type {className} identified by {objectNumber} associated to the given page.
749 ** **Status codes:**
750 *** 200: If the request was successful.
751 *** 401: If the user is not authorized.
752
753 * **HTTP Method:** PUT
754 ** **Accepted media types:**
755 *** application/xml (Object element)
756 *** application/x-www-form-urlencoded (a set of property#name=value pairs representing properties)
757 ** **Media types:**
758 *** application/xml (Object element)
759 ** **Query parameters**
760 *** ##minorRevision## ({{info}}Since 9.11.4 & 10.2RC1{{/info}}): Create a minor revision for the page. Disabled by default.
761 ** **Description:** Modify the object properties.
762 ** **Status codes:**
763 *** 202: If the object was updated.
764 *** 401: If the user is not authorized.
765
766 * **HTTP Method:** DELETE
767 ** **Media types:**
768 ** **Description:** Delete the object.
769 ** **Status codes:**
770 *** 204: If the object was deleted.
771 *** 401: If the user is not authorized.
772
773 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/objects/{className}/{objectNumber}/properties ===
774
775 * **HTTP Method:** GET
776 ** **Media types:**
777 *** application/xml (Properties element)
778 ** **Description:** The properties of the object of type {className} identified by {objectNumber} associated to the given page.
779 ** **Status codes:**
780 *** 200: If the request was successful.
781 *** 401: If the user is not authorized.
782
783 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/objects/{className}/{objectNumber}/properties/{propertyName}[?minorRevision~={true,false}] ===
784
785 * **HTTP Method:** GET
786 ** **Media types:**
787 *** application/xml (Properties element)
788 ** **Description:** The property {propertyname} of the object of type {className} identified by {objectNumber} associated to the given page.
789 ** **Status codes:**
790 *** 200: If the request was successful.
791 *** 401: If the user is not authorized.
792
793 * **HTTP Method:** PUT
794 ** **Accepted media types:**
795 *** application/xml (Property element)
796 *** text/plain
797 *** application/x-www-form-urlencoded (a field property#name=value pairs representing a property)
798 ** **Media types:**
799 *** application/xml (Property element)
800 ** **Query parameters**
801 *** ##minorRevision## ({{info}}Since 9.11.4 & 10.2RC1{{/info}}): Create a minor revision for the page. Disabled by default.
802 ** **Description:** Modify the object properties.
803 ** **Status codes:**
804 *** 202: If the object was updated.
805 *** 401: If the user is not authorized.
806
807 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/history/{version}/objects[?start~=offset&number~=n] ===
808
809 * **HTTP Method:** GET
810 ** **Media types:**
811 *** application/xml (Objects element)
812 ** **Description:** The list of objects associated to a page at a given {version}.
813 ** **Status codes:**
814 *** 200: If the request was successful.
815 *** 401: If the user is not authorized.
816
817 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/history/{version}/objects/{className}/{objectNumber} ===
818
819 * **HTTP Method:** GET
820 ** **Media types:**
821 *** application/xml (Object element)
822 ** **Description:** The object of type {className} identified by {objectNumber} associated to the given page at a given {version}.
823 ** **Status codes:**
824 *** 200: If the request was successful.
825 *** 401: If the user is not authorized.
826
827 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/history/{version}/objects/{className}/{objectNumber}/properties ===
828
829 * **HTTP Method:** GET
830 ** **Media types:**
831 *** application/xml (Properties element)
832 ** **Description:** The properties of the object of type {className} identified by {objectNumber} associated to the given page at a given {version}.
833 ** **Status codes:**
834 *** 200: If the request was successful.
835 *** 401: If the user is not authorized.
836
837 === /wikis/{wikiName}/spaces/{spaceName}[/spaces/{nestedSpaceName}]*/pages/{pageName}/history/{version}/objects/{className}/{objectNumber}/properties/{propertyName} ===
838
839 * **HTTP Method:** GET
840 ** **Media types:**
841 *** application/xml (Properties element)
842 ** **Description:** The property {propertyName} of the object of type {className} identified by {objectNumber} associated to the given page at a given {version}.
843 ** **Status codes:**
844 *** 200: If the request was successful.
845 *** 401: If the user is not authorized.
846
847 === /wikis/{wikiName}/classes/{className}/objects[?start~=offset&number~=n] ===
848
849 * **HTTP Method:** GET
850 ** **Media types:**
851 *** application/xml (Objects element)
852 ** **Description:** The list of all the objects of a given {className}.
853 ** **Status codes:**
854 *** 200: If the request was successful.
855 *** 401: If the user is not authorized.
856
857 == Class resources ==
858
859 === /wikis/{wikiName}/classes[?start~=offset&number~=n] ===
860
861 * **HTTP Method:** GET
862 ** **Media types:**
863 *** application/xml (Classes element)
864 ** **Description:** The list of all the classes defined in the wiki {wikiName}
865 ** **Status codes:**
866 *** 200: If the request was successful.
867 *** 401: If the user is not authorized.
868
869 === /wikis/{wikiName}/classes/{className} ===
870
871 * **HTTP Method:** GET
872 ** **Media types:**
873 *** application/xml (Class element)
874 ** **Description:** The {className} definition
875 ** **Status codes:**
876 *** 200: If the request was successful.
877 *** 401: If the user is not authorized.
878
879 === /wikis/{wikiName}/classes/{className}/properties ===
880
881 * **HTTP Method:** GET
882 ** **Media types:**
883 *** application/xml (Properties element)
884 ** **Description:** The properties of the class {className}.
885 ** **Status codes:**
886 *** 200: If the request was successful.
887 *** 401: If the user is not authorized.
888
889 === /wikis/{wikiName}/classes/{className}/properties/{propertyName} ===
890
891 * **HTTP Method:** GET
892 ** **Media types:**
893 *** application/xml (Property element)
894 ** **Description:** The property {propertyName} of the class {className}.
895 ** **Status codes:**
896 *** 200: If the request was successful.
897 *** 401: If the user is not authorized.
898
899 === /wikis/{wikiName}/classes/{className}/properties/{propertyName}/values {{info}}Since 9.8RC1{{/info}} ===
900
901 Request parameters:
902
903 |=Name|=Description|
904 |limit|Limit the number of values returned. Zero or a negative number means no limit.
905 |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.
906
907 * **HTTP Method:** GET
908 ** **Media types:**
909 *** application/xml (Property element)
910 ** **Description:** The list of values for the property {propertyName} of the class {className}. At the moment only Database List properties are supported.
911 ** **Status codes:**
912 *** 200: If the request was successful.
913 *** 401: If the user is not authorized to view the specified property.
914 *** 404: If the specified property doesn't exist.
915
916 == Job resources ==
917
918 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##).
919
920 === /jobstatus/{jobId} {{info}}Since 7.2M3{{/info}} ===
921
922 Request parameters:
923
924 |=Name|=Required|=Values|=Default|=Description|=Version
925 |##request##|no|##true~|false##|##false##|Return also the job request|9.1RC1
926 |##progress##|no|##true~|false##|##true##|Return also the job progress|9.1RC1
927 |##log##|no|##true~|false##|##false##|Return also the job log|9.1RC1
928 |##log_fromLevel##|no|##error~|warn~|info~|debug~|trace##| |Indicate the level from which to return logs|9.1RC1
929
930 * **HTTP Method:** GET
931 ** **Media types:**
932 *** application/xml (JobStatus element)
933 ** **Description:** status of a job
934 ** **Status codes:**
935 *** 200: If the request was successful.
936 *** 404: If the job status has not been found
937
938 === /joblog/{jobId} {{info}}Since 7.2M3{{/info}} ===
939
940 Request parameters:
941
942 |=Name|=Required|=Values|=Default|=Description|=Version
943 |##level##|no|##error~|warn~|info~|debug~|trace##| |Indicate the exact level for which to return logs|7.2M3
944 |##fromLevel##|no|##error~|warn~|info~|debug~|trace##| |Indicate the level from which to return logs|7.2M3
945
946 * **HTTP Method:** GET
947 ** **Media types:**
948 *** application/xml (JobLog element)
949 ** **Description:** log of a job
950 ** **Status codes:**
951 *** 200: If the request was successful.
952 *** 404: If the job status has not been found
953
954 === /jobs {{info}}Since 9.1RC1{{/info}} ===
955
956 Request parameters:
957
958 |=Name|=Required|=Values|=Default|=Description|=Version
959 |##jobType##|yes| | |The type of the job to pass to the Job Executor|9.1RC1
960 |##async##|no|##true~|false##|##true##|If false, return the response only when the job is done|9.1RC1
961
962 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.).
963
964 * **HTTP Method:** PUT
965 ** **Input:**
966 *** Media Types: ##application/xml## or ##application/json##
967 *** Input body: ##JobRequest## element
968 ** **Output:**
969 *** Media Types: ##application/xml## or ##application/json##
970 *** Response body: ##JobStatus## element
971 ** **Description:** Start a new job synchronously or asynchronously
972 ** **Status codes:**
973 *** 200: If the job was successfully executed
974 *** 401: If the user is not authorized (i.e. doesn't have Programming Rights)
975 *** 500: Failing jobs with ##async=false## return an error 500 (Since 9.7RC1)
976
977 Jobs started through the REST API automatically get their runtime context injected with the following REST HTTP request context properties:
978
979 * current wiki
980 * current user
981 * request URL and parameters
982
983 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:
984
985 * ask for the status of an existing job to have an hint of how the XML/JSON should look like (see [[jobstatus section>>#H2Fjobstatus2F7BjobId7D]])
986 * 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/
987
988 === Example of Extension Manager installJob ===
989
990 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):
991
992 {{code language="none"}}
993 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
994 {{/code}}
995
996 == Localization resources ==
997
998 For more details see the [[Localization Module documentation>>extensions:Extension.Localization.WebHome]].
999
1000 {{version since="13.3RC1"}}
1001 === /wikis/{wikiName}/localization/translations[?locale~=l&prefix~=p[&key~=k]*] ===
1002
1003 * **HTTP Method**: GET
1004 ** **Media Types:** ##application/xml## or ##application/json##
1005 ** **Description: **The list of translations of the requested keys in a given locale
1006 ** **Query Parameters:**
1007 *** **locale:** (optional) the locale of the returned translation, if missing the locale is resolved from the context
1008 *** **prefix:** (optional) a common prefix concatenated to all the provided keys.
1009 *** **key:** (multiple) a list of translation keys
1010 ** **Status Code:**
1011 *** 200: if the request was successful
1012 ** **Response:**
1013 *** 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).
1014 {{/version}}
1015
1016 == Icon Theme resources ==
1017
1018 For more details see the [[extensions:Extension.Icon Theme Application.WebHome]].
1019
1020 {{version since="13.3RC1"}}
1021 === /wikis/{wikiName}/iconThemes/icons[?[name~=n]*] ===
1022
1023 * **HTTP Method**: GET
1024 ** **Media Types:** ##application/xml## or ##application/json##
1025 ** **Description: **Provides the metadata of the icons of the current icon theme in a given ##{wikiName}## wiki
1026 ** **Query Parameters:**
1027 *** **name:** (multiple) the name of the requested icons
1028 ** **Status Code:**
1029 *** 200: if the request was successful
1030 ** **Response:**
1031 *** 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.
1032
1033
1034 === /wikis/{wikiName}/iconThemes/{iconTheme}/icons[?[name~=n]*] ===
1035
1036 * **HTTP Method**: GET
1037 ** **Media Types:** ##application/xml## or ##application/json##
1038 ** **Description: **Provides the metadata of the icons of the ##{iconTheme}## icon theme in a given ##{wikiName}## wiki
1039 ** **Query Parameters:**
1040 *** **name:** (multiple) the name of the requested icons
1041 ** **Status Code:**
1042 *** 200: if the request was successful
1043 ** **Response:**
1044 *** 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.
1045 {{/version}}
1046
1047 == Other resources ==
1048
1049 === /wikis/{wikiName}/modifications[?start~=offset&number~=n&date~=t] ===
1050
1051 * **HTTP Method:** GET
1052 ** **Media types:**
1053 *** application/xml (Modifications element)
1054 ** **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)
1055 ** **Status codes:**
1056 *** 200: If the request was successful.
1057 *** 401: If the user is not authorized.
1058
1059 = Custom resources =
1060
1061 == In Wiki Pages ==
1062
1063 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:
1064
1065 {{code language="velocity"}}
1066 {{velocity}}
1067 #if ("$!request.space" != '')
1068 #set ($discard = $response.setContentType('text/xml'))
1069
1070 <pages>
1071 #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"))
1072 #set ($spaceReferenceString = $request.space)
1073 #set ($spaceLike = $spaceReferenceString.replaceAll('([%_!])', '!$1').concat('.%'))
1074 #set ($query = $query.bindValue('spacelike', $spaceLike))
1075 #set ($query = $query.bindValue('space', $spaceReferenceString))
1076 #foreach ($item in $query.execute())
1077 <page>$item</page>
1078 #end
1079 </pages>
1080 #end
1081 {{/velocity}}
1082 {{/code}}
1083
1084 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:
1085
1086 {{code language="none"}}
1087 <pages>
1088 <page>Sandbox.Test.WebHome</page>
1089 <page>Sandbox.TestPage2</page>
1090 <page>Sandbox.ApplicationsPanelEntry</page>
1091 <page>Sandbox.TestPage3</page>
1092 <page>Sandbox.TestPage1</page>
1093 <page>Sandbox.WebPreferences</page>
1094 <page>Sandbox.WebHome</page>
1095 </pages>
1096 {{/code}}
1097
1098 == In Java ==
1099
1100 It's possible to easily add any REST resource by registering a ##org.xwiki.rest.XWikiResource## java component on your wiki (see [[Component guide>>platform:DevGuide.WritingComponents]] for more details).
1101
1102 {{code language="java"}}
1103 package org.xwiki.contrib.rest;
1104
1105 import javax.ws.rs.DefaultValue;
1106 import javax.ws.rs.GET;
1107 import javax.ws.rs.Path;
1108
1109 import org.xwiki.component.annotation.Component;
1110 import org.xwiki.rest.XWikiResource;
1111
1112 @Component("org.xwiki.contrib.rest.HelloWorldResource")
1113 @Path("/myresources/{myresourcename}")
1114 public class HelloWorldResource extends XWikiResource {
1115 @GET
1116 public String get(@PathParam("myresourcename") @DefaultValue("world") String myresourcename)
1117 {
1118 return "Hello " + myresourcename;
1119 }
1120 }
1121 {{/code}}
1122
1123 The name of the component has to be the class FQN.
1124
1125 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]].
1126
1127 Starting from release 4.3M2, the RESTful API modules have been refactored so that now resource declarations are available in a separate module.
1128 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.
1129
1130 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:
1131
1132 * Another platform module that wants to generate responses with links to existing resources.
1133 * HTTP clients that wants to make requests to the RESTful API.
1134
1135 The xwiki-platform-rest-api module can be also seen as an authoritative reference for the REST API.
1136
1137 = Generate a REST URL for a resource =
1138
1139 If you need to generate a REST URL as String for a resource inside a script, you can use the REST script services:
1140
1141 {{code language="velocity"}}
1142 ## Return a relative URL String unless the reference wiki is different from the current wiki
1143 $services.rest.url($entityReference)
1144
1145 ## Force returning an external form URL String, false as second parameter would have the same effect that the previous call
1146 $services.rest.url($entityReference, true)
1147
1148 ## String parameter automaticallly converter to entity reference
1149 $services.rest.url('MySpace.MyPage')
1150 $services.rest.url('document:MySpace.MyPage')
1151 $services.rest.url('space:MySpace')
1152 {{/code}}
1153
1154 Where ##$entityReference## could be:
1155
1156 * a ##DocumentReference##
1157 * a ##SpaceReference##
1158
1159 We plan to add more supported entities in the future (ObjectReference, ClassReference, etc...).
1160
1161 = Using the RESTful API =
1162
1163 {{info}}
1164 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.)
1165 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.
1166 {{/info}}
1167
1168 == Tutorial ==
1169
1170 See [[this tutorial>>http://blog.fabio.mancinelli.me/2011/03/07/XWikis_RESTful_API.html]] by Fabio Mancinelli.
1171
1172 == Creating an XWiki Object ==
1173
1174 In this example we will use the [[curl>>http://curl.haxx.se/]] utility as the HTTP client.
1175
1176 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##.
1177
1178 So, on the command line, you have to do the following:
1179
1180 {{code}}
1181 $ curl -u Admin:admin
1182 -X POST
1183 -H "Content-type: application/xml"
1184 -H "Accept: application/xml"
1185 -d "@test.xml"
1186 http://localhost/xwiki/rest/wikis/xwiki/spaces/Test/pages/Test/objects
1187 {{/code}}
1188
1189 where ##test.xml## is:
1190
1191 {{code language="xml"}}
1192 <object xmlns="http://www.xwiki.org">
1193 <className>XWiki.TestClass</className>
1194 <property name="text">
1195 <value>Whatever you want to put here</value>
1196 </property>
1197 </object>
1198 {{/code}}
1199
1200 Alternatively you can use the less verbose ##application/x-www-form-urlencoded format##:
1201
1202 {{code}}
1203 $ curl -u Admin:admin
1204 -X POST
1205 -H "Content-type: application/x-www-form-urlencoded"
1206 -H "Accept: application/xml"
1207 -d "@test.txt"
1208 http://localhost/xwiki/rest/wikis/xwiki/spaces/Test/pages/Test/objects
1209 {{/code}}
1210
1211 where ##test.txt## contains something like:
1212
1213 {{code}}
1214 className=XWiki.TestClass&property#test=Whatever+you+want
1215 {{/code}}
1216
1217 Or, better, you can use directly curl to specify these parameters
1218 using multiple ##-d## switches:
1219
1220 {{code}}
1221 $ curl -u Admin:admin
1222 -X POST -H "Content-type: application/x-www-form-urlencoded"
1223 -H "Accept: application/xml"
1224 -d "className=XWiki.TestClass"
1225 -d "property#test=Whatever you want"
1226 http://localhost/xwiki/rest/wikis/xwiki/spaces/Test/pages/Test/objects
1227 {{/code}}
1228
1229 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.
1230
1231 === Remarks: ===
1232
1233 * 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.
1234
1235 * The information you get back when you retrieve an object (i.e., all
1236 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.
1237
1238 * 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.
1239
1240 == Formats of files ==
1241
1242 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).
1243
1244 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.
1245
1246 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.
1247
1248 === Example of a file for a ##wiki## ===
1249
1250 {{code language="xml"}}
1251
1252 <wiki xmlns="http://www.xwiki.org">
1253 <id>xwiki</id>
1254 <name>xwiki</name>
1255 <description>Some description of the wiki</description>
1256 <owner>Admin</owner>
1257 </wiki>
1258 {{/code}}
1259
1260 === Example of a file for a ##space## ===
1261
1262 {{code language="xml"}}
1263 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1264 <space xmlns="http://www.xwiki.org">
1265 <id>xwiki:Main</id>
1266 <wiki>xwiki</wiki>
1267 <name>Main</name>
1268 <home>xwiki:Main.WebHome</home>
1269 <xwikiRelativeUrl>http://localhost:8080/xwiki/bin/view/Main/</xwikiRelativeUrl>
1270 <xwikiAbsoluteUrl>http://localhost:8080/xwiki/bin/view/Main/</xwikiAbsoluteUrl>
1271 </space>
1272 {{/code}}
1273
1274 === Example of a file for a ##page## ===
1275
1276 {{code language="xml"}}
1277 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1278 <page xmlns="http://www.xwiki.org">
1279 <id>xwiki:Main.WebHome</id>
1280 <fullName>Main.WebHome</fullName>
1281 <wiki>xwiki</wiki>
1282 <space>Main</space>
1283 <name>WebHome</name>
1284 <title>Home</title>
1285 <parent></parent>
1286 <parentId></parentId>
1287 <version>1.1</version>
1288 <author>XWiki.Admin</author>
1289 <authorName>Administrator</authorName>
1290 <xwikiRelativeUrl>http://localhost:8080/xwiki/bin/view/Main/</xwikiRelativeUrl>
1291 <xwikiAbsoluteUrl>http://localhost:8080/xwiki/bin/view/Main/</xwikiAbsoluteUrl>
1292 <translations></translations>
1293 <syntax>xwiki/2.0</syntax>
1294 <language></language>
1295 <majorVersion>1</majorVersion>
1296 <minorVersion>1</minorVersion>
1297 <hidden>false</hidden>
1298 <created>2009-09-09T02:00:00+02:00</created>
1299 <creator>XWiki.Admin</creator>
1300 <creatorName>Administrator</creatorName>
1301 <modified>2015-10-29T11:19:02+01:00</modified>
1302 <modifier>XWiki.Admin</modifier>
1303 <modifierName>Administrator</modifierName>
1304 <comment>Imported from XAR</comment>
1305 <content>{{include reference="Dashboard.WebHome" context="new"/}}</content>
1306 </page>
1307 {{/code}}
1308
1309 === Example of a file for a ##tag## ===
1310
1311 {{code language="xml"}}
1312 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1313 <tags xmlns="http://www.xwiki.org">
1314 <tag name="food"></tag>
1315 </tags>
1316 {{/code}}
1317
1318 === Example of a file for a ##comment## ===
1319
1320 {{code language="xml"}}
1321 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1322 <comments xmlns="http://www.xwiki.org">
1323 <comment>
1324 <id>0</id>
1325 <pageId>xwiki:Main.WebHome</pageId>
1326 <author>XWiki.Admin</author>
1327 <authorName>Administrator</authorName>
1328 <date>2015-11-13T18:20:51.936+01:00</date>
1329 <highlight></highlight>
1330 <text>This is a comment</text>
1331 <replyTo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"></replyTo>
1332 </comment>
1333 </comments>
1334 {{/code}}
1335
1336 === Example of a file for an ##object## ===
1337
1338 {{code language="xml"}}
1339 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1340 <object xmlns="http://www.xwiki.org">
1341 <id>xwiki:Main.WebHome:c170a0a8-cc17-41cd-aa1e-6f6faf1d9f28</id>
1342 <guid>c170a0a8-cc17-41cd-aa1e-6f6faf1d9f28</guid>
1343 <pageId>xwiki:Main.WebHome</pageId>
1344 <pageVersion>1.1</pageVersion>
1345 <wiki>xwiki</wiki>
1346 <space>Main</space>
1347 <pageName>WebHome</pageName>
1348 <pageAuthor>XWiki.superadmin</pageAuthor>
1349 <className>XWiki.EditModeClass</className>
1350 <number>0</number>
1351 <headline>edit</headline>
1352 <property name="defaultEditMode" type="String">
1353 <attribute name="name" value="defaultEditMode"></attribute>
1354 <attribute name="prettyName" value="Default Edit Mode"></attribute>
1355 <attribute name="unmodifiable" value="0"></attribute>
1356 <attribute name="disabled" value="0"></attribute>
1357 <attribute name="size" value="15"></attribute>
1358 <attribute name="number" value="1"></attribute>
1359 <value>edit</value>
1360 </property>
1361 </object>
1362 {{/code}}
1363
1364 === Example of a file for a ##property## ===
1365
1366 {{code language="xml"}}
1367 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1368 <property xmlns="http://www.xwiki.org" name="defaultEditMode" type="String">
1369 <attribute name="name" value="defaultEditMode"></attribute>
1370 <attribute name="prettyName" value="Default Edit Mode"></attribute>
1371 <attribute name="unmodifiable" value="0"></attribute>
1372 <attribute name="disabled" value="0"></attribute>
1373 <attribute name="size" value="15"></attribute>
1374 <attribute name="number" value="1"></attribute>
1375 <value>edit</value>
1376 </property>
1377 {{/code}}
1378
1379 = Examples =
1380
1381 == Getting the list of users ==
1382
1383 Since Users are stored as Objects, you can do a search of the type ##XWiki.XWikiUsers##. For example:
1384
1385 {{code}}
1386 http://<server>/xwiki/rest/wikis/query?q=object:XWiki.XWikiUsers
1387 {{/code}}
1388
1389 == Getting the list of users using XWQL ==
1390
1391 Using the parameter "className" the result includes the data for the first object of the ##XWiki.XWikiUsers##:
1392
1393 {{code}}
1394 http://<server>/xwiki/rest/wikis/xwiki/query?q=,doc.object(XWiki.XWikiUsers) as obj&type=xwql&className=XWiki.XWikiUsers
1395 {{/code}}

Get Connected