api.rst
473 lines
| 12.3 KiB
| text/x-rst
|
RstLexer
r1446 | .. _api: | |||
API | ||||
=== | ||||
Starting from RhodeCode version 1.2 a simple API was implemented. | ||||
r1500 | There's a single schema for calling all api methods. API is implemented | |||
Nicolas VINOT
|
r1592 | with JSON protocol both ways. An url to send API request in RhodeCode is | ||
r1500 | <your_server>/_admin/api | |||
r1446 | ||||
r1839 | API ACCESS FOR WEB VIEWS | |||
++++++++++++++++++++++++ | ||||
r1446 | ||||
r1911 | API access can also be turned on for each web view in RhodeCode that is | |||
decorated with `@LoginRequired` decorator. To enable API access simple change | ||||
the standard login decorator to `@LoginRequired(api_access=True)`. | ||||
After this change, a rhodecode view can be accessed without login by adding a | ||||
GET parameter `?api_key=<api_key>` to url. By default this is only | ||||
r1812 | enabled on RSS/ATOM feed views. | |||
r1839 | API ACCESS | |||
++++++++++ | ||||
r1708 | All clients are required to send JSON-RPC spec JSON data:: | |||
r1446 | ||||
r1708 | { | |||
"id:<id>, | ||||
r1446 | "api_key":"<api_key>", | |||
"method":"<method_name>", | ||||
"args":{"<arg_key>":"<arg_val>"} | ||||
} | ||||
r1500 | Example call for autopulling remotes repos using curl:: | |||
r1708 | 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"}}' | |||
r1500 | ||||
Nicolas VINOT
|
r1592 | Simply provide | ||
r1708 | - *id* A value of any type, which is used to match the response with the request that it is replying to. | |||
r1500 | - *api_key* for access and permission validation. | |||
- *method* is name of method to call | ||||
- *args* is an key:value list of arguments to pass to method | ||||
Nicolas VINOT
|
r1592 | |||
r1446 | .. note:: | |||
Nicolas VINOT
|
r1592 | |||
api_key can be found in your user account page | ||||
r1708 | RhodeCode API will return always a JSON-RPC response:: | |||
Nicolas VINOT
|
r1592 | |||
r1708 | { | |||
"id":<id>, | ||||
Nicolas VINOT
|
r1592 | "result": "<result>", | ||
r1446 | "error": null | |||
} | ||||
All responses from API will be `HTTP/1.0 200 OK`, if there's an error while | ||||
Nicolas VINOT
|
r1592 | calling api *error* key from response will contain failure description | ||
r1446 | and result will be null. | |||
API METHODS | ||||
+++++++++++ | ||||
Nicolas VINOT
|
r1592 | |||
r1446 | pull | |||
---- | ||||
Nicolas VINOT
|
r1592 | Pulls given repo from remote location. Can be used to automatically keep | ||
remote repos up to date. This command can be executed only using api_key | ||||
r1500 | belonging to user with admin rights | |||
INPUT:: | ||||
Nicolas VINOT
|
r1592 | api_key : "<api_key>" | ||
method : "pull" | ||||
args : { | ||||
r1843 | "repo_name" : "<reponame>" | |||
Nicolas VINOT
|
r1592 | } | ||
OUTPUT:: | ||||
r1843 | result : "Pulled from <reponame>" | |||
Nicolas VINOT
|
r1592 | error : null | ||
r1843 | get_user | |||
-------- | ||||
Get's an user by username, Returns empty result if user is not found. | ||||
This command can be executed only using api_key belonging to user with admin | ||||
rights. | ||||
INPUT:: | ||||
api_key : "<api_key>" | ||||
method : "get_user" | ||||
args : { | ||||
"username" : "<username>" | ||||
} | ||||
OUTPUT:: | ||||
result: None if user does not exist or | ||||
{ | ||||
"id" : "<id>", | ||||
"username" : "<username>", | ||||
"firstname": "<firstname>", | ||||
"lastname" : "<lastname>", | ||||
"email" : "<email>", | ||||
"active" : "<bool>", | ||||
"admin" :Â "<bool>", | ||||
"ldap" : "<ldap_dn>" | ||||
} | ||||
error: null | ||||
Nicolas VINOT
|
r1592 | get_users | ||
--------- | ||||
Lists all existing users. This command can be executed only using api_key | ||||
belonging to user with admin rights. | ||||
INPUT:: | ||||
api_key : "<api_key>" | ||||
method : "get_users" | ||||
args : { } | ||||
OUTPUT:: | ||||
result: [ | ||||
{ | ||||
"id" : "<id>", | ||||
"username" : "<username>", | ||||
"firstname": "<firstname>", | ||||
"lastname" : "<lastname>", | ||||
"email" : "<email>", | ||||
"active" : "<bool>", | ||||
"admin" :Â "<bool>", | ||||
"ldap" : "<ldap_dn>" | ||||
}, | ||||
… | ||||
] | ||||
error: null | ||||
create_user | ||||
----------- | ||||
r1909 | Creates new user or updates current one if such user exists. This command can | |||
be executed only using api_key belonging to user with admin rights. | ||||
Nicolas VINOT
|
r1592 | |||
INPUT:: | ||||
api_key : "<api_key>" | ||||
method : "create_user" | ||||
args : { | ||||
"username" : "<username>", | ||||
"password" : "<password>", | ||||
r1950 | "email" : "<useremail>", | |||
"firstname" : "<firstname> = None", | ||||
"lastname" : "<lastname> = None", | ||||
Nicolas VINOT
|
r1592 | "active" : "<bool> = True", | ||
"admin" : "<bool> = False", | ||||
"ldap_dn" : "<ldap_dn> = None" | ||||
} | ||||
r1500 | ||||
OUTPUT:: | ||||
Nicolas VINOT
|
r1592 | result: { | ||
r1843 | "id" : "<new_user_id>", | |||
Nicolas VINOT
|
r1592 | "msg" : "created new user <username>" | ||
} | ||||
error: null | ||||
get_users_group | ||||
--------------- | ||||
Gets an existing users group. This command can be executed only using api_key | ||||
belonging to user with admin rights. | ||||
INPUT:: | ||||
api_key : "<api_key>" | ||||
method : "get_users_group" | ||||
args : { | ||||
"group_name" : "<name>" | ||||
} | ||||
OUTPUT:: | ||||
result : None if group not exist | ||||
{ | ||||
r1843 | "id" : "<id>", | |||
"group_name" : "<groupname>", | ||||
"active": "<bool>", | ||||
Nicolas VINOT
|
r1592 | "members" : [ | ||
r1843 | { "id" : "<userid>", | |||
"username" : "<username>", | ||||
"firstname": "<firstname>", | ||||
"lastname" : "<lastname>", | ||||
"email" : "<email>", | ||||
"active" : "<bool>", | ||||
"admin" :Â "<bool>", | ||||
"ldap" : "<ldap_dn>" | ||||
}, | ||||
… | ||||
] | ||||
Nicolas VINOT
|
r1592 | } | ||
error : null | ||||
r1843 | get_users_groups | |||
---------------- | ||||
Lists all existing users groups. This command can be executed only using | ||||
api_key belonging to user with admin rights. | ||||
INPUT:: | ||||
api_key : "<api_key>" | ||||
method : "get_users_groups" | ||||
args : { } | ||||
OUTPUT:: | ||||
result : [ | ||||
{ | ||||
"id" : "<id>", | ||||
"group_name" : "<groupname>", | ||||
"active": "<bool>", | ||||
"members" : [ | ||||
{ | ||||
"id" : "<userid>", | ||||
"username" : "<username>", | ||||
"firstname": "<firstname>", | ||||
"lastname" : "<lastname>", | ||||
"email" : "<email>", | ||||
"active" : "<bool>", | ||||
"admin" :Â "<bool>", | ||||
"ldap" : "<ldap_dn>" | ||||
}, | ||||
… | ||||
] | ||||
} | ||||
] | ||||
error : null | ||||
r1500 | create_users_group | |||
------------------ | ||||
Nicolas VINOT
|
r1592 | Creates new users group. This command can be executed only using api_key | ||
r1500 | belonging to user with admin rights | |||
INPUT:: | ||||
Nicolas VINOT
|
r1592 | api_key : "<api_key>" | ||
method : "create_users_group" | ||||
args: { | ||||
r1843 | "group_name": "<groupname>", | |||
Nicolas VINOT
|
r1592 | "active":"<bool> = True" | ||
} | ||||
OUTPUT:: | ||||
result: { | ||||
"id": "<newusersgroupid>", | ||||
r1843 | "msg": "created new users group <groupname>" | |||
Nicolas VINOT
|
r1592 | } | ||
error: null | ||||
r1793 | add_user_to_users_group | |||
----------------------- | ||||
Nicolas VINOT
|
r1592 | |||
Adds a user to a users group. This command can be executed only using api_key | ||||
belonging to user with admin rights | ||||
INPUT:: | ||||
api_key : "<api_key>" | ||||
method : "add_user_users_group" | ||||
args: { | ||||
"group_name" : "<groupname>", | ||||
r1810 | "username" : "<username>" | |||
Nicolas VINOT
|
r1592 | } | ||
OUTPUT:: | ||||
result: { | ||||
"id": "<newusersgroupmemberid>", | ||||
"msg": "created new users group member" | ||||
} | ||||
error: null | ||||
r1843 | get_repo | |||
-------- | ||||
Gets an existing repository. This command can be executed only using api_key | ||||
belonging to user with admin rights | ||||
INPUT:: | ||||
api_key : "<api_key>" | ||||
method : "get_repo" | ||||
args: { | ||||
"repo_name" : "<reponame>" | ||||
} | ||||
OUTPUT:: | ||||
result: None if repository does not exist or | ||||
{ | ||||
"id" : "<id>", | ||||
"repo_name" : "<reponame>" | ||||
"type" : "<type>", | ||||
"description" : "<description>", | ||||
"members" : [ | ||||
{ "id" : "<userid>", | ||||
"username" : "<username>", | ||||
"firstname": "<firstname>", | ||||
"lastname" : "<lastname>", | ||||
"email" : "<email>", | ||||
"active" : "<bool>", | ||||
"admin" :Â "<bool>", | ||||
"ldap" : "<ldap_dn>", | ||||
"permission" : "repository.(read|write|admin)" | ||||
}, | ||||
… | ||||
{ | ||||
"id" : "<usersgroupid>", | ||||
"name" : "<usersgroupname>", | ||||
"active": "<bool>", | ||||
"permission" : "repository.(read|write|admin)" | ||||
}, | ||||
… | ||||
] | ||||
} | ||||
error: null | ||||
Nicolas VINOT
|
r1592 | get_repos | ||
--------- | ||||
Lists all existing repositories. This command can be executed only using api_key | ||||
belonging to user with admin rights | ||||
INPUT:: | ||||
api_key : "<api_key>" | ||||
method : "get_repos" | ||||
args: { } | ||||
r1500 | ||||
OUTPUT:: | ||||
Nicolas VINOT
|
r1592 | result: [ | ||
{ | ||||
"id" : "<id>", | ||||
r1843 | "repo_name" : "<reponame>" | |||
Nicolas VINOT
|
r1592 | "type" : "<type>", | ||
"description" : "<description>" | ||||
}, | ||||
… | ||||
] | ||||
error: null | ||||
r1810 | get_repo_nodes | |||
-------------- | ||||
returns a list of nodes and it's children in a flat list for a given path | ||||
r1843 | at given revision. It's possible to specify ret_type to show only `files` or | |||
`dirs`. This command can be executed only using api_key belonging to user | ||||
r1810 | with admin rights | |||
INPUT:: | ||||
api_key : "<api_key>" | ||||
method : "get_repo_nodes" | ||||
args: { | ||||
r1843 | "repo_name" : "<reponame>", | |||
r1810 | "revision" : "<revision>", | |||
"root_path" : "<root_path>", | ||||
"ret_type" : "<ret_type>" = 'all' | ||||
} | ||||
OUTPUT:: | ||||
result: [ | ||||
{ | ||||
"name" : "<name>" | ||||
"type" : "<type>", | ||||
}, | ||||
… | ||||
] | ||||
error: null | ||||
Nicolas VINOT
|
r1592 | create_repo | ||
----------- | ||||
Creates a repository. This command can be executed only using api_key | ||||
belonging to user with admin rights. | ||||
If repository name contains "/", all needed repository groups will be created. | ||||
For example "foo/bar/baz" will create groups "foo", "bar" (with "foo" as parent), | ||||
and create "baz" repository with "bar" as group. | ||||
INPUT:: | ||||
api_key : "<api_key>" | ||||
method : "create_repo" | ||||
args: { | ||||
r1843 | "repo_name" : "<reponame>", | |||
Nicolas VINOT
|
r1592 | "owner_name" : "<ownername>", | ||
"description" : "<description> = ''", | ||||
"repo_type" : "<type> = 'hg'", | ||||
"private" : "<bool> = False" | ||||
} | ||||
OUTPUT:: | ||||
r1843 | result: { | |||
"id": "<newrepoid>", | ||||
"msg": "Created new repository <reponame>", | ||||
} | ||||
Nicolas VINOT
|
r1592 | error: null | ||
add_user_to_repo | ||||
---------------- | ||||
Add a user to a repository. This command can be executed only using api_key | ||||
belonging to user with admin rights. | ||||
If "perm" is None, user will be removed from the repository. | ||||
INPUT:: | ||||
api_key : "<api_key>" | ||||
method : "add_user_to_repo" | ||||
args: { | ||||
"repo_name" : "<reponame>", | ||||
r1843 | "username" : "<username>", | |||
r1793 | "perm" : "(None|repository.(read|write|admin))", | |||
Nicolas VINOT
|
r1592 | } | ||
OUTPUT:: | ||||
r1843 | result: { | |||
"msg" : "Added perm: <perm> for <username> in repo: <reponame>" | ||||
} | ||||
Nicolas VINOT
|
r1592 | error: null | ||
r1793 | ||||
add_users_group_to_repo | ||||
----------------------- | ||||
Add a users group to a repository. This command can be executed only using | ||||
api_key belonging to user with admin rights. If "perm" is None, group will | ||||
be removed from the repository. | ||||
INPUT:: | ||||
api_key : "<api_key>" | ||||
method : "add_users_group_to_repo" | ||||
args: { | ||||
"repo_name" : "<reponame>", | ||||
r1843 | "group_name" : "<groupname>", | |||
r1793 | "perm" : "(None|repository.(read|write|admin))", | |||
r1843 | } | |||
OUTPUT:: | ||||
result: { | ||||
"msg" : Added perm: <perm> for <groupname> in repo: <reponame>" | ||||
} | ||||