Mercurial > public > src > rhodecode
annotate docs/api/api.rst @ 1994:f2bd5b0c1094 beta
create user api_doc update
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Tue, 17 Jan 2012 20:51:42 +0200 |
parents | 0771f0f5ab28 |
children | 0bd97250cd36 |
rev | line source |
---|---|
1526 | 1 .. _api: |
2 | |
3 | |
4 API | |
5 === | |
6 | |
7 | |
8 Starting from RhodeCode version 1.2 a simple API was implemented. | |
1580 | 9 There's a single schema for calling all api methods. API is implemented |
1676 | 10 with JSON protocol both ways. An url to send API request in RhodeCode is |
1580 | 11 <your_server>/_admin/api |
1526 | 12 |
1924 | 13 API ACCESS FOR WEB VIEWS |
14 ++++++++++++++++++++++++ | |
1526 | 15 |
1896
320dec24fb9a
Added instruction on enabling the API access to web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1895
diff
changeset
|
16 API access can also be turned on for each view decorated with `@LoginRequired` |
320dec24fb9a
Added instruction on enabling the API access to web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1895
diff
changeset
|
17 decorator. To enable API access simple change standard login decorator into |
320dec24fb9a
Added instruction on enabling the API access to web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1895
diff
changeset
|
18 `@LoginRequired(api_access=True)`. After such a change view can be accessed |
320dec24fb9a
Added instruction on enabling the API access to web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1895
diff
changeset
|
19 by adding a GET parameter to url `?api_key=<api_key>`. By default it's only |
320dec24fb9a
Added instruction on enabling the API access to web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1895
diff
changeset
|
20 enabled on RSS/ATOM feed views. |
320dec24fb9a
Added instruction on enabling the API access to web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1895
diff
changeset
|
21 |
320dec24fb9a
Added instruction on enabling the API access to web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1895
diff
changeset
|
22 |
1924 | 23 API ACCESS |
24 ++++++++++ | |
25 | |
1793
fee9895fa46e
changed API to match fully JSON-RPC specs
Marcin Kuzminski <marcin@python-works.com>
parents:
1676
diff
changeset
|
26 All clients are required to send JSON-RPC spec JSON data:: |
1526 | 27 |
1793
fee9895fa46e
changed API to match fully JSON-RPC specs
Marcin Kuzminski <marcin@python-works.com>
parents:
1676
diff
changeset
|
28 { |
fee9895fa46e
changed API to match fully JSON-RPC specs
Marcin Kuzminski <marcin@python-works.com>
parents:
1676
diff
changeset
|
29 "id:<id>, |
1526 | 30 "api_key":"<api_key>", |
31 "method":"<method_name>", | |
32 "args":{"<arg_key>":"<arg_val>"} | |
33 } | |
34 | |
1580 | 35 Example call for autopulling remotes repos using curl:: |
1793
fee9895fa46e
changed API to match fully JSON-RPC specs
Marcin Kuzminski <marcin@python-works.com>
parents:
1676
diff
changeset
|
36 curl https://server.com/_admin/api -X POST -H 'content-type:text/plain' --data-binary '{"id":1,"api_key":"xe7cdb2v278e4evbdf5vs04v832v0efvcbcve4a3","method":"pull","args":{"repo":"CPython"}}' |
1580 | 37 |
1676 | 38 Simply provide |
1793
fee9895fa46e
changed API to match fully JSON-RPC specs
Marcin Kuzminski <marcin@python-works.com>
parents:
1676
diff
changeset
|
39 - *id* A value of any type, which is used to match the response with the request that it is replying to. |
1580 | 40 - *api_key* for access and permission validation. |
41 - *method* is name of method to call | |
42 - *args* is an key:value list of arguments to pass to method | |
1676 | 43 |
1526 | 44 .. note:: |
1676 | 45 |
46 api_key can be found in your user account page | |
47 | |
48 | |
1793
fee9895fa46e
changed API to match fully JSON-RPC specs
Marcin Kuzminski <marcin@python-works.com>
parents:
1676
diff
changeset
|
49 RhodeCode API will return always a JSON-RPC response:: |
1676 | 50 |
1793
fee9895fa46e
changed API to match fully JSON-RPC specs
Marcin Kuzminski <marcin@python-works.com>
parents:
1676
diff
changeset
|
51 { |
fee9895fa46e
changed API to match fully JSON-RPC specs
Marcin Kuzminski <marcin@python-works.com>
parents:
1676
diff
changeset
|
52 "id":<id>, |
1676 | 53 "result": "<result>", |
1526 | 54 "error": null |
55 } | |
56 | |
57 All responses from API will be `HTTP/1.0 200 OK`, if there's an error while | |
1676 | 58 calling api *error* key from response will contain failure description |
1526 | 59 and result will be null. |
60 | |
61 API METHODS | |
62 +++++++++++ | |
63 | |
1676 | 64 |
1526 | 65 pull |
66 ---- | |
67 | |
1676 | 68 Pulls given repo from remote location. Can be used to automatically keep |
69 remote repos up to date. This command can be executed only using api_key | |
1580 | 70 belonging to user with admin rights |
71 | |
72 INPUT:: | |
73 | |
1676 | 74 api_key : "<api_key>" |
75 method : "pull" | |
76 args : { | |
1928 | 77 "repo_name" : "<reponame>" |
1676 | 78 } |
79 | |
80 OUTPUT:: | |
81 | |
1928 | 82 result : "Pulled from <reponame>" |
1676 | 83 error : null |
84 | |
85 | |
1928 | 86 get_user |
87 -------- | |
88 | |
89 Get's an user by username, Returns empty result if user is not found. | |
90 This command can be executed only using api_key belonging to user with admin | |
91 rights. | |
92 | |
93 INPUT:: | |
94 | |
95 api_key : "<api_key>" | |
96 method : "get_user" | |
97 args : { | |
98 "username" : "<username>" | |
99 } | |
100 | |
101 OUTPUT:: | |
102 | |
103 result: None if user does not exist or | |
104 { | |
105 "id" : "<id>", | |
106 "username" : "<username>", | |
107 "firstname": "<firstname>", | |
108 "lastname" : "<lastname>", | |
109 "email" : "<email>", | |
110 "active" : "<bool>", | |
111 "admin" : "<bool>", | |
112 "ldap" : "<ldap_dn>" | |
113 } | |
114 | |
115 error: null | |
116 | |
117 | |
1676 | 118 get_users |
119 --------- | |
120 | |
121 Lists all existing users. This command can be executed only using api_key | |
122 belonging to user with admin rights. | |
123 | |
124 INPUT:: | |
125 | |
126 api_key : "<api_key>" | |
127 method : "get_users" | |
128 args : { } | |
129 | |
130 OUTPUT:: | |
131 | |
132 result: [ | |
133 { | |
134 "id" : "<id>", | |
135 "username" : "<username>", | |
136 "firstname": "<firstname>", | |
137 "lastname" : "<lastname>", | |
138 "email" : "<email>", | |
139 "active" : "<bool>", | |
140 "admin" : "<bool>", | |
141 "ldap" : "<ldap_dn>" | |
142 }, | |
143 … | |
144 ] | |
145 error: null | |
146 | |
147 create_user | |
148 ----------- | |
149 | |
1994
f2bd5b0c1094
create user api_doc update
Marcin Kuzminski <marcin@python-works.com>
parents:
1928
diff
changeset
|
150 Creates new user or updates current one if such user exists. This command can |
f2bd5b0c1094
create user api_doc update
Marcin Kuzminski <marcin@python-works.com>
parents:
1928
diff
changeset
|
151 be executed only using api_key belonging to user with admin rights. |
1676 | 152 |
153 INPUT:: | |
154 | |
155 api_key : "<api_key>" | |
156 method : "create_user" | |
157 args : { | |
158 "username" : "<username>", | |
159 "password" : "<password>", | |
160 "firstname" : "<firstname>", | |
161 "lastname" : "<lastname>", | |
162 "email" : "<useremail>" | |
163 "active" : "<bool> = True", | |
164 "admin" : "<bool> = False", | |
165 "ldap_dn" : "<ldap_dn> = None" | |
166 } | |
1580 | 167 |
168 OUTPUT:: | |
169 | |
1676 | 170 result: { |
1928 | 171 "id" : "<new_user_id>", |
1676 | 172 "msg" : "created new user <username>" |
173 } | |
174 error: null | |
175 | |
176 get_users_group | |
177 --------------- | |
178 | |
179 Gets an existing users group. This command can be executed only using api_key | |
180 belonging to user with admin rights. | |
181 | |
182 INPUT:: | |
183 | |
184 api_key : "<api_key>" | |
185 method : "get_users_group" | |
186 args : { | |
187 "group_name" : "<name>" | |
188 } | |
189 | |
190 OUTPUT:: | |
191 | |
192 result : None if group not exist | |
193 { | |
1928 | 194 "id" : "<id>", |
195 "group_name" : "<groupname>", | |
196 "active": "<bool>", | |
1676 | 197 "members" : [ |
1928 | 198 { "id" : "<userid>", |
199 "username" : "<username>", | |
200 "firstname": "<firstname>", | |
201 "lastname" : "<lastname>", | |
202 "email" : "<email>", | |
203 "active" : "<bool>", | |
204 "admin" : "<bool>", | |
205 "ldap" : "<ldap_dn>" | |
206 }, | |
207 … | |
208 ] | |
1676 | 209 } |
210 error : null | |
211 | |
1928 | 212 get_users_groups |
213 ---------------- | |
214 | |
215 Lists all existing users groups. This command can be executed only using | |
216 api_key belonging to user with admin rights. | |
217 | |
218 INPUT:: | |
219 | |
220 api_key : "<api_key>" | |
221 method : "get_users_groups" | |
222 args : { } | |
223 | |
224 OUTPUT:: | |
225 | |
226 result : [ | |
227 { | |
228 "id" : "<id>", | |
229 "group_name" : "<groupname>", | |
230 "active": "<bool>", | |
231 "members" : [ | |
232 { | |
233 "id" : "<userid>", | |
234 "username" : "<username>", | |
235 "firstname": "<firstname>", | |
236 "lastname" : "<lastname>", | |
237 "email" : "<email>", | |
238 "active" : "<bool>", | |
239 "admin" : "<bool>", | |
240 "ldap" : "<ldap_dn>" | |
241 }, | |
242 … | |
243 ] | |
244 } | |
245 ] | |
246 error : null | |
247 | |
248 | |
1580 | 249 create_users_group |
250 ------------------ | |
251 | |
1676 | 252 Creates new users group. This command can be executed only using api_key |
1580 | 253 belonging to user with admin rights |
254 | |
255 INPUT:: | |
256 | |
1676 | 257 api_key : "<api_key>" |
258 method : "create_users_group" | |
259 args: { | |
1928 | 260 "group_name": "<groupname>", |
1676 | 261 "active":"<bool> = True" |
262 } | |
263 | |
264 OUTPUT:: | |
265 | |
266 result: { | |
267 "id": "<newusersgroupid>", | |
1928 | 268 "msg": "created new users group <groupname>" |
1676 | 269 } |
270 error: null | |
271 | |
1878
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
272 add_user_to_users_group |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
273 ----------------------- |
1676 | 274 |
275 Adds a user to a users group. This command can be executed only using api_key | |
276 belonging to user with admin rights | |
277 | |
278 INPUT:: | |
279 | |
280 api_key : "<api_key>" | |
281 method : "add_user_users_group" | |
282 args: { | |
283 "group_name" : "<groupname>", | |
1895
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1878
diff
changeset
|
284 "username" : "<username>" |
1676 | 285 } |
286 | |
287 OUTPUT:: | |
288 | |
289 result: { | |
290 "id": "<newusersgroupmemberid>", | |
291 "msg": "created new users group member" | |
292 } | |
293 error: null | |
294 | |
1928 | 295 get_repo |
296 -------- | |
297 | |
298 Gets an existing repository. This command can be executed only using api_key | |
299 belonging to user with admin rights | |
300 | |
301 INPUT:: | |
302 | |
303 api_key : "<api_key>" | |
304 method : "get_repo" | |
305 args: { | |
306 "repo_name" : "<reponame>" | |
307 } | |
308 | |
309 OUTPUT:: | |
310 | |
311 result: None if repository does not exist or | |
312 { | |
313 "id" : "<id>", | |
314 "repo_name" : "<reponame>" | |
315 "type" : "<type>", | |
316 "description" : "<description>", | |
317 "members" : [ | |
318 { "id" : "<userid>", | |
319 "username" : "<username>", | |
320 "firstname": "<firstname>", | |
321 "lastname" : "<lastname>", | |
322 "email" : "<email>", | |
323 "active" : "<bool>", | |
324 "admin" : "<bool>", | |
325 "ldap" : "<ldap_dn>", | |
326 "permission" : "repository.(read|write|admin)" | |
327 }, | |
328 … | |
329 { | |
330 "id" : "<usersgroupid>", | |
331 "name" : "<usersgroupname>", | |
332 "active": "<bool>", | |
333 "permission" : "repository.(read|write|admin)" | |
334 }, | |
335 … | |
336 ] | |
337 } | |
338 error: null | |
339 | |
1676 | 340 get_repos |
341 --------- | |
342 | |
343 Lists all existing repositories. This command can be executed only using api_key | |
344 belonging to user with admin rights | |
345 | |
346 INPUT:: | |
347 | |
348 api_key : "<api_key>" | |
349 method : "get_repos" | |
350 args: { } | |
1580 | 351 |
352 OUTPUT:: | |
353 | |
1676 | 354 result: [ |
355 { | |
356 "id" : "<id>", | |
1928 | 357 "repo_name" : "<reponame>" |
1676 | 358 "type" : "<type>", |
359 "description" : "<description>" | |
360 }, | |
361 … | |
362 ] | |
363 error: null | |
364 | |
365 | |
1895
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1878
diff
changeset
|
366 get_repo_nodes |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1878
diff
changeset
|
367 -------------- |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1878
diff
changeset
|
368 |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1878
diff
changeset
|
369 returns a list of nodes and it's children in a flat list for a given path |
1928 | 370 at given revision. It's possible to specify ret_type to show only `files` or |
371 `dirs`. This command can be executed only using api_key belonging to user | |
1895
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1878
diff
changeset
|
372 with admin rights |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1878
diff
changeset
|
373 |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1878
diff
changeset
|
374 INPUT:: |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1878
diff
changeset
|
375 |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1878
diff
changeset
|
376 api_key : "<api_key>" |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1878
diff
changeset
|
377 method : "get_repo_nodes" |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1878
diff
changeset
|
378 args: { |
1928 | 379 "repo_name" : "<reponame>", |
1895
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1878
diff
changeset
|
380 "revision" : "<revision>", |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1878
diff
changeset
|
381 "root_path" : "<root_path>", |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1878
diff
changeset
|
382 "ret_type" : "<ret_type>" = 'all' |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1878
diff
changeset
|
383 } |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1878
diff
changeset
|
384 |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1878
diff
changeset
|
385 OUTPUT:: |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1878
diff
changeset
|
386 |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1878
diff
changeset
|
387 result: [ |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1878
diff
changeset
|
388 { |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1878
diff
changeset
|
389 "name" : "<name>" |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1878
diff
changeset
|
390 "type" : "<type>", |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1878
diff
changeset
|
391 }, |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1878
diff
changeset
|
392 … |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1878
diff
changeset
|
393 ] |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1878
diff
changeset
|
394 error: null |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1878
diff
changeset
|
395 |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1878
diff
changeset
|
396 |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1878
diff
changeset
|
397 |
1676 | 398 create_repo |
399 ----------- | |
400 | |
401 Creates a repository. This command can be executed only using api_key | |
402 belonging to user with admin rights. | |
403 If repository name contains "/", all needed repository groups will be created. | |
404 For example "foo/bar/baz" will create groups "foo", "bar" (with "foo" as parent), | |
405 and create "baz" repository with "bar" as group. | |
406 | |
407 INPUT:: | |
408 | |
409 api_key : "<api_key>" | |
410 method : "create_repo" | |
411 args: { | |
1928 | 412 "repo_name" : "<reponame>", |
1676 | 413 "owner_name" : "<ownername>", |
414 "description" : "<description> = ''", | |
415 "repo_type" : "<type> = 'hg'", | |
416 "private" : "<bool> = False" | |
417 } | |
418 | |
419 OUTPUT:: | |
420 | |
1928 | 421 result: { |
422 "id": "<newrepoid>", | |
423 "msg": "Created new repository <reponame>", | |
424 } | |
1676 | 425 error: null |
426 | |
427 add_user_to_repo | |
428 ---------------- | |
429 | |
430 Add a user to a repository. This command can be executed only using api_key | |
431 belonging to user with admin rights. | |
432 If "perm" is None, user will be removed from the repository. | |
433 | |
434 INPUT:: | |
435 | |
436 api_key : "<api_key>" | |
437 method : "add_user_to_repo" | |
438 args: { | |
439 "repo_name" : "<reponame>", | |
1928 | 440 "username" : "<username>", |
1878
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
441 "perm" : "(None|repository.(read|write|admin))", |
1676 | 442 } |
443 | |
444 OUTPUT:: | |
445 | |
1928 | 446 result: { |
447 "msg" : "Added perm: <perm> for <username> in repo: <reponame>" | |
448 } | |
1676 | 449 error: null |
1878
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
450 |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
451 add_users_group_to_repo |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
452 ----------------------- |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
453 |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
454 Add a users group to a repository. This command can be executed only using |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
455 api_key belonging to user with admin rights. If "perm" is None, group will |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
456 be removed from the repository. |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
457 |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
458 INPUT:: |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
459 |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
460 api_key : "<api_key>" |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
461 method : "add_users_group_to_repo" |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
462 args: { |
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
463 "repo_name" : "<reponame>", |
1928 | 464 "group_name" : "<groupname>", |
1878
631caf880b87
implements #329
Marcin Kuzminski <marcin@python-works.com>
parents:
1793
diff
changeset
|
465 "perm" : "(None|repository.(read|write|admin))", |
1928 | 466 } |
467 OUTPUT:: | |
468 | |
469 result: { | |
470 "msg" : Added perm: <perm> for <groupname> in repo: <reponame>" | |
471 } | |
472 |