blob: bedf21808e6c5c939134c7945588c788e5d885fd [file] [log] [blame]
Shawn O. Pearceec9efd72012-04-04 20:44:39 -07001Gerrit Code Review - REST API
2=============================
3
4Gerrit Code Review comes with a REST like API available over HTTP.
5The API is suitable for automated tools to build upon, as well as
6supporting some ad-hoc scripting use cases.
7
David Pursehouseed321322013-05-17 13:53:32 +01008See also: link:dev-rest-api.html[REST API Developers' Notes].
David Pursehouse567e57b2013-05-07 16:41:48 +01009
Edwin Kempin361ed762013-04-03 13:52:24 +020010Endpoints
11---------
Edwin Kempin87340e62013-06-24 16:46:34 +020012link:rest-api-access.html[/access/]::
13 Access Right related REST endpoints
Edwin Kempin361ed762013-04-03 13:52:24 +020014link:rest-api-accounts.html[/accounts/]::
15 Account related REST endpoints
16link:rest-api-changes.html[/changes/]::
17 Change related REST endpoints
David Ostrovsky28b8ea62013-06-09 02:16:57 +020018link:rest-api-config.html[/config/]::
19 Config related REST endpoints
Edwin Kempin361ed762013-04-03 13:52:24 +020020link:rest-api-groups.html[/groups/]::
21 Group related REST endpoints
Edwin Kempin36eeee22013-08-30 15:57:34 +020022link:rest-api-plugins.html[/plugins/]::
23 Plugin related REST endpoints
Edwin Kempin361ed762013-04-03 13:52:24 +020024link:rest-api-projects.html[/projects/]::
25 Project related REST endpoints
Yuxuan 'fishy' Wangec4b06a2013-10-14 12:39:30 -070026link:rest-api-documentation.html[/Documentation/]::
27 Documentation related REST endpoints
Edwin Kempin361ed762013-04-03 13:52:24 +020028
Shawn O. Pearceec9efd72012-04-04 20:44:39 -070029Protocol Details
30----------------
31
Edwin Kempind089fc42012-07-18 14:58:40 +020032[[authentication]]
Shawn O. Pearceec9efd72012-04-04 20:44:39 -070033Authentication
34~~~~~~~~~~~~~~
35By default all REST endpoints assume anonymous access and filter
36results to correspond to what anonymous users can read (which may
37be nothing at all).
38
39Users (and programs) may authenticate using HTTP authentication by
40supplying the HTTP password from the user's account settings page.
41Gerrit by default uses HTTP digest authentication. To authenticate,
42prefix the endpoint URL with `/a/`. For example to authenticate to
43`/projects/` request URL `/a/projects/`.
44
Shawn Pearcea90a43a2013-01-26 12:50:56 -080045[[preconditions]]
46Preconditions
47~~~~~~~~~~~~~
48Clients can request PUT to create a new resource and not overwrite
49an existing one by adding `If-None-Match: *` to the request HTTP
50headers. If the named resource already exists the server will respond
51with HTTP 412 Precondition Failed.
52
Edwin Kempind089fc42012-07-18 14:58:40 +020053[[output]]
Shawn O. Pearceec9efd72012-04-04 20:44:39 -070054Output Format
55~~~~~~~~~~~~~
Shawn O. Pearceea6d0b52012-11-16 10:57:31 -080056Most APIs return pretty printed JSON by default. Compact JSON can be
57requested by setting the `Accept` HTTP request header to include
Shawn O. Pearceec9efd72012-04-04 20:44:39 -070058`application/json`, for example:
59
60----
61 GET /projects/ HTTP/1.0
62 Accept: application/json
63----
64
65JSON responses are encoded using UTF-8 and use content type
David Pursehousef6c0bec2013-08-26 16:31:51 +090066`application/json`.
67
68To prevent against Cross Site Script Inclusion (XSSI) attacks, the JSON
69response body starts with a magic prefix line that must be stripped before
70feeding the rest of the response body to a JSON parser:
Shawn O. Pearceec9efd72012-04-04 20:44:39 -070071
72----
73 )]}'
74 [ ... valid JSON ... ]
75----
76
Shawn O. Pearceea6d0b52012-11-16 10:57:31 -080077The default JSON format is pretty, which uses extra whitespace to make
78the output more readable for a human. Producing (and parsing) the
79non-pretty compact format is more efficient so tools should request it
80by using the `Accept: application/json` header or `pp=0` query
81parameter whenever possible.
Shawn O. Pearceec9efd72012-04-04 20:44:39 -070082
83Responses will be gzip compressed by the server if the HTTP
84`Accept-Encoding` request header is set to `gzip`. This may
85save on network transfer time for larger responses.
86
Edwin Kempine3446292013-02-19 16:40:14 +010087[[timestamp]]
88Timestamp
89~~~~~~~~~
90Timestamps are given in UTC and have the format
91"'yyyy-mm-dd hh:mm:ss.fffffffff'" where "'ffffffffff'" indicates the
92nanoseconds.
93
Edwin Kempin7fe2f7f2013-02-06 10:12:52 +010094[[encoding]]
95Encoding
96~~~~~~~~
97All IDs that appear in the URL of a REST call (e.g. project name, group name)
98must be URL encoded.
99
Edwin Kempine026a7d2013-03-13 11:03:42 +0100100[[response-codes]]
101Response Codes
102~~~~~~~~~~~~~~
103HTTP status codes are well defined and the Gerrit REST endpoints use
104them as described in the HTTP spec.
105
106Here are examples for some HTTP status codes that show how they are
107used in the context of the Gerrit REST API.
108
109400 Bad Request
110^^^^^^^^^^^^^^^
111`400 Bad Request` is used if the request is not understood by the
112server due to malformed syntax.
113
114E.g. `400 Bad Request` is returned if JSON input is expected but the
115'Content-Type' of the request is not 'application/json' or the request
116body doesn't contain valid JSON.
117
118`400 Bad Request` is also used if required input fields are not set or
119if options are set which cannot be used together.
120
121403 Forbidden
122^^^^^^^^^^^^^
123`403 Forbidden` is used if the operation is not allowed because the
124calling user has no sufficient permissions.
125
126E.g. some REST endpoints require that the calling user has certain
David Pursehouse8becc2a2013-04-23 18:51:04 +0900127link:access-control.html#global_capabilities[global capabilities]
Edwin Kempine026a7d2013-03-13 11:03:42 +0100128assigned.
129
130`403 Forbidden` is also used if `self` is used as account ID and the
131REST call was done without authentication.
132
133404 Not Found
134^^^^^^^^^^^^^
135`404 Not Found` is returned if the resource that is specified by the
136URL is not found or is not visible to the calling user. A resource
137cannot be found if the URL contains a non-existing ID or view.
138
139405 Method Not Allowed
140^^^^^^^^^^^^^^^^^^^^^^
141`405 Method Not Allowed` is used if the resource exists but doesn't
142support the operation.
143
144E.g. some of the `/groups/` endpoints are only supported for Gerrit
145internal groups, if they are invoked for an external group the response
146is `405 Method Not Allowed`.
147
148409 Conflict
149^^^^^^^^^^^^
150`409 Conflict` is used if the request cannot be completed because the
151current state of the resource doesn't allow the operation.
152
153E.g. if you try to submit a change that is abandoned, this fails with
154`409 Conflict` because the state of the change doesn't allow the submit
155operation.
156
157`409 Conflict` is also used if you try to create a resource but the
158name is already occupied by an existing resource.
159
160412 Precondition Failed
161^^^^^^^^^^^^^^^^^^^^^^^
162`412 Precondition Failed` is used if a precondition from the request
163header fields is not fulfilled as described in the link:#preconditions[
164Preconditions] section.
165
166422 Unprocessable Entity
167^^^^^^^^^^^^^^^^^^^^^^^^
168`422 Unprocessable Entity` is returned if the ID of a resource that is
169specified in the request body cannot be resolved.
170
Shawn O. Pearceec9efd72012-04-04 20:44:39 -0700171GERRIT
172------
173Part of link:index.html[Gerrit Code Review]
Yuxuan 'fishy' Wang99cb68d2013-10-31 17:26:00 -0700174
175SEARCHBOX
176---------