Files @ 2dd317e9cc4b
Branch filter:

Location: kallithea/docs/api/api.rst

2dd317e9cc4b 38.5 KiB text/prs.fallenstein.rst Show Annotation Show as Raw Download as Raw
Mads Kiilerich
api docs: make examples use comma more like json does
   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
.. _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
``<your_server>/_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: "<id>",
        "api_key": "<api_key>",
        "method": "<method_name>",
        "args": {"<arg_key>": "<arg_val>"}
    }

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": <id>,  # the id that was used in the request
        "result": <result>|null,  # JSON formatted result (null on error)
        "error": null|<error_message>  # 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=<Kallithea URL> --apikey=<API key> get_repo

    Calling method get_repo => <Kallithea URL>
    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=<Kallithea URL> --apikey=<API key> get_repo repoid:myrepo

    Calling method get_repo => <Kallithea URL>
    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=<Kallithea URL> --apikey=<API key>

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 : <id_for_response>
    api_key : "<api_key>"
    method :  "pull"
    args :    {
                "repoid" : "<reponame or repo_id>"
              }

OUTPUT::

    id : <id_given_in_input>
    result : "Pulled from `<reponame>`"
    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 : <id_for_response>
    api_key : "<api_key>"
    method :  "rescan_repos"
    args :    {
                "remove_obsolete" : "<boolean = Optional(False)>"
              }

OUTPUT::

    id : <id_given_in_input>
    result : "{'added': [<list of names of added repos>],
               'removed': [<list of names of removed repos>]}"
    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 : <id_for_response>
    api_key : "<api_key>"
    method :  "invalidate_cache"
    args :    {
                "repoid" : "<reponame or repo_id>"
              }

OUTPUT::

    id : <id_given_in_input>
    result : "Caches of repository `<reponame>`"
    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 : <id_for_response>
    api_key : "<api_key>"
    method :  "get_ip"
    args :    {
                "userid" : "<user_id or username>"
              }

OUTPUT::

    id : <id_given_in_input>
    result : {
                 "ip_addr_server" : <ip_from_client>",
                 "user_ips" : [
                                {
                                   "ip_addr" : "<ip_with_mask>",
                                   "ip_range" : ["<start_ip>", "<end_ip>"]
                                },
                                ...
                              ]
             }
    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 : <id_for_response>
    api_key : "<api_key>"
    method :  "get_user"
    args :    {
                "userid" : "<username or user_id Optional(=apiuser)>"
              }

