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