Mercurial > public > src > rhodecode
annotate docs/api/api.rst @ 1793:fee9895fa46e beta
changed API to match fully JSON-RPC specs
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Mon, 21 Nov 2011 03:08:09 +0200 |
parents | 8628c8706bf8 |
children | 631caf880b87 |
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 |
13 | |
1793
fee9895fa46e
changed API to match fully JSON-RPC specs
Marcin Kuzminski <marcin@python-works.com>
parents:
1676
diff
changeset
|
14 All clients are required to send JSON-RPC spec JSON data:: |
1526 | 15 |
1793
fee9895fa46e
changed API to match fully JSON-RPC specs
Marcin Kuzminski <marcin@python-works.com>
parents:
1676
diff
changeset
|
16 { |
fee9895fa46e
changed API to match fully JSON-RPC specs
Marcin Kuzminski <marcin@python-works.com>
parents:
1676
diff
changeset
|
17 "id:<id>, |
1526 | 18 "api_key":"<api_key>", |
19 "method":"<method_name>", | |
20 "args":{"<arg_key>":"<arg_val>"} | |
21 } | |
22 | |
1580 | 23 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
|
24 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 | 25 |
1676 | 26 Simply provide |
1793
fee9895fa46e
changed API to match fully JSON-RPC specs
Marcin Kuzminski <marcin@python-works.com>
parents:
1676
diff
changeset
|
27 - *id* A value of any type, which is used to match the response with the request that it is replying to. |
1580 | 28 - *api_key* for access and permission validation. |
29 - *method* is name of method to call | |
30 - *args* is an key:value list of arguments to pass to method | |
1676 | 31 |
1526 | 32 .. note:: |
1676 | 33 |
34 api_key can be found in your user account page | |
35 | |
36 | |
1793
fee9895fa46e
changed API to match fully JSON-RPC specs
Marcin Kuzminski <marcin@python-works.com>
parents:
1676
diff
changeset
|
37 RhodeCode API will return always a JSON-RPC response:: |
1676 | 38 |
1793
fee9895fa46e
changed API to match fully JSON-RPC specs
Marcin Kuzminski <marcin@python-works.com>
parents:
1676
diff
changeset
|
39 { |
fee9895fa46e
changed API to match fully JSON-RPC specs
Marcin Kuzminski <marcin@python-works.com>
parents:
1676
diff
changeset
|
40 "id":<id>, |
1676 | 41 "result": "<result>", |
1526 | 42 "error": null |
43 } | |
44 | |
45 All responses from API will be `HTTP/1.0 200 OK`, if there's an error while | |
1676 | 46 calling api *error* key from response will contain failure description |
1526 | 47 and result will be null. |
48 | |
49 API METHODS | |
50 +++++++++++ | |
51 | |
1676 | 52 |
1526 | 53 pull |
54 ---- | |
55 | |
1676 | 56 Pulls given repo from remote location. Can be used to automatically keep |
57 remote repos up to date. This command can be executed only using api_key | |
1580 | 58 belonging to user with admin rights |
59 | |
60 INPUT:: | |
61 | |
1676 | 62 api_key : "<api_key>" |
63 method : "pull" | |
64 args : { | |
65 "repo" : "<repo_name>" | |
66 } | |
67 | |
68 OUTPUT:: | |
69 | |
70 result : "Pulled from <repo_name>" | |
71 error : null | |
72 | |
73 | |
74 get_users | |
75 --------- | |
76 | |
77 Lists all existing users. This command can be executed only using api_key | |
78 belonging to user with admin rights. | |
79 | |
80 INPUT:: | |
81 | |
82 api_key : "<api_key>" | |
83 method : "get_users" | |
84 args : { } | |
85 | |
86 OUTPUT:: | |
87 | |
88 result: [ | |
89 { | |
90 "id" : "<id>", | |
91 "username" : "<username>", | |
92 "firstname": "<firstname>", | |
93 "lastname" : "<lastname>", | |
94 "email" : "<email>", | |
95 "active" : "<bool>", | |
96 "admin" : "<bool>", | |
97 "ldap" : "<ldap_dn>" | |
98 }, | |
99 … | |
100 ] | |
101 error: null | |
102 | |
103 create_user | |
104 ----------- | |
105 | |
106 Creates new user in RhodeCode. This command can be executed only using api_key | |
107 belonging to user with admin rights. | |
108 | |
109 INPUT:: | |
110 | |
111 api_key : "<api_key>" | |
112 method : "create_user" | |
113 args : { | |
114 "username" : "<username>", | |
115 "password" : "<password>", | |
116 "firstname" : "<firstname>", | |
117 "lastname" : "<lastname>", | |
118 "email" : "<useremail>" | |
119 "active" : "<bool> = True", | |
120 "admin" : "<bool> = False", | |
121 "ldap_dn" : "<ldap_dn> = None" | |
122 } | |
1580 | 123 |
124 OUTPUT:: | |
125 | |
1676 | 126 result: { |
127 "msg" : "created new user <username>" | |
128 } | |
129 error: null | |
130 | |
131 get_users_groups | |
132 ---------------- | |
133 | |
134 Lists all existing users groups. This command can be executed only using api_key | |
135 belonging to user with admin rights. | |
136 | |
137 INPUT:: | |
138 | |
139 api_key : "<api_key>" | |
140 method : "get_users_groups" | |
141 args : { } | |
142 | |
143 OUTPUT:: | |
144 | |
145 result : [ | |
146 { | |
147 "id" : "<id>", | |
148 "name" : "<name>", | |
149 "active": "<bool>", | |
150 "members" : [ | |
151 { | |
152 "id" : "<userid>", | |
153 "username" : "<username>", | |
154 "firstname": "<firstname>", | |
155 "lastname" : "<lastname>", | |
156 "email" : "<email>", | |
157 "active" : "<bool>", | |
158 "admin" : "<bool>", | |
159 "ldap" : "<ldap_dn>" | |
160 }, | |
161 … | |
162 ] | |
163 } | |
164 ] | |
165 error : null | |
166 | |
167 get_users_group | |
168 --------------- | |
169 | |
170 Gets an existing users group. This command can be executed only using api_key | |
171 belonging to user with admin rights. | |
172 | |
173 INPUT:: | |
174 | |
175 api_key : "<api_key>" | |
176 method : "get_users_group" | |
177 args : { | |
178 "group_name" : "<name>" | |
179 } | |
180 | |
181 OUTPUT:: | |
182 | |
183 result : None if group not exist | |
184 { | |
185 "id" : "<id>", | |
186 "name" : "<name>", | |
187 "active": "<bool>", | |
188 "members" : [ | |
189 { "id" : "<userid>", | |
190 "username" : "<username>", | |
191 "firstname": "<firstname>", | |
192 "lastname" : "<lastname>", | |
193 "email" : "<email>", | |
194 "active" : "<bool>", | |
195 "admin" : "<bool>", | |
196 "ldap" : "<ldap_dn>" | |
197 }, | |
198 … | |
199 ] | |
200 } | |
201 error : null | |
202 | |
1580 | 203 create_users_group |
204 ------------------ | |
205 | |
1676 | 206 Creates new users group. This command can be executed only using api_key |
1580 | 207 belonging to user with admin rights |
208 | |
209 INPUT:: | |
210 | |
1676 | 211 api_key : "<api_key>" |
212 method : "create_users_group" | |
213 args: { | |
214 "name": "<name>", | |
215 "active":"<bool> = True" | |
216 } | |
217 | |
218 OUTPUT:: | |
219 | |
220 result: { | |
221 "id": "<newusersgroupid>", | |
222 "msg": "created new users group <name>" | |
223 } | |
224 error: null | |
225 | |
226 add_user_to_users_groups | |
227 ------------------------ | |
228 | |
229 Adds a user to a users group. This command can be executed only using api_key | |
230 belonging to user with admin rights | |
231 | |
232 INPUT:: | |
233 | |
234 api_key : "<api_key>" | |
235 method : "add_user_users_group" | |
236 args: { | |
237 "group_name" : "<groupname>", | |
238 "user_name" : "<username>" | |
239 } | |
240 | |
241 OUTPUT:: | |
242 | |
243 result: { | |
244 "id": "<newusersgroupmemberid>", | |
245 "msg": "created new users group member" | |
246 } | |
247 error: null | |
248 | |
249 get_repos | |
250 --------- | |
251 | |
252 Lists all existing repositories. This command can be executed only using api_key | |
253 belonging to user with admin rights | |
254 | |
255 INPUT:: | |
256 | |
257 api_key : "<api_key>" | |
258 method : "get_repos" | |
259 args: { } | |
1580 | 260 |
261 OUTPUT:: | |
262 | |
1676 | 263 result: [ |
264 { | |
265 "id" : "<id>", | |
266 "name" : "<name>" | |
267 "type" : "<type>", | |
268 "description" : "<description>" | |
269 }, | |
270 … | |
271 ] | |
272 error: null | |
273 | |
274 get_repo | |
275 -------- | |
276 | |
277 Gets an existing repository. This command can be executed only using api_key | |
278 belonging to user with admin rights | |
279 | |
280 INPUT:: | |
281 | |
282 api_key : "<api_key>" | |
283 method : "get_repo" | |
284 args: { | |
285 "name" : "<name>" | |
286 } | |
287 | |
288 OUTPUT:: | |
289 | |
290 result: None if repository not exist | |
291 { | |
292 "id" : "<id>", | |
293 "name" : "<name>" | |
294 "type" : "<type>", | |
295 "description" : "<description>", | |
296 "members" : [ | |
297 { "id" : "<userid>", | |
298 "username" : "<username>", | |
299 "firstname": "<firstname>", | |
300 "lastname" : "<lastname>", | |
301 "email" : "<email>", | |
302 "active" : "<bool>", | |
303 "admin" : "<bool>", | |
304 "ldap" : "<ldap_dn>", | |
305 "permission" : "repository_(read|write|admin)" | |
306 }, | |
307 … | |
308 { | |
309 "id" : "<usersgroupid>", | |
310 "name" : "<usersgroupname>", | |
311 "active": "<bool>", | |
312 "permission" : "repository_(read|write|admin)" | |
313 }, | |
314 … | |
315 ] | |
316 } | |
317 error: null | |
318 | |
319 create_repo | |
320 ----------- | |
321 | |
322 Creates a repository. This command can be executed only using api_key | |
323 belonging to user with admin rights. | |
324 If repository name contains "/", all needed repository groups will be created. | |
325 For example "foo/bar/baz" will create groups "foo", "bar" (with "foo" as parent), | |
326 and create "baz" repository with "bar" as group. | |
327 | |
328 INPUT:: | |
329 | |
330 api_key : "<api_key>" | |
331 method : "create_repo" | |
332 args: { | |
333 "name" : "<name>", | |
334 "owner_name" : "<ownername>", | |
335 "description" : "<description> = ''", | |
336 "repo_type" : "<type> = 'hg'", | |
337 "private" : "<bool> = False" | |
338 } | |
339 | |
340 OUTPUT:: | |
341 | |
342 result: None | |
343 error: null | |
344 | |
345 add_user_to_repo | |
346 ---------------- | |
347 | |
348 Add a user to a repository. This command can be executed only using api_key | |
349 belonging to user with admin rights. | |
350 If "perm" is None, user will be removed from the repository. | |
351 | |
352 INPUT:: | |
353 | |
354 api_key : "<api_key>" | |
355 method : "add_user_to_repo" | |
356 args: { | |
357 "repo_name" : "<reponame>", | |
358 "user_name" : "<username>", | |
359 "perm" : "(None|repository_(read|write|admin))", | |
360 } | |
361 | |
362 OUTPUT:: | |
363 | |
364 result: None | |
365 error: null |