.. _api: === API === Kallithea has a simple JSON RPC API with a single schema for calling all API methods. Everything is available by sending JSON encoded http(s) requests to ``/_admin/api``. API keys -------- Every Kallithea user automatically receives an API key, which they can view under "My Account". On this page, API keys can also be revoked, and additional API keys can be generated. API access ---------- Clients must send JSON encoded JSON-RPC requests:: { "id": "", "api_key": "", "method": "", "args": {"": ""} } For example, to pull to a local "CPython" mirror using curl:: curl https://kallithea.example.com/_admin/api -X POST -H 'content-type:text/plain' \ --data-binary '{"id":1,"api_key":"xe7cdb2v278e4evbdf5vs04v832v0efvcbcve4a3","method":"pull","args":{"repoid":"CPython"}}' In general, provide - *id*, a value of any type, can be used to match the response with the request that it is replying to. - *api_key*, for authentication and permission validation. - *method*, the name of the method to call -- a list of available methods can be found below. - *args*, the arguments to pass to the method. .. note:: api_key can be found or set on the user account page. The response to the JSON-RPC API call will always be a JSON structure:: { "id": , # the id that was used in the request "result": |null, # JSON formatted result (null on error) "error": null| # JSON formatted error (null on success) } All responses from the API will be ``HTTP/1.0 200 OK``. If an error occurs, the reponse will have a failure description in *error* and *result* will be null. API client ---------- Kallithea comes with a ``kallithea-api`` command line tool, providing a convenient way to call the JSON-RPC API. For example, to call ``get_repo``:: kallithea-api --apihost= --apikey= get_repo Calling method get_repo => Server response ERROR:"Missing non optional `repoid` arg in JSON DATA" Oops, looks like we forgot to add an argument. Let's try again, now providing the ``repoid`` as a parameter:: kallithea-api --apihost= --apikey= get_repo repoid:myrepo Calling method get_repo => Server response { "clone_uri": null, "created_on": "2015-08-31T14:55:19.042", ... To avoid specifying ``apihost`` and ``apikey`` every time, run:: kallithea-api --save-config --apihost= --apikey= This will create a ``~/.config/kallithea`` with the specified URL and API key so you don't have to specify them every time. API methods ----------- pull ^^^^ Pull the given repo from remote location. Can be used to automatically keep remote repos up to date. This command can only be executed using the api_key of a user with admin rights. INPUT:: id : api_key : "" method : "pull" args : { "repoid" : "" } OUTPUT:: id : result : "Pulled from ``" error : null rescan_repos ^^^^^^^^^^^^ Rescan repositories. If ``remove_obsolete`` is set, Kallithea will delete repos that are in the database but not in the filesystem. This command can only be executed using the api_key of a user with admin rights. INPUT:: id : api_key : "" method : "rescan_repos" args : { "remove_obsolete" : "" } OUTPUT:: id : result : "{'added': [], 'removed': []}" error : null invalidate_cache ^^^^^^^^^^^^^^^^ Invalidate the cache for a repository. 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. INPUT:: id : api_key : "" method : "invalidate_cache" args : { "repoid" : "" } OUTPUT:: id : result : "Caches of repository ``" error : null get_ip ^^^^^^ Return IP address as seen from Kallithea server, together with all defined IP addresses for given user. This command can only be executed using the api_key of a user with admin rights. INPUT:: id : api_key : "" method : "get_ip" args : { "userid" : "" } OUTPUT:: id : result : { "ip_addr_server" : ", "user_ips" : [ { "ip_addr" : "", "ip_range" : ["", ""] }, ... ] } error : null get_user ^^^^^^^^ Get a user by username or userid. The result is empty if user can't be found. If userid param is skipped, it is set to id of user who is calling this method. Any userid can be specified when the command is executed using the api_key of a user with admin rights. Regular users can only specify their own userid. INPUT:: id : api_key : "" method : "get_user" args : { "userid" : "" } OUTPUT:: id : result : None if user does not exist or { "user_id" : "", "api_key" : "", "username" : "", "firstname" : "", "lastname" : "", "email" : "", "emails" : "", "ip_addresses": "", "active" : "", "admin" : "", "ldap_dn" : "", "last_login" : "", "permissions": { "global": ["hg.create.repository", "repository.read", "hg.register.manual_activate"], "repositories" : {"repo1" : "repository.none"}, "repositories_groups" : {"Group1" : "group.read"} } } error : null get_users ^^^^^^^^^ List all existing users. This command can only be executed using the api_key of a user with admin rights. INPUT:: id : api_key : "" method : "get_users" args : { } OUTPUT:: id : result : [ { "user_id" : "", "api_key" : "", "username" : "", "firstname" : "", "lastname" : "", "email" : "", "emails" : "", "ip_addresses": "", "active" : "", "admin" : "", "ldap_dn" : "", "last_login" : "" }, … ] error : null .. _create-user: create_user ^^^^^^^^^^^ Create new user. This command can only be executed using the api_key of a user with admin rights. INPUT:: id : api_key : "" method : "create_user" args : { "username" : "", "email" : "", "password" : "", "firstname" : " = Optional(None)", "lastname" : " = Optional(None)", "active" : " = Optional(True)", "admin" : " = Optional(False)", "ldap_dn" : " = Optional(None)" } OUTPUT:: id : result : { "msg" : "created new user ``", "user" : { "user_id" : "", "username" : "", "firstname": "", "lastname" : "", "email" : "", "emails" : "", "active" : "", "admin" : "", "ldap_dn" : "", "last_login": "" } } error : null Example:: kallithea-api create_user username:bent email:bent@example.com firstname:Bent lastname:Bentsen extern_type:ldap extern_name:uid=bent,dc=example,dc=com update_user ^^^^^^^^^^^ Update the given user if such user exists. This command can only be executed using the api_key of a user with admin rights. INPUT:: id : api_key : "" method : "update_user" args : { "userid" : "", "username" : " = Optional(None)", "email" : " = Optional(None)", "password" : " = Optional(None)", "firstname" : " = Optional(None)", "lastname" : " = Optional(None)", "active" : " = Optional(None)", "admin" : " = Optional(None)", "ldap_dn" : " = Optional(None)" } OUTPUT:: id : result : { "msg" : "updated user ID: ", "user" : { "user_id" : "", "api_key" : "", "username" : "", "firstname": "", "lastname" : "", "email" : "", "emails" : "", "active" : "", "admin" : "", "ldap_dn" : "", "last_login": "" } } error : null delete_user ^^^^^^^^^^^ Delete the given user if such a user exists. This command can only be executed using the api_key of a user with admin rights. INPUT:: id : api_key : "" method : "delete_user" args : { "userid" : "" } OUTPUT:: id : result : { "msg" : "deleted user ID: ", "user" : null } error : null get_user_group ^^^^^^^^^^^^^^ Get an existing user group. This command can only be executed using the api_key of a user with admin rights. INPUT:: id : api_key : "" method : "get_user_group" args : { "usergroupid" : "" } OUTPUT:: id : result : None if group not exist { "users_group_id" : "", "group_name" : "", "active" : "", "members" : [ { "user_id" : "", "api_key" : "", "username" : "", "firstname": "", "lastname" : "", "email" : "", "emails" : "", "active" : "", "admin" : "", "ldap_dn" : "", "last_login": "" }, … ] } error : null get_user_groups ^^^^^^^^^^^^^^^ List all existing user groups. This command can only be executed using the api_key of a user with admin rights. INPUT:: id : api_key : "" method : "get_user_groups" args : { } OUTPUT:: id : result : [ { "users_group_id" : "", "group_name" : "", "active" : "" }, … ] error : null create_user_group ^^^^^^^^^^^^^^^^^ Create a new user group. This command can only be executed using the api_key of a user with admin rights. INPUT:: id : api_key : "" method : "create_user_group" args : { "group_name": "", "owner" : "", "active" : " = Optional(True)" } OUTPUT:: id : result : { "msg" : "created new user group ``", "users_group" : { "users_group_id" : "", "group_name" : "", "active" : "" } } error : null add_user_to_user_group ^^^^^^^^^^^^^^^^^^^^^^ Add a user to a user group. If the user already is in that group, success will be ``false``. This command can only be executed using the api_key of a user with admin rights. INPUT:: id : api_key : "" method : "add_user_user_group" args : { "usersgroupid" : "", "userid" : "" } OUTPUT:: id : result : { "success" : True|False, # depends on if member is in group "msg" : "added member `` to a user group `` | User is already in that group" } error : null remove_user_from_user_group ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Remove a user from a user group. If the user isn't in the given group, success will be ``false``. This command can only be executed using the api_key of a user with admin rights. INPUT:: id : api_key : "" method : "remove_user_from_user_group" args : { "usersgroupid" : "", "userid" : "" } OUTPUT:: id : result : { "success" : True|False, # depends on if member is in group "msg" : "removed member from user group | User wasn't in group" } error : null get_repo_group ^^^^^^^^^^^^^^ Get an existing repository group. This command can only be executed using the api_key of a user with admin rights. INPUT:: id : api_key : "" method : "get_repo_group" args : { "repogroupid" : "" } OUTPUT:: id : result : { "group_id" : "", "group_name" : "", "group_description" : "", "parent_group" : ""|null, "repositories" : "", "owner" : "", "members" : [ { "name" : "", "type" : "user", "permission" : "group.(none|read|write|admin)" }, { "name" : "", "type" : "user_group", "permission" : "group.(none|read|write|admin)" }, … ] }, error : null get_repo_groups ^^^^^^^^^^^^^^^ List all existing repository groups. This command can only be executed using the api_key of a user with admin rights. INPUT:: id : api_key : "" method : "get_repo_groups" args : { } OUTPUT:: id : result : [ { "group_id" : "", "group_name" : "", "group_description" : "", "parent_group" : ""|null, "repositories" : "", "owner" : "" }, … ] error : null create_repo_group ^^^^^^^^^^^^^^^^^ Create a new repository group. This command can only be executed using the api_key of a user with admin rights. INPUT:: id : api_key : "" method : "create_repo_group" args : { "group_name" : "", "description" : " = Optional("")", "owner" : " = Optional(None)", "parent" : " = Optional(None)", "copy_permissions" : " = Optional(False)" } OUTPUT:: id : result : { "msg" : "created new repo group ``", "repo_group" : { "group_id" : , "group_name" : "/", "group_description" : "", "parent_group" : |null, "repositories" : , "owner" : "" } update_repo_group ^^^^^^^^^^^^^^^^^ Update a repository group. This command can only be executed using the api_key of a user with admin rights. INPUT:: id : api_key : "" method : "update_repo_group" args : { "repogroupid" : "", "group_name" : " = Optional(None)", "description" : " = Optional(None)", "owner" : " = Optional(None)", "parent" : " = Optional(None)" } OUTPUT:: id : result : { "msg" : "updated repository group ID: ", "repo_group" : { "group_id" : , "group_name" : "/", "group_description" : "", "parent_group" : |null, "repositories" : , "owner" : "" } delete_repo_group ^^^^^^^^^^^^^^^^^ Delete a repository group. This command can only be executed using the api_key of a user with admin rights. INPUT:: id : api_key : "" method : "delete_repo_group" args : { "repogroupid" : "" } OUTPUT:: id : result : { "msg" : "deleted repo group ID: ", "repo_group" : null } get_repo ^^^^^^^^ Get an existing repository by its name or repository_id. Members will contain either users_group or users associated to that repository. This command can only be executed using the api_key of a user with admin rights, or that of a regular user with at least read access to the repository. INPUT:: id : api_key : "" method : "get_repo" args : { "repoid" : "", "with_revision_names" : " = Optional(False)", "with_pullrequests" : " = Optional(False)" } OUTPUT:: id : result : None if repository does not exist or { "repo_id" : "", "repo_name" : "", "repo_type" : "", "clone_uri" : "", "enable_downloads" : "", "enable_statistics": "", "private" : "", "created_on" : "", "description" : "", "landing_rev" : "", "last_changeset" : { "author" : "", "date" : "", "message" : "", "raw_id" : "", "revision": "", "short_id": "" }, "owner" : "", "fork_of" : "", "members" : [ { "type" : "user", "user_id" : "", "api_key" : "", "username" : "", "firstname" : "", "lastname" : "", "email" : "", "emails" : "", "active" : "", "admin" : "", "ldap_dn" : "", "last_login" : "", "permission" : "repository.(read|write|admin)" }, … { "type" : "users_group", "id" : "", "name" : "", "active" : "", "permission" : "repository.(read|write|admin)" }, … ], "followers" : [ { "user_id" : "", "username" : "", "api_key" : "", "firstname" : "", "lastname" : "", "email" : "", "emails" : "", "ip_addresses": "", "active" : "", "admin" : "", "ldap_dn" : "", "last_login" : "" }, … ], "tags" : { "" : "", ... }, "branches" : { "" : "", ... }, "bookmarks" : { "" : "", ... }, "pull_requests" : [ { "status" : "", "pull_request_id" : , "description" : "", "title" : "", "url" : "", "reviewers" : [ { "username" : "" }, ... ], "org_repo_url" : "", "org_ref_parts" : [ "", "", "" ], "other_ref_parts" : [ "", "", "" ], "comments" : [ { "username" : "", "text" : "", "comment_id" : "" }, ... ], "owner" : "", "statuses" : [ { "status" : "", # "under_review", "approved" or "rejected" "reviewer" : "", "modified_at" : "" # iso 8601 date, server's timezone }, ... ], "revisions" : [ "", ... ] }, ... ] } error : null get_repos ^^^^^^^^^ List all existing repositories. This command can only be executed using the api_key of a user with admin rights, or that of a regular user with at least read access to the repository. INPUT:: id : api_key : "" method : "get_repos" args : { } OUTPUT:: id : result : [ { "repo_id" : "", "repo_name" : "", "repo_type" : "", "clone_uri" : "", "private" : "", "created_on" : "", "description" : "", "landing_rev" : "", "owner" : "", "fork_of" : "", "enable_downloads" : "", "enable_statistics": "" }, … ] error : null get_repo_nodes ^^^^^^^^^^^^^^ Return a list of files and directories for a given path at the given revision. It is possible to specify ret_type to show only ``files`` or ``dirs``. This command can only be executed using the api_key of a user with admin rights. INPUT:: id : api_key : "" method : "get_repo_nodes" args : { "repoid" : "", "revision" : "", "root_path" : "", "ret_type" : " = Optional('all')" } OUTPUT:: id : result : [ { "name" : "", "type" : "" }, … ] error : null create_repo ^^^^^^^^^^^ Create a repository. If the repository name contains "/", the repository will be created in the repository group indicated by that path. Any such repository groups need to exist before calling this method, or the call will fail. For example "foo/bar/baz" will create a repository "baz" inside the repository group "bar" which itself is in a repository group "foo", but both "foo" and "bar" already need to exist before calling this method. This command can only be executed using the api_key of a user with admin rights, or that of a regular user with create repository permission. Regular users cannot specify owner parameter. INPUT:: id : api_key : "" method : "create_repo" args : { "repo_name" : "", "owner" : "", "repo_type" : " = Optional('hg')", "description" : " = Optional('')", "private" : " = Optional(False)", "clone_uri" : " = Optional(None)", "landing_rev" : " = Optional('tip')", "enable_downloads" : " = Optional(False)", "enable_statistics": " = Optional(False)" } OUTPUT:: id : result : { "msg" : "Created new repository ``", "repo" : { "repo_id" : "", "repo_name" : "", "repo_type" : "", "clone_uri" : "", "private" : "", "created_on" : "", "description" : "", "landing_rev" : "", "owner" : "", "fork_of" : "", "enable_downloads" : "", "enable_statistics": "" } } error : null update_repo ^^^^^^^^^^^ Update a repository. This command can only be executed using the api_key of a user with admin rights, or that of a regular user with create repository permission. Regular users cannot specify owner parameter. INPUT:: id : api_key : "" method : "update_repo" args : { "repoid" : "", "name" : " = Optional('')", "group" : " = Optional(None)", "owner" : "", "description" : " = Optional('')", "private" : " = Optional(False)", "clone_uri" : " = Optional(None)", "landing_rev" : " = Optional('tip')", "enable_downloads" : " = Optional(False)", "enable_statistics": " = Optional(False)" } OUTPUT:: id : result : { "msg" : "updated repo ID:repo_id ``", "repository" : { "repo_id" : "", "repo_name" : "", "repo_type" : "", "clone_uri" : "", "private" : "", "created_on" : "", "description" : "", "landing_rev" : "", "owner" : "", "fork_of" : "", "enable_downloads" : "", "enable_statistics": "", "last_changeset" : { "author" : "", "date" : "", "message" : "", "raw_id" : "", "revision": "", "short_id": "" } } } error : null fork_repo ^^^^^^^^^ Create a fork of the given repo. If using Celery, this will return success message immediately and a fork will be created asynchronously. This command can only be executed using the api_key of a user with admin rights, or with the global fork permission, by a regular user with create repository permission and at least read access to the repository. Regular users cannot specify owner parameter. INPUT:: id : api_key : "" method : "fork_repo" args : { "repoid" : "", "fork_name" : "", "owner" : "", "description" : "", "copy_permissions": "", "private" : "", "landing_rev" : "" } OUTPUT:: id : result : { "msg" : "Created fork of `` as ``", "success" : true } error : null delete_repo ^^^^^^^^^^^ Delete a repository. This command can only be executed using the api_key of a user with admin rights, or that of a regular user with admin access to the repository. When ``forks`` param is set it is possible to detach or delete forks of the deleted repository. INPUT:: id : api_key : "" method : "delete_repo" args : { "repoid" : "", "forks" : "`delete` or `detach` = Optional(None)" } OUTPUT:: id : result : { "msg" : "Deleted repository ``", "success" : true } error : null grant_user_permission ^^^^^^^^^^^^^^^^^^^^^ Grant permission for a user on the given repository, or update the existing one if found. This command can only be executed using the api_key of a user with admin rights. INPUT:: id : api_key : "" method : "grant_user_permission" args : { "repoid" : "", "userid" : "", "perm" : "(repository.(none|read|write|admin))" } OUTPUT:: id : result : { "msg" : "Granted perm: `` for user: `` in repo: ``", "success" : true } error : null revoke_user_permission ^^^^^^^^^^^^^^^^^^^^^^ Revoke permission for a user on the given repository. This command can only be executed using the api_key of a user with admin rights. INPUT:: id : api_key : "" method : "revoke_user_permission" args : { "repoid" : "", "userid" : "" } OUTPUT:: id : result : { "msg" : "Revoked perm for user: `` in repo: ``", "success" : true } error : null grant_user_group_permission ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Grant permission for a user group on the given repository, or update the existing one if found. This command can only be executed using the api_key of a user with admin rights. INPUT:: id : api_key : "" method : "grant_user_group_permission" args : { "repoid" : "", "usersgroupid" : "", "perm" : "(repository.(none|read|write|admin))" } OUTPUT:: id : result : { "msg" : "Granted perm: `` for group: `` in repo: ``", "success" : true } error : null revoke_user_group_permission ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Revoke permission for a user group on the given repository. This command can only be executed using the api_key of a user with admin rights. INPUT:: id : api_key : "" method : "revoke_user_group_permission" args : { "repoid" : "", "usersgroupid" : "" } OUTPUT:: id : result : { "msg" : "Revoked perm for group: `` in repo: ``", "success" : true } error : null get_changesets ^^^^^^^^^^^^^^ Get changesets of a given repository. This command can only be executed using the api_key of a user with read permissions to the repository. INPUT:: id : api_key : "" method : "get_changesets" args : { "repoid" : "", "start" : " = Optional(None)", "end" : " = Optional(None)", "start_date" : " = Optional(None)", # in "%Y-%m-%dT%H:%M:%S" format "end_date" : " = Optional(None)", # in "%Y-%m-%dT%H:%M:%S" format "branch_name" : " = Optional(None)", "reverse" : " = Optional(False)", "with_file_list" : " = Optional(False)" } OUTPUT:: id : result : [ { "raw_id" : "", "short_id" : "", "author" : "", "date" : "", "message" : "", "revision" : "", "added" : [], "changed" : [], "removed" : [] }, ... ] error : null get_changeset ^^^^^^^^^^^^^ Get information and review status for a given changeset. This command can only be executed using the api_key of a user with read permissions to the repository. INPUT:: id : api_key : "" method : "get_changeset" args : { "repoid" : "", "raw_id" : "", "with_reviews" : " = Optional(False)" } OUTPUT:: id : result : { "author" : "", "date" : "", "message" : "", "raw_id" : "", "revision": "", "short_id": "", "reviews" : [{ "reviewer" : "", "modified_at" : "", # iso 8601 date, server's timezone "status" : "", # "under_review", "approved" or "rejected" }, ... ] } error : null Example output:: { "id" : 1, "error" : null, "result" : { "author" : { "email" : "user@example.com", "name" : "Kallithea Admin" }, "changed" : [], "short_id" : "e1022d3d28df", "date" : "2017-03-28T09:09:03", "added" : [ "README.rst" ], "removed" : [], "revision" : 0, "raw_id" : "e1022d3d28dfba02f626cde65dbe08f4ceb0e4e7", "message" : "Added file via Kallithea", "id" : "e1022d3d28dfba02f626cde65dbe08f4ceb0e4e7", "reviews" : [ { "status" : "under_review", "modified_at" : "2017-03-28T09:17:08.618", "reviewer" : "user" } ] } } get_pullrequest ^^^^^^^^^^^^^^^ Get information and review status for a given pull request. This command can only be executed using the api_key of a user with read permissions to the original repository. INPUT:: id : api_key : "" method : "get_pullrequest" args : { "pullrequest_id" : "" } OUTPUT:: id : result : { "status" : "", "pull_request_id" : , "description" : "", "title" : "", "url" : "", "reviewers" : [ { "username" : "" }, ... ], "org_repo_url" : "", "org_ref_parts" : [ "", "", "" ], "other_ref_parts" : [ "", "", "" ], "comments" : [ { "username" : "", "text" : "", "comment_id" : "" }, ... ], "owner" : "", "statuses" : [ { "status" : "", # "under_review", "approved" or "rejected" "reviewer" : "", "modified_at" : "" # iso 8601 date, server's timezone }, ... ], "revisions" : [ "", ... ] }, error : null comment_pullrequest ^^^^^^^^^^^^^^^^^^^ Add comment, change status or close a given pull request. This command can only be executed using the api_key of a user with read permissions to the original repository. INPUT:: id : api_key : "" method : "comment_pullrequest" args : { "pull_request_id" : "", "comment_msg" : Optional(''), "status" : Optional(None), # "under_review", "approved" or "rejected" "close_pr" : Optional(False)" } OUTPUT:: id : result : True error : null API access for web views ------------------------ Kallithea HTTP entry points can also be accessed without login using bearer authentication by including this header with the request:: Authentication: Bearer Alternatively, the API key can be passed in the URL query string using ``?api_key=``, though this is not recommended due to the increased risk of API key leaks, and support will likely be removed in the future. Exposing raw diffs is a good way to integrate with third-party services like code review, or build farms that can download archives.