OUTPUT::

    id : <id_given_in_input>
    result : None if user does not exist or
             {
                "user_id" :     "<user_id>",
                "api_key" :     "<api_key>",
                "username" :    "<username>",
                "firstname" :   "<firstname>",
                "lastname" :    "<lastname>",
                "email" :       "<email>",
                "emails" :      "<list_of_all_additional_emails>",
                "ip_addresses": "<list_of_ip_addresses_for_user>",
                "active" :      "<bool>",
                "admin" :       "<bool>",
                "ldap_dn" :     "<ldap_dn>",
                "last_login" :  "<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 : <id_for_response>
    api_key : "<api_key>"
    method :  "get_users"
    args :    { }

OUTPUT::

    id : <id_given_in_input>
    result : [
              {
                "user_id" :     "<user_id>",
                "api_key" :     "<api_key>",
                "username" :    "<username>",
                "firstname" :   "<firstname>",
                "lastname" :    "<lastname>",
                "email" :       "<email>",
                "emails" :      "<list_of_all_additional_emails>",
                "ip_addresses": "<list_of_ip_addresses_for_user>",
                "active" :      "<bool>",
                "admin" :       "<bool>",
                "ldap_dn" :     "<ldap_dn>",
                "last_login" :  "<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 : <id_for_response>
    api_key : "<api_key>"
    method :  "create_user"
    args :    {
                "username" :  "<username>",
                "email" :     "<useremail>",
                "password" :  "<password = Optional(None)>",
                "firstname" : "<firstname> = Optional(None)",
                "lastname" :  "<lastname> = Optional(None)",
                "active" :    "<bool> = Optional(True)",
                "admin" :     "<bool> = Optional(False)",
                "ldap_dn" :   "<ldap_dn> = Optional(None)"
              }

OUTPUT::

    id : <id_given_in_input>
    result : {
              "msg" : "created new user `<username>`",
              "user" : {
                "user_id" :  "<user_id>",
                "username" : "<username>",
                "firstname": "<firstname>",
                "lastname" : "<lastname>",
                "email" :    "<email>",
                "emails" :   "<list_of_all_additional_emails>",
                "active" :   "<bool>",
                "admin" :    "<bool>",
                "ldap_dn" :  "<ldap_dn>",
                "last_login": "<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 : <id_for_response>
    api_key : "<api_key>"
    method :  "update_user"
    args :    {
                "userid" : "<user_id or username>",
                "username" :  "<username> = Optional(None)",
                "email" :     "<useremail> = Optional(None)",
                "password" :  "<password> = Optional(None)",
                "firstname" : "<firstname> = Optional(None)",
                "lastname" :  "<lastname> = Optional(None)",
                "active" :    "<bool> = Optional(None)",
                "admin" :     "<bool> = Optional(None)",
                "ldap_dn" :   "<ldap_dn> = Optional(None)"
              }

OUTPUT::

    id : <id_given_in_input>
    result : {
              "msg" : "updated user ID:<userid> <username>",
              "user" : {
                "user_id" :  "<user_id>",
                "api_key" :  "<api_key>",
                "username" : "<username>",
                "firstname": "<firstname>",
                "lastname" : "<lastname>",
                "email" :    "<email>",
                "emails" :   "<list_of_all_additional_emails>",
                "active" :   "<bool>",
                "admin" :    "<bool>",
                "ldap_dn" :  "<ldap_dn>",
                "last_login": "<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 : <id_for_response>
    api_key : "<api_key>"
    method :  "delete_user"
    args :    {
                "userid" : "<user_id or username>"
              }

OUTPUT::

    id : <id_given_in_input>
    result : {
              "msg" : "deleted user ID:<userid> <username>",
              "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 : <id_for_response>
    api_key : "<api_key>"
    method :  "get_user_group"
    args :    {
                "usergroupid" : "<user group id or name>"
              }

OUTPUT::

    id : <id_given_in_input>
    result : None if group not exist
             {
               "users_group_id" : "<id>",
               "group_name" :     "<groupname>",
               "active" :         "<bool>",
               "members" :  [
                              {
                                "user_id" :  "<user_id>",
                                "api_key" :  "<api_key>",
                                "username" : "<username>",
                                "firstname": "<firstname>",
                                "lastname" : "<lastname>",
                                "email" :    "<email>",
                                "emails" :   "<list_of_all_additional_emails>",
                                "active" :   "<bool>",
                                "admin" :    "<bool>",
                                "ldap_dn" :  "<ldap_dn>",
                                "last_login": "<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 : <id_for_response>
    api_key : "<api_key>"
    method :  "get_user_groups"
    args :    { }

OUTPUT::

    id : <id_given_in_input>
    result : [
               {
               "users_group_id" : "<id>",
               "group_name" :     "<groupname>",
               "active" :         "<bool>"
               },

              ]
    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 : <id_for_response>
    api_key : "<api_key>"
    method :  "create_user_group"
    args :    {
                "group_name": "<groupname>",
                "owner" :     "<owner_name_or_id = Optional(=apiuser)>",
                "active" :    "<bool> = Optional(True)"
              }

OUTPUT::

    id : <id_given_in_input>
    result : {
              "msg" : "created new user group `<groupname>`",
              "users_group" : {
                     "users_group_id" : "<id>",
                     "group_name" :     "<groupname>",
                     "active" :         "<bool>"
               }
             }
    error : null

add_user_to_user_group
^^^^^^^^^^^^^^^^^^^^^^

Adds 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 : <id_for_response>
    api_key : "<api_key>"
    method :  "add_user_user_group"
    args :    {
                "usersgroupid" : "<user group id or name>",
                "userid" : "<user_id or username>"
              }

OUTPUT::

    id : <id_given_in_input>
    result : {
              "success" : True|False,  # depends on if member is in group
              "msg" : "added member `<username>` to a user group `<groupname>` |
                       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 : <id_for_response>
    api_key : "<api_key>"
    method :  "remove_user_from_user_group"
    args :    {
                "usersgroupid" : "<user group id or name>",
                "userid" : "<user_id or username>"
              }

OUTPUT::

    id : <id_given_in_input>
    result : {
              "success" : True|False,  # depends on if member is in group
              "msg" : "removed member <username> from user group <groupname> |
                       User wasn't in group"
             }
    error : 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 : <id_for_response>
    api_key : "<api_key>"
    method :  "get_repo"
    args :    {
                "repoid" : "<reponame or repo_id>",
                "with_revision_names" : "<bool> = Optional(False)",
                "with_pullrequests" : "<bool> = Optional(False)"
              }

OUTPUT::

    id : <id_given_in_input>
    result : None if repository does not exist or
             {
                "repo_id" :          "<repo_id>",
                "repo_name" :        "<reponame>",
                "repo_type" :        "<repo_type>",
                "clone_uri" :        "<clone_uri>",
                "enable_downloads" : "<bool>",
                "enable_statistics": "<bool>",
                "private" :          "<bool>",
                "created_on" :       "<date_time_created>",
                "description" :      "<description>",
                "landing_rev" :      "<landing_rev>",
                "last_changeset" :   {
                                         "author" :  "<full_author>",
                                         "date" :    "<date_time_of_commit>",
                                         "message" : "<commit_message>",
                                         "raw_id" :  "<raw_id>",
                                         "revision": "<numeric_revision>",
                                         "short_id": "<short_id>"
                                     },
                "owner" :            "<repo_owner>",
                "fork_of" :          "<name_of_fork_parent>",
                "members" :   [
                                  {
                                    "type" :       "user",
                                    "user_id" :    "<user_id>",
                                    "api_key" :    "<api_key>",
                                    "username" :   "<username>",
                                    "firstname" :  "<firstname>",
                                    "lastname" :   "<lastname>",
                                    "email" :      "<email>",
                                    "emails" :     "<list_of_all_additional_emails>",
                                    "active" :     "<bool>",
                                    "admin" :      "<bool>",
                                    "ldap_dn" :    "<ldap_dn>",
                                    "last_login" : "<last_login>",
                                    "permission" : "repository.(read|write|admin)"
                                  },

                                  {
                                    "type" :     "users_group",
                                    "id" :       "<usersgroupid>",
                                    "name" :     "<usersgroupname>",
                                    "active" :   "<bool>",
                                    "permission" : "repository.(read|write|admin)"
                                  },

                              ],
                "followers" : [
                                  {
                                    "user_id" :     "<user_id>",
                                    "username" :    "<username>",
                                    "api_key" :     "<api_key>",
                                    "firstname" :   "<firstname>",
                                    "lastname" :    "<lastname>",
                                    "email" :       "<email>",
                                    "emails" :      "<list_of_all_additional_emails>",
                                    "ip_addresses": "<list_of_ip_addresses_for_user>",
                                    "active" :      "<bool>",
                                    "admin" :       "<bool>",
                                    "ldap_dn" :     "<ldap_dn>",
                                    "last_login" :  "<last_login>"
                                  },

                              ],
                <if with_revision_names == True>
                "tags" : {
                            "<tagname>" : "<raw_id>",
                            ...
                        },
                "branches" : {
                            "<branchname>" : "<raw_id>",
                            ...
                        },
                "bookmarks" : {
                            "<bookmarkname>" : "<raw_id>",
                            ...
                        },
                <if with_pullrequests == True>
                "pull_requests" : [
                  {
                    "status" : "<pull_request_status>",
                    "pull_request_id" : <pull_request_id>,
                    "description" : "<pull_request_description>",
                    "title" : "<pull_request_title>",
                    "url" : "<pull_request_url>",
                    "reviewers" : [
                      {
                        "username" : "<user_id>"
                      },
                      ...
                    ],
                    "org_repo_url" : "<repo_url>",
                    "org_ref_parts" : [
                      "<ref_type>",
                      "<ref_name>",
                      "<raw_id>"
                    ],
                    "other_ref_parts" : [
                      "<ref_type>",
                      "<ref_name>",
                      "<raw_id>"
                    ],
                    "comments" : [
                      {
                        "username" : "<user_id>",
                        "text" : "<comment text>",
                        "comment_id" : "<comment_id>"
                      },
                      ...
                    ],
                    "owner" : "<username>",
                    "statuses" : [
                      {
                        "status" : "<status_of_review>",        # "under_review", "approved" or "rejected"
                        "reviewer" : "<user_id>",
                        "modified_at" : "<date_time_of_review>" # iso 8601 date, server's timezone
                      },
                      ...
                    ],
                    "revisions" : [
                      "<raw_id>",
                      ...
                    ]
                  },
                  ...
                ]
             }
    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 : <id_for_response>
    api_key : "<api_key>"
    method :  "get_repos"
    args :    { }

OUTPUT::

    id : <id_given_in_input>
    result : [
              {
                "repo_id" :          "<repo_id>",
                "repo_name" :        "<reponame>",
                "repo_type" :        "<repo_type>",
                "clone_uri" :        "<clone_uri>",
                "private" :          "<bool>",
                "created_on" :       "<datetimecreated>",
                "description" :      "<description>",
                "landing_rev" :      "<landing_rev>",
                "owner" :            "<repo_owner>",
                "fork_of" :          "<name_of_fork_parent>",
                "enable_downloads" : "<bool>",
                "enable_statistics": "<bool>"
              },

             ]
    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 : <id_for_response>
    api_key : "<api_key>"
    method :  "get_repo_nodes"
    args :    {
                "repoid" : "<reponame or repo_id>",
                "revision" :  "<revision>",
                "root_path" : "<root_path>",
                "ret_type" :  "<ret_type> = Optional('all')"
              }

OUTPUT::

    id : <id_given_in_input>
    result : [
              {
                "name" :        "<name>",
                "type" :        "<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 : <id_for_response>
    api_key : "<api_key>"
    method :  "create_repo"
    args :    {
                "repo_name" :        "<reponame>",
                "owner" :            "<owner_name_or_id = Optional(=apiuser)>",
                "repo_type" :        "<repo_type> = Optional('hg')",
                "description" :      "<description> = Optional('')",
                "private" :          "<bool> = Optional(False)",
                "clone_uri" :        "<clone_uri> = Optional(None)",
                "landing_rev" :      "<landing_rev> = Optional('tip')",
                "enable_downloads" : "<bool> = Optional(False)",
                "enable_statistics": "<bool> = Optional(False)"
              }

OUTPUT::

    id : <id_given_in_input>
    result : {
              "msg" : "Created new repository `<reponame>`",
              "repo" : {
                "repo_id" :          "<repo_id>",
                "repo_name" :        "<reponame>",
                "repo_type" :        "<repo_type>",
                "clone_uri" :        "<clone_uri>",
                "private" :          "<bool>",
                "created_on" :       "<datetimecreated>",
                "description" :      "<description>",
                "landing_rev" :      "<landing_rev>",
                "owner" :            "<username or user_id>",
                "fork_of" :          "<name_of_fork_parent>",
                "enable_downloads" : "<bool>",
                "enable_statistics": "<bool>"
              }
             }
    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 : <id_for_response>
    api_key : "<api_key>"
    method :  "update_repo"
    args :    {
                "repoid" :           "<reponame or repo_id>",
                "name" :             "<reponame> = Optional('')",
                "group" :            "<group_id> = Optional(None)",
                "owner" :            "<owner_name_or_id = Optional(=apiuser)>",
                "description" :      "<description> = Optional('')",
                "private" :          "<bool> = Optional(False)",
                "clone_uri" :        "<clone_uri> = Optional(None)",
                "landing_rev" :      "<landing_rev> = Optional('tip')",
                "enable_downloads" : "<bool> = Optional(False)",
                "enable_statistics": "<bool> = Optional(False)"
              }

OUTPUT::

    id : <id_given_in_input>
    result : {
              "msg" : "updated repo ID:repo_id `<reponame>`",
              "repository" : {
                "repo_id" :          "<repo_id>",
                "repo_name" :        "<reponame>",
                "repo_type" :        "<repo_type>",
                "clone_uri" :        "<clone_uri>",
                "private" :          "<bool>",
                "created_on" :       "<datetimecreated>",
                "description" :      "<description>",
                "landing_rev" :      "<landing_rev>",
                "owner" :            "<username or user_id>",
                "fork_of" :          "<name_of_fork_parent>",
                "enable_downloads" : "<bool>",
                "enable_statistics": "<bool>",
                "last_changeset" :   {
                                       "author" :  "<full_author>",
                                       "date" :    "<date_time_of_commit>",
                                       "message" : "<commit_message>",
                                       "raw_id" :  "<raw_id>",
                                       "revision": "<numeric_revision>",
                                       "short_id": "<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 : <id_for_response>
    api_key : "<api_key>"
    method :  "fork_repo"
    args :    {
                "repoid" :          "<reponame or repo_id>",
                "fork_name" :       "<forkname>",
                "owner" :           "<username or user_id = Optional(=apiuser)>",
                "description" :     "<description>",
                "copy_permissions": "<bool>",
                "private" :         "<bool>",
                "landing_rev" :     "<landing_rev>"
              }

OUTPUT::

    id : <id_given_in_input>
    result : {
              "msg" : "Created fork of `<reponame>` as `<forkname>`",
              "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 : <id_for_response>
    api_key : "<api_key>"
    method :  "delete_repo"
    args :    {
                "repoid" : "<reponame or repo_id>",
                "forks" :  "`delete` or `detach` = Optional(None)"
              }

OUTPUT::

    id : <id_given_in_input>
    result : {
              "msg" : "Deleted repository `<reponame>`",
              "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 : <id_for_response>
    api_key : "<api_key>"
    method :  "grant_user_permission"
    args :    {
                "repoid" : "<reponame or repo_id>",
                "userid" : "<username or user_id>",
                "perm" :       "(repository.(none|read|write|admin))"
              }

OUTPUT::

    id : <id_given_in_input>
    result : {
              "msg" : "Granted perm: `<perm>` for user: `<username>` in repo: `<reponame>`",
              "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 : <id_for_response>
    api_key : "<api_key>"
    method :  "revoke_user_permission"
    args :    {
                "repoid" : "<reponame or repo_id>",
                "userid" : "<username or user_id>"
              }

OUTPUT::

    id : <id_given_in_input>
    result : {
              "msg" : "Revoked perm for user: `<username>` in repo: `<reponame>`",
              "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 : <id_for_response>
    api_key : "<api_key>"
    method :  "grant_user_group_permission"
    args :    {
                "repoid" : "<reponame or repo_id>",
                "usersgroupid" : "<user group id or name>",
                "perm" : "(repository.(none|read|write|admin))"
              }

OUTPUT::

    id : <id_given_in_input>
    result : {
              "msg" : "Granted perm: `<perm>` for group: `<usersgroupname>` in repo: `<reponame>`",
              "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 : <id_for_response>
    api_key : "<api_key>"
    method :  "revoke_user_group_permission"
    args :    {
                "repoid" : "<reponame or repo_id>",
                "usersgroupid" : "<user group id or name>"
              }

OUTPUT::

    id : <id_given_in_input>
    result : {
              "msg" : "Revoked perm for group: `<usersgroupname>` in repo: `<reponame>`",
              "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 : <id_for_response>
    api_key : "<api_key>"
    method :  "get_changesets"
    args :    {
                "repoid" : "<reponame or repo_id>",
                "start" : "<revision number> = Optional(None)",
                "end" : "<revision number> = Optional(None)",
                "start_date" : "<date> = Optional(None)",    # in "%Y-%m-%dT%H:%M:%S" format
                "end_date" : "<date> = Optional(None)",      # in "%Y-%m-%dT%H:%M:%S" format
                "branch_name" : "<branch name filter> = Optional(None)",
                "reverse" : "<bool> = Optional(False)",
                "with_file_list" : "<bool> = Optional(False)"
              }

OUTPUT::

    id : <id_given_in_input>
    result : [
    {
      "raw_id" : "<raw_id>",
      "short_id" : "<short_id>",
      "author" : "<full_author>",
      "date" : "<date_time_of_commit>",
      "message" : "<commit_message>",
      "revision" : "<numeric_revision>",
      <if with_file_list == True>
      "added" : [<list of added files>],
      "changed" : [<list of changed files>],
      "removed" : [<list of removed files>]
    },
    ...
    ]
    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 : <id_for_response>
    api_key : "<api_key>"
    method :  "get_changeset"
    args :    {
                "repoid" : "<reponame or repo_id>",
                "raw_id" : "<raw_id>",
                "with_reviews" : "<bool> = Optional(False)"
              }

OUTPUT::

    id : <id_given_in_input>
    result : {
              "author" :  "<full_author>",
              "date" :    "<date_time_of_commit>",
              "message" : "<commit_message>",
              "raw_id" :  "<raw_id>",
              "revision": "<numeric_revision>",
              "short_id": "<short_id>",
              "reviews" : [{
                    "reviewer" :  "<username>",
                    "modified_at" : "<date_time_of_review>",  # iso 8601 date, server's timezone
                    "status" :  "<status_of_review>",        # "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 : <id_for_response>
    api_key : "<api_key>"
    method :  "get_pullrequest"
    args :    {
                "pullrequest_id" : "<pullrequest_id>"
              }

OUTPUT::

    id : <id_given_in_input>
    result : {
        "status" : "<pull_request_status>",
        "pull_request_id" : <pull_request_id>,
        "description" : "<pull_request_description>",
        "title" : "<pull_request_title>",
        "url" : "<pull_request_url>",
        "reviewers" : [
          {
            "username" : "<user_name>"
          },
          ...
        ],
        "org_repo_url" : "<repo_url>",
        "org_ref_parts" : [
          "<ref_type>",
          "<ref_name>",
          "<raw_id>"
        ],
        "other_ref_parts" : [
          "<ref_type>",
          "<ref_name>",
          "<raw_id>"
        ],
        "comments" : [
          {
            "username" : "<user_name>",
            "text" : "<comment text>",
            "comment_id" : "<comment_id>"
          },
          ...
        ],
        "owner" : "<username>",
        "statuses" : [
          {
            "status" : "<status_of_review>",        # "under_review", "approved" or "rejected"
            "reviewer" : "<user_name>",
            "modified_at" : "<date_time_of_review>" # iso 8601 date, server's timezone
          },
          ...
        ],
        "revisions" : [
          "<raw_id>",
          ...
        ]
    },
    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 : <id_for_response>
    api_key : "<api_key>"
    method :  "comment_pullrequest"
    args :    {
                "pull_request_id" : "<pull_request_id>",
                "comment_msg" :     Optional(''),
                "status" :          Optional(None),     # "under_review", "approved" or "rejected"
                "close_pr" :        Optional(False)"
              }

OUTPUT::

    id : <id_given_in_input>
    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 <api_key>

Alternatively, the API key can be passed in the URL query string using
``?api_key=<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.