Wiki source code of REST API

Version 91.2 by Sergei Kulagin on 2022/12/04

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

Get Connected