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