##// END OF EJS Templates
docs: improve the API documentation
Mads Kiilerich -
r4879:599fba99 default
parent child Browse files
Show More
@@ -5,23 +5,23 b' API'
5 5 ===
6 6
7 7
8 Starting from Kallithea version 1.2 a simple API was 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 to Kallithea is
11 <your_server>/_admin/api
8 Kallithea has a simple JSON RPC API with a single schema for calling all api
9 methods. Everything is available by sending JSON encoded http(s) requests to
10 <your_server>/_admin/api .
11
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 Kallithea that is
17 decorated with `@LoginRequired` decorator. To enable API access simple change
18 the standard login decorator to `@LoginRequired(api_access=True)`.
17 decorated with the `@LoginRequired` decorator. Some views use
18 `@LoginRequired(api_access=True)` and are always available. By default only
19 RSS/ATOM feed views are enabled. Other views are
20 only available if they have been white listed. Edit the
21 `api_access_controllers_whitelist` option in your .ini file and define views
22 that should have API access enabled.
19 23
20 To make this operation easier, starting from version 1.7.0 there's a white list
21 of views that will have API access enabled. Simply edit `api_access_controllers_whitelist`
22 option in your .ini file, and define views that should have API access enabled.
23 Following example shows how to enable API access to patch/diff raw file and archive
24 in Kallithea::
24 For example, to enable API access to patch/diff raw file and archive::
25 25
26 26 api_access_controllers_whitelist =
27 27 ChangesetController:changeset_patch,
@@ -29,71 +29,61 b' in Kallithea::'
29 29 FilesController:raw,
30 30 FilesController:archivefile
31 31
32 After this change, a Kallithea view can be accessed without login by adding a
33 GET parameter `?api_key=<api_key>` to url.
32 34
33 After this change, a Kallithea view can be accessed without login by adding a
34 GET parameter `?api_key=<api_key>` to url. By default this is only
35 enabled on RSS/ATOM feed views. Exposing raw diffs is a good way to integrate with
35 Exposing raw diffs is a good way to integrate with
36 36 3rd party services like code review, or build farms that could download archives.
37 37
38 38
39 39 API ACCESS
40 40 ++++++++++
41 41
42 All clients are required to send JSON-RPC spec JSON data::
42 Clients must send JSON encoded JSON-RPC requests::
43 43
44 44 {
45 "id:"<id>",
46 "api_key":"<api_key>",
47 "method":"<method_name>",
48 "args":{"<arg_key>":"<arg_val>"}
45 "id: "<id>",
46 "api_key": "<api_key>",
47 "method": "<method_name>",
48 "args": {"<arg_key>": "<arg_val>"}
49 49 }
50 50
51 Example call for autopulling remotes repos using curl::
51 For example, to pull to a local "CPython" mirror using curl::
52
52 53 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"}}'
53 54
54 Simply provide
55 - *id* A value of any type, which is used to match the response with the request that it is replying to.
56 - *api_key* for access and permission validation.
57 - *method* is name of method to call
58 - *args* is an key:value list of arguments to pass to method
55 In general, provide
56 - *id*, a value of any type, can be used to match the response with the request that it is replying to.
57 - *api_key*, for authentication and permission validation.
58 - *method*, the name of the method to call - a list of available methods can be found below.
59 - *args*, the arguments to pass to the method.
59 60
60 61 .. note::
61 62
62 api_key can be found in your user account page
63 api_key can be found or set on the user account page
63 64
64
65 Kallithea API will return always a JSON-RPC response::
65 The response to the JSON-RPC API call will always be a JSON structure::
66 66
67 67 {
68 "id":<id>, # matching id sent by request
68 "id":<id>, # the id that was used in the request
69 69 "result": "<result>"|null, # JSON formatted result, null if any errors
70 70 "error": "null"|<error_message> # JSON formatted error (if any)
71 71 }
72 72
73 All responses from API will be `HTTP/1.0 200 OK`, if there's an error while
74 calling api *error* key from response will contain failure description
75 and result will be null.
73 All responses from API will be `HTTP/1.0 200 OK`. If there is an error,
74 the reponse will have a failure description in *error* and
75 *result* will be null.
76 76
77 77
78 78 API CLIENT
79 79 ++++++++++
80 80
81 From version 1.4 Kallithea adds a script that allows to easily
82 communicate with API. After installing Kallithea a `kallithea-api` script
83 will be available.
84
85 To get started quickly simply run::
86
87 kallithea-api _create_config --apikey=<youapikey> --apihost=<your.kallithea.server>
81 Kallithea comes with a `kallithea-api` command line tool providing a convenient
82 way to call the JSON-RPC API.
88 83
89 This will create a file named .config in the directory you executed it storing
90 json config file with credentials. You can skip this step and always provide
91 both of the arguments to be able to communicate with server
84 For example, to call `get_repo`::
92 85
93
94 after that simply run any api command for example get_repo::
95
96 kallithea-api get_repo
86 kallithea-api --apihost=<your.kallithea.server.url> --apikey=<yourapikey> get_repo
97 87
98 88 calling {"api_key": "<apikey>", "id": 75, "args": {}, "method": "get_repo"} to http://127.0.0.1:5000
99 89 Kallithea said:
@@ -101,9 +91,7 b' after that simply run any api command fo'
101 91 'id': 75,
102 92 'result': None}
103 93
104 Ups looks like we forgot to add an argument
105
106 Let's try again now giving the repoid as parameters::
94 Oops, looks like we forgot to add an argument. Let's try again, now providing the repoid as parameter::
107 95
108 96 kallithea-api get_repo repoid:myrepo
109 97
@@ -113,6 +101,12 b" Let's try again now giving the repoid as"
113 101 'id': 39,
114 102 'result': <json data...>}
115 103
104 To avoid specifying apihost and apikey every time, run::
105
106 kallithea-api --save-config --apihost=<your.kallithea.server.url> --apikey=<yourapikey>
107
108 This will create a `~/.config/kallithea` with the specified hostname and apikey
109 so you don't have to specify them every time.
116 110
117 111
118 112 API METHODS
@@ -122,9 +116,9 b' API METHODS'
122 116 pull
123 117 ----
124 118
125 Pulls given repo from remote location. Can be used to automatically keep
126 remote repos up to date. This command can be executed only using api_key
127 belonging to user with admin rights
119 Pull the given repo from remote location. Can be used to automatically keep
120 remote repos up to date.
121 This command can only be executed using the api_key of a user with admin rights.
128 122
129 123 INPUT::
130 124
@@ -145,10 +139,9 b' OUTPUT::'
145 139 rescan_repos
146 140 ------------
147 141
148 Dispatch rescan repositories action. If remove_obsolete is set
142 Rescan repositories. If remove_obsolete is set,
149 143 Kallithea will delete repos that are in database but not in the filesystem.
150 This command can be executed only using api_key belonging to user with admin
151 rights.
144 This command can only be executed using the api_key of a user with admin rights.
152 145
153 146 INPUT::
154 147
@@ -171,8 +164,8 b' invalidate_cache'
171 164 ----------------
172 165
173 166 Invalidate cache for repository.
174 This command can be executed only using api_key belonging to user with admin
175 rights or regular user that have write or admin or write access to repository.
167 This command can only be executed using the api_key of a user with admin rights,
168 or that of a regular user with admin or write access to the repository.
176 169
177 170 INPUT::
178 171
@@ -189,14 +182,14 b' OUTPUT::'
189 182 result : "Caches of repository `<reponame>`"
190 183 error : null
191 184
185
192 186 lock
193 187 ----
194 188
195 Set locking state on given repository by given user. If userid param is skipped
196 , then it is set to id of user whos calling this method. If locked param is skipped
197 then function shows current lock state of given repo.
198 This command can be executed only using api_key belonging to user with admin
199 rights or regular user that have admin or write access to repository.
189 Set the locking state on the given repository by the given user.
190 If param 'userid' is skipped, it is set to the id of the user who is calling this method.
191 If param 'locked' is skipped, the current lock state of the repository is returned.
192 This command can only be executed using the api_key of a user with admin rights, or that of a regular user with admin or write access to the repository.
200 193
201 194 INPUT::
202 195
@@ -225,10 +218,9 b' OUTPUT::'
225 218 get_ip
226 219 ------
227 220
228 Shows IP address as seen from Kallithea server, together with all
221 Return IP address as seen from Kallithea server, together with all
229 222 defined IP addresses for given user.
230 This command can be executed only using api_key belonging to user with admin
231 rights.
223 This command can only be executed using the api_key of a user with admin rights.
232 224
233 225 INPUT::
234 226
@@ -259,10 +251,10 b' OUTPUT::'
259 251 get_user
260 252 --------
261 253
262 Gets an user by username or user_id, Returns empty result if user is not found.
263 If userid param is skipped it is set to id of user who is calling this method.
264 This command can be executed only using api_key belonging to user with admin
265 rights, or regular users that cannot specify different userid than theirs
254 Get a user by username or userid. The result is empty if user can't be found.
255 If userid param is skipped, it is set to id of user who is calling this method.
256 Any userid can be specified when the command is executed using the api_key of a user with admin rights.
257 Regular users can only speicy their own userid.
266 258
267 259
268 260 INPUT::
@@ -306,8 +298,8 b' OUTPUT::'
306 298 get_users
307 299 ---------
308 300
309 Lists all existing users. This command can be executed only using api_key
310 belonging to user with admin rights.
301 List all existing users.
302 This command can only be executed using the api_key of a user with admin rights.
311 303
312 304
313 305 INPUT::
@@ -343,8 +335,8 b' OUTPUT::'
343 335 create_user
344 336 -----------
345 337
346 Creates new user. This command can
347 be executed only using api_key belonging to user with admin rights.
338 Create new user.
339 This command can only be executed using the api_key of a user with admin rights.
348 340
349 341
350 342 INPUT::
@@ -387,8 +379,8 b' OUTPUT::'
387 379 update_user
388 380 -----------
389 381
390 updates given user if such user exists. This command can
391 be executed only using api_key belonging to user with admin rights.
382 Update the given user if such user exists.
383 This command can only be executed using the api_key of a user with admin rights.
392 384
393 385
394 386 INPUT::
@@ -433,9 +425,8 b' OUTPUT::'
433 425 delete_user
434 426 -----------
435 427
436
437 deletes givenuser if such user exists. This command can
438 be executed only using api_key belonging to user with admin rights.
428 Delete given user if such user exists.
429 This command can only be executed using the api_key of a user with admin rights.
439 430
440 431
441 432 INPUT::
@@ -460,8 +451,8 b' OUTPUT::'
460 451 get_user_group
461 452 --------------
462 453
463 Gets an existing user group. This command can be executed only using api_key
464 belonging to user with admin rights.
454 Get an existing user group.
455 This command can only be executed using the api_key of a user with admin rights.
465 456
466 457
467 458 INPUT::
@@ -504,8 +495,8 b' OUTPUT::'
504 495 get_user_groups
505 496 ---------------
506 497
507 Lists all existing user groups. This command can be executed only using
508 api_key belonging to user with admin rights.
498 List all existing user groups.
499 This command can only be executed using the api_key of a user with admin rights.
509 500
510 501
511 502 INPUT::
@@ -532,8 +523,8 b' OUTPUT::'
532 523 create_user_group
533 524 -----------------
534 525
535 Creates new user group. This command can be executed only using api_key
536 belonging to user with admin rights
526 Create a new user group.
527 This command can only be executed using the api_key of a user with admin rights.
537 528
538 529
539 530 INPUT::
@@ -564,9 +555,9 b' OUTPUT::'
564 555 add_user_to_user_group
565 556 ----------------------
566 557
567 Adds a user to a user group. If user exists in that group success will be
568 `false`. This command can be executed only using api_key
569 belonging to user with admin rights
558 Addsa user to a user group. If the user already is in that group, success will be
559 `false`.
560 This command can only be executed using the api_key of a user with admin rights.
570 561
571 562
572 563 INPUT::
@@ -584,7 +575,7 b' OUTPUT::'
584 575 id : <id_given_in_input>
585 576 result: {
586 577 "success": True|False # depends on if member is in group
587 "msg": "added member `<username>` to user group `<groupname>` |
578 "msg": "added member `<username>` to a user group `<groupname>` |
588 579 User is already in that group"
589 580 }
590 581 error: null
@@ -593,9 +584,9 b' OUTPUT::'
593 584 remove_user_from_user_group
594 585 ---------------------------
595 586
596 Removes a user from a user group. If user is not in given group success will
597 be `false`. This command can be executed only
598 using api_key belonging to user with admin rights
587 Remove a user from a user group. If the user isn't in the given group, success will
588 be `false`.
589 This command can only be executed using the api_key of a user with admin rights.
599 590
600 591
601 592 INPUT::
@@ -622,11 +613,10 b' OUTPUT::'
622 613 get_repo
623 614 --------
624 615
625 Gets an existing repository by it's name or repository_id. Members will return
626 either users_group or user associated to that repository. This command can be
627 executed only using api_key belonging to user with admin
628 rights or regular user that have at least read access to repository.
629
616 Get an existing repository by its name or repository_id. Members will contain
617 either users_group or user associated to that repository.
618 This command can only be executed using the api_key of a user with admin rights,
619 or that of a regular user with at least read access to the repository.
630 620
631 621 INPUT::
632 622
@@ -713,9 +703,9 b' OUTPUT::'
713 703 get_repos
714 704 ---------
715 705
716 Lists all existing repositories. This command can be executed only using
717 api_key belonging to user with admin rights or regular user that have
718 admin, write or read access to repository.
706 List all existing repositories.
707 This command can only be executed using the api_key of a user with admin rights,
708 or that of a regular user with at least read access to the repository.
719 709
720 710
721 711 INPUT::
@@ -752,10 +742,9 b' OUTPUT::'
752 742 get_repo_nodes
753 743 --------------
754 744
755 returns a list of nodes and it's children in a flat list for a given path
756 at given revision. It's possible to specify ret_type to show only `files` or
757 `dirs`. This command can be executed only using api_key belonging to user
758 with admin rights
745 Return a list of files and directories for a given path at the given revision.
746 It's possible to specify ret_type to show only `files` or `dirs`.
747 This command can only be executed using the api_key of a user with admin rights.
759 748
760 749
761 750 INPUT::
@@ -786,12 +775,13 b' OUTPUT::'
786 775 create_repo
787 776 -----------
788 777
789 Creates a repository. If repository name contains "/", all needed repository
790 groups will be created. For example "foo/bar/baz" will create groups
778 Create a repository. If repository name contains "/", all needed repository
779 groups will be created. For example "foo/bar/baz" will create repository groups
791 780 "foo", "bar" (with "foo" as parent), and create "baz" repository with
792 "bar" as group. This command can be executed only using api_key belonging to user with admin
793 rights or regular user that have create repository permission. Regular users
794 cannot specify owner parameter
781 "bar" as group.
782 This command can only be executed using the api_key of a user with admin rights,
783 or that of a regular user with create repository permission.
784 Regular users cannot specify owner parameter.
795 785
796 786
797 787 INPUT::
@@ -839,11 +829,12 b' OUTPUT::'
839 829 fork_repo
840 830 ---------
841 831
842 Creates a fork of given repo. In case of using celery this will
843 immidiatelly return success message, while fork is going to be created
844 asynchronous. This command can be executed only using api_key belonging to
845 user with admin rights or regular user that have fork permission, and at least
846 read access to forking repository. Regular users cannot specify owner parameter.
832 Create a fork of given repo. If using celery, this will
833 return success message immidiatelly and fork will be created
834 asynchronously.
835 This command can only be executed using the api_key of a user with admin rights,
836 or that of a regular user with fork permission and at least read access to the repository.
837 Regular users cannot specify owner parameter.
847 838
848 839
849 840 INPUT::
@@ -875,10 +866,10 b' OUTPUT::'
875 866 delete_repo
876 867 -----------
877 868
878 Deletes a repository. This command can be executed only using api_key belonging
879 to user with admin rights or regular user that have admin access to repository.
880 When `forks` param is set it's possible to detach or delete forks of deleting
881 repository
869 Delete a repository.
870 This command can only be executed using the api_key of a user with admin rights,
871 or that of a regular user with admin access to the repository.
872 When `forks` param is set it's possible to detach or delete forks of the deleted repository.
882 873
883 874
884 875 INPUT::
@@ -904,9 +895,8 b' OUTPUT::'
904 895 grant_user_permission
905 896 ---------------------
906 897
907 Grant permission for user on given repository, or update existing one
908 if found. This command can be executed only using api_key belonging to user
909 with admin rights.
898 Grant permission for user on given repository, or update existing one if found.
899 This command can only be executed using the api_key of a user with admin rights.
910 900
911 901
912 902 INPUT::
@@ -933,8 +923,8 b' OUTPUT::'
933 923 revoke_user_permission
934 924 ----------------------
935 925
936 Revoke permission for user on given repository. This command can be executed
937 only using api_key belonging to user with admin rights.
926 Revoke permission for user on given repository.
927 This command can only be executed using the api_key of a user with admin rights.
938 928
939 929
940 930 INPUT::
@@ -961,8 +951,8 b' grant_user_group_permission'
961 951 ---------------------------
962 952
963 953 Grant permission for user group on given repository, or update
964 existing one if found. This command can be executed only using
965 api_key belonging to user with admin rights.
954 existing one if found.
955 This command can only be executed using the api_key of a user with admin rights.
966 956
967 957
968 958 INPUT::
@@ -989,8 +979,8 b' OUTPUT::'
989 979 revoke_user_group_permission
990 980 ----------------------------
991 981
992 Revoke permission for user group on given repository.This command can be
993 executed only using api_key belonging to user with admin rights.
982 Revoke permission for user group on given repository.
983 This command can only be executed using the api_key of a user with admin rights.
994 984
995 985 INPUT::
996 986
General Comments 0
You need to be logged in to leave comments. Login now