Wiki source code of REST API

Version 99.1 by slauriere on 2024/09/11

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

Get Connected