##// END OF EJS Templates
API docs improvement....
marcink -
r2143:c1f1f066 beta
parent child Browse files
Show More
@@ -1,627 +1,646 b''
1 1 .. _api:
2 2
3 3 ===
4 4 API
5 5 ===
6 6
7 7
8 8 Starting from RhodeCode version 1.2 a simple API was implemented.
9 9 There's a single schema for calling all api methods. API is implemented
10 10 with JSON protocol both ways. An url to send API request in RhodeCode is
11 11 <your_server>/_admin/api
12 12
13 13 API ACCESS FOR WEB VIEWS
14 14 ++++++++++++++++++++++++
15 15
16 16 API access can also be turned on for each web view in RhodeCode that is
17 17 decorated with `@LoginRequired` decorator. To enable API access simple change
18 18 the standard login decorator to `@LoginRequired(api_access=True)`.
19 19 After this change, a rhodecode view can be accessed without login by adding a
20 20 GET parameter `?api_key=<api_key>` to url. By default this is only
21 21 enabled on RSS/ATOM feed views.
22 22
23 23
24 24 API ACCESS
25 25 ++++++++++
26 26
27 27 All clients are required to send JSON-RPC spec JSON data::
28 28
29 29 {
30 "id:<id>,
30 "id:"<id>",
31 31 "api_key":"<api_key>",
32 32 "method":"<method_name>",
33 33 "args":{"<arg_key>":"<arg_val>"}
34 34 }
35 35
36 36 Example call for autopulling remotes repos using curl::
37 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"}}'
38 38
39 39 Simply provide
40 40 - *id* A value of any type, which is used to match the response with the request that it is replying to.
41 41 - *api_key* for access and permission validation.
42 42 - *method* is name of method to call
43 43 - *args* is an key:value list of arguments to pass to method
44 44
45 45 .. note::
46 46
47 47 api_key can be found in your user account page
48 48
49 49
50 50 RhodeCode API will return always a JSON-RPC response::
51 51
52 52 {
53 "id":<id>,
54 "result": "<result>",
55 "error": null
53 "id":<id>, # matching id sent by request
54 "result": "<result>"|null, # JSON formatted result, null if any errors
55 "error": "null"|<error_message> # JSON formatted error (if any)
56 56 }
57 57
58 58 All responses from API will be `HTTP/1.0 200 OK`, if there's an error while
59 59 calling api *error* key from response will contain failure description
60 60 and result will be null.
61 61
62 62 API METHODS
63 63 +++++++++++
64 64
65 65
66 66 pull
67 67 ----
68 68
69 69 Pulls given repo from remote location. Can be used to automatically keep
70 70 remote repos up to date. This command can be executed only using api_key
71 71 belonging to user with admin rights
72 72
73 73 INPUT::
74 74
75 id : <id_for_response>
75 76 api_key : "<api_key>"
76 77 method : "pull"
77 78 args : {
78 79 "repo_name" : "<reponame>"
79 80 }
80 81
81 82 OUTPUT::
82 83
83 84 result : "Pulled from <reponame>"
84 85 error : null
85 86
86 87
87 88 get_user
88 89 --------
89 90
90 91 Get's an user by username or user_id, Returns empty result if user is not found.
91 92 This command can be executed only using api_key belonging to user with admin
92 93 rights.
93 94
94 95
95 96 INPUT::
96 97
98 id : <id_for_response>
97 99 api_key : "<api_key>"
98 100 method : "get_user"
99 101 args : {
100 102 "userid" : "<username or user_id>"
101 103 }
102 104
103 105 OUTPUT::
104 106
105 107 result: None if user does not exist or
106 108 {
107 109 "id" : "<id>",
108 110 "username" : "<username>",
109 111 "firstname": "<firstname>",
110 112 "lastname" : "<lastname>",
111 113 "email" : "<email>",
112 114 "active" : "<bool>",
113 115 "admin" :Β  "<bool>",
114 116 "ldap_dn" : "<ldap_dn>"
115 117 }
116 118
117 119 error: null
118 120
119 121
120 122 get_users
121 123 ---------
122 124
123 125 Lists all existing users. This command can be executed only using api_key
124 126 belonging to user with admin rights.
125 127
126 128
127 129 INPUT::
128 130
131 id : <id_for_response>
129 132 api_key : "<api_key>"
130 133 method : "get_users"
131 134 args : { }
132 135
133 136 OUTPUT::
134 137
135 138 result: [
136 139 {
137 140 "id" : "<id>",
138 141 "username" : "<username>",
139 142 "firstname": "<firstname>",
140 143 "lastname" : "<lastname>",
141 144 "email" : "<email>",
142 145 "active" : "<bool>",
143 146 "admin" :Β  "<bool>",
144 147 "ldap_dn" : "<ldap_dn>"
145 148 },
146 149 …
147 150 ]
148 151 error: null
149 152
150 153
151 154 create_user
152 155 -----------
153 156
154 157 Creates new user. This command can
155 158 be executed only using api_key belonging to user with admin rights.
156 159
157 160
158 161 INPUT::
159 162
163 id : <id_for_response>
160 164 api_key : "<api_key>"
161 165 method : "create_user"
162 166 args : {
163 167 "username" : "<username>",
164 168 "password" : "<password>",
165 169 "email" : "<useremail>",
166 170 "firstname" : "<firstname> = None",
167 171 "lastname" : "<lastname> = None",
168 172 "active" : "<bool> = True",
169 173 "admin" : "<bool> = False",
170 174 "ldap_dn" : "<ldap_dn> = None"
171 175 }
172 176
173 177 OUTPUT::
174 178
175 179 result: {
176 180 "id" : "<new_user_id>",
177 181 "msg" : "created new user <username>"
178 182 }
179 183 error: null
180 184
181 185
182 186 update_user
183 187 -----------
184 188
185 189 updates current one if such user exists. This command can
186 190 be executed only using api_key belonging to user with admin rights.
187 191
188 192
189 193 INPUT::
190 194
195 id : <id_for_response>
191 196 api_key : "<api_key>"
192 197 method : "update_user"
193 198 args : {
194 199 "userid" : "<user_id or username>",
195 200 "username" : "<username>",
196 201 "password" : "<password>",
197 202 "email" : "<useremail>",
198 203 "firstname" : "<firstname>",
199 204 "lastname" : "<lastname>",
200 205 "active" : "<bool>",
201 206 "admin" : "<bool>",
202 207 "ldap_dn" : "<ldap_dn>"
203 208 }
204 209
205 210 OUTPUT::
206 211
207 212 result: {
208 213 "id" : "<edited_user_id>",
209 214 "msg" : "updated user <username>"
210 215 }
211 216 error: null
212 217
213 218
214 219 get_users_group
215 220 ---------------
216 221
217 222 Gets an existing users group. This command can be executed only using api_key
218 223 belonging to user with admin rights.
219 224
220 225
221 226 INPUT::
222 227
228 id : <id_for_response>
223 229 api_key : "<api_key>"
224 230 method : "get_users_group"
225 231 args : {
226 232 "group_name" : "<name>"
227 233 }
228 234
229 235 OUTPUT::
230 236
231 237 result : None if group not exist
232 238 {
233 239 "id" : "<id>",
234 240 "group_name" : "<groupname>",
235 241 "active": "<bool>",
236 242 "members" : [
237 243 { "id" : "<userid>",
238 244 "username" : "<username>",
239 245 "firstname": "<firstname>",
240 246 "lastname" : "<lastname>",
241 247 "email" : "<email>",
242 248 "active" : "<bool>",
243 249 "admin" :Β  "<bool>",
244 250 "ldap" : "<ldap_dn>"
245 251 },
246 252 …
247 253 ]
248 254 }
249 255 error : null
250 256
251 257
252 258 get_users_groups
253 259 ----------------
254 260
255 261 Lists all existing users groups. This command can be executed only using
256 262 api_key belonging to user with admin rights.
257 263
258 264
259 265 INPUT::
260 266
267 id : <id_for_response>
261 268 api_key : "<api_key>"
262 269 method : "get_users_groups"
263 270 args : { }
264 271
265 272 OUTPUT::
266 273
267 274 result : [
268 275 {
269 276 "id" : "<id>",
270 277 "group_name" : "<groupname>",
271 278 "active": "<bool>",
272 279 "members" : [
273 280 {
274 281 "id" : "<userid>",
275 282 "username" : "<username>",
276 283 "firstname": "<firstname>",
277 284 "lastname" : "<lastname>",
278 285 "email" : "<email>",
279 286 "active" : "<bool>",
280 287 "admin" :Β  "<bool>",
281 288 "ldap" : "<ldap_dn>"
282 289 },
283 290 …
284 291 ]
285 292 }
286 293 ]
287 294 error : null
288 295
289 296
290 297 create_users_group
291 298 ------------------
292 299
293 300 Creates new users group. This command can be executed only using api_key
294 301 belonging to user with admin rights
295 302
296 303
297 304 INPUT::
298 305
306 id : <id_for_response>
299 307 api_key : "<api_key>"
300 308 method : "create_users_group"
301 309 args: {
302 310 "group_name": "<groupname>",
303 311 "active":"<bool> = True"
304 312 }
305 313
306 314 OUTPUT::
307 315
308 316 result: {
309 317 "id": "<newusersgroupid>",
310 318 "msg": "created new users group <groupname>"
311 319 }
312 320 error: null
313 321
314 322
315 323 add_user_to_users_group
316 324 -----------------------
317 325
318 326 Adds a user to a users group. If user exists in that group success will be
319 327 `false`. This command can be executed only using api_key
320 328 belonging to user with admin rights
321 329
322 330
323 331 INPUT::
324 332
333 id : <id_for_response>
325 334 api_key : "<api_key>"
326 335 method : "add_user_users_group"
327 336 args: {
328 337 "group_name" : "<groupname>",
329 338 "username" : "<username>"
330 339 }
331 340
332 341 OUTPUT::
333 342
334 343 result: {
335 344 "id": "<newusersgroupmemberid>",
336 345 "success": True|False # depends on if member is in group
337 346 "msg": "added member <username> to users group <groupname> |
338 347 User is already in that group"
339 348 }
340 349 error: null
341 350
342 351
343 352 remove_user_from_users_group
344 353 ----------------------------
345 354
346 355 Removes a user from a users group. If user is not in given group success will
347 356 be `false`. This command can be executed only
348 357 using api_key belonging to user with admin rights
349 358
350 359
351 360 INPUT::
352 361
362 id : <id_for_response>
353 363 api_key : "<api_key>"
354 364 method : "remove_user_from_users_group"
355 365 args: {
356 366 "group_name" : "<groupname>",
357 367 "username" : "<username>"
358 368 }
359 369
360 370 OUTPUT::
361 371
362 372 result: {
363 373 "success": True|False, # depends on if member is in group
364 374 "msg": "removed member <username> from users group <groupname> |
365 375 User wasn't in group"
366 376 }
367 377 error: null
368 378
369 379
370 380 get_repo
371 381 --------
372 382
373 383 Gets an existing repository by it's name or repository_id. This command can
374 384 be executed only using api_key belonging to user with admin rights.
375 385
376 386
377 387 INPUT::
378 388
389 id : <id_for_response>
379 390 api_key : "<api_key>"
380 391 method : "get_repo"
381 392 args: {
382 393 "repoid" : "<reponame or repo_id>"
383 394 }
384 395
385 396 OUTPUT::
386 397
387 398 result: None if repository does not exist or
388 399 {
389 400 "id" : "<id>",
390 401 "repo_name" : "<reponame>"
391 402 "type" : "<type>",
392 403 "description" : "<description>",
393 404 "members" : [
394 405 { "id" : "<userid>",
395 406 "username" : "<username>",
396 407 "firstname": "<firstname>",
397 408 "lastname" : "<lastname>",
398 409 "email" : "<email>",
399 410 "active" : "<bool>",
400 411 "admin" :Β  "<bool>",
401 412 "ldap" : "<ldap_dn>",
402 413 "permission" : "repository.(read|write|admin)"
403 414 },
404 415 …
405 416 {
406 417 "id" : "<usersgroupid>",
407 418 "name" : "<usersgroupname>",
408 419 "active": "<bool>",
409 420 "permission" : "repository.(read|write|admin)"
410 421 },
411 422 …
412 423 ]
413 424 }
414 425 error: null
415 426
416 427
417 428 get_repos
418 429 ---------
419 430
420 431 Lists all existing repositories. This command can be executed only using api_key
421 432 belonging to user with admin rights
422 433
423 434
424 435 INPUT::
425 436
437 id : <id_for_response>
426 438 api_key : "<api_key>"
427 439 method : "get_repos"
428 440 args: { }
429 441
430 442 OUTPUT::
431 443
432 444 result: [
433 445 {
434 446 "id" : "<id>",
435 447 "repo_name" : "<reponame>"
436 448 "type" : "<type>",
437 449 "description" : "<description>"
438 450 },
439 451 …
440 452 ]
441 453 error: null
442 454
443 455
444 456 get_repo_nodes
445 457 --------------
446 458
447 459 returns a list of nodes and it's children in a flat list for a given path
448 460 at given revision. It's possible to specify ret_type to show only `files` or
449 461 `dirs`. This command can be executed only using api_key belonging to user
450 462 with admin rights
451 463
452 464
453 465 INPUT::
454 466
467 id : <id_for_response>
455 468 api_key : "<api_key>"
456 469 method : "get_repo_nodes"
457 470 args: {
458 471 "repo_name" : "<reponame>",
459 472 "revision" : "<revision>",
460 473 "root_path" : "<root_path>",
461 474 "ret_type" : "<ret_type>" = 'all'
462 475 }
463 476
464 477 OUTPUT::
465 478
466 479 result: [
467 480 {
468 481 "name" : "<name>"
469 482 "type" : "<type>",
470 483 },
471 484 …
472 485 ]
473 486 error: null
474 487
475 488
476 489 create_repo
477 490 -----------
478 491
479 492 Creates a repository. This command can be executed only using api_key
480 493 belonging to user with admin rights.
481 494 If repository name contains "/", all needed repository groups will be created.
482 495 For example "foo/bar/baz" will create groups "foo", "bar" (with "foo" as parent),
483 496 and create "baz" repository with "bar" as group.
484 497
485 498
486 499 INPUT::
487 500
501 id : <id_for_response>
488 502 api_key : "<api_key>"
489 503 method : "create_repo"
490 504 args: {
491 505 "repo_name" : "<reponame>",
492 506 "owner_name" : "<ownername>",
493 507 "description" : "<description> = ''",
494 508 "repo_type" : "<type> = 'hg'",
495 509 "private" : "<bool> = False",
496 510 "clone_uri" : "<clone_uri> = None",
497 511 }
498 512
499 513 OUTPUT::
500 514
501 515 result: {
502 516 "id": "<newrepoid>",
503 517 "msg": "Created new repository <reponame>",
504 518 }
505 519 error: null
506 520
507 521
508 522 delete_repo
509 523 -----------
510 524
511 525 Deletes a repository. This command can be executed only using api_key
512 526 belonging to user with admin rights.
513 527
514 528
515 529 INPUT::
516 530
531 id : <id_for_response>
517 532 api_key : "<api_key>"
518 533 method : "delete_repo"
519 534 args: {
520 535 "repo_name" : "<reponame>",
521 536 }
522 537
523 538 OUTPUT::
524 539
525 540 result: {
526 541 "msg": "Deleted repository <reponame>",
527 542 }
528 543 error: null
529 544
530 545
531 546 grant_user_permission
532 547 ---------------------
533 548
534 549 Grant permission for user on given repository, or update existing one
535 550 if found. This command can be executed only using api_key belonging to user
536 551 with admin rights.
537 552
538 553
539 554 INPUT::
540 555
556 id : <id_for_response>
541 557 api_key : "<api_key>"
542 558 method : "grant_user_permission"
543 559 args: {
544 560 "repo_name" : "<reponame>",
545 561 "username" : "<username>",
546 562 "perm" : "(repository.(none|read|write|admin))",
547 563 }
548 564
549 565 OUTPUT::
550 566
551 567 result: {
552 568 "msg" : "Granted perm: <perm> for user: <username> in repo: <reponame>"
553 569 }
554 570 error: null
555 571
556 572
557 573 revoke_user_permission
558 574 ----------------------
559 575
560 576 Revoke permission for user on given repository. This command can be executed
561 577 only using api_key belonging to user with admin rights.
562 578
563 579
564 580 INPUT::
565 581
582 id : <id_for_response>
566 583 api_key : "<api_key>"
567 584 method : "revoke_user_permission"
568 585 args: {
569 586 "repo_name" : "<reponame>",
570 587 "username" : "<username>",
571 588 }
572 589
573 590 OUTPUT::
574 591
575 592 result: {
576 593 "msg" : "Revoked perm for user: <suername> in repo: <reponame>"
577 594 }
578 595 error: null
579 596
580 597
581 598 grant_users_group_permission
582 599 ----------------------------
583 600
584 601 Grant permission for users group on given repository, or update
585 602 existing one if found. This command can be executed only using
586 603 api_key belonging to user with admin rights.
587 604
588 605
589 606 INPUT::
590 607
608 id : <id_for_response>
591 609 api_key : "<api_key>"
592 610 method : "grant_users_group_permission"
593 611 args: {
594 612 "repo_name" : "<reponame>",
595 613 "group_name" : "<usersgroupname>",
596 614 "perm" : "(repository.(none|read|write|admin))",
597 615 }
598 616
599 617 OUTPUT::
600 618
601 619 result: {
602 620 "msg" : "Granted perm: <perm> for group: <usersgroupname> in repo: <reponame>"
603 621 }
604 622 error: null
605 623
606 624
607 625 revoke_users_group_permission
608 626 -----------------------------
609 627
610 628 Revoke permission for users group on given repository.This command can be
611 629 executed only using api_key belonging to user with admin rights.
612 630
613 631 INPUT::
614 632
633 id : <id_for_response>
615 634 api_key : "<api_key>"
616 635 method : "revoke_users_group_permission"
617 636 args: {
618 637 "repo_name" : "<reponame>",
619 638 "users_group" : "<usersgroupname>",
620 639 }
621 640
622 641 OUTPUT::
623 642
624 643 result: {
625 644 "msg" : "Revoked perm for group: <usersgroupname> in repo: <reponame>"
626 645 }
627 646 error: null No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now