Skip to content

confluence

Confluence

Bases: AtlassianRestAPI

Source code in server/vendor/atlassian/confluence.py
  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
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
class Confluence(AtlassianRestAPI):
    content_types = {
        ".gif": "image/gif",
        ".png": "image/png",
        ".jpg": "image/jpeg",
        ".jpeg": "image/jpeg",
        ".pdf": "application/pdf",
        ".doc": "application/msword",
        ".xls": "application/vnd.ms-excel",
        ".svg": "image/svg+xml",
    }

    def __init__(self, url, *args, **kwargs):
        if ("atlassian.net" in url or "jira.com" in url) and ("/wiki" not in url):
            url = AtlassianRestAPI.url_joiner(url, "/wiki")
            if "cloud" not in kwargs:
                kwargs["cloud"] = True
        super(Confluence, self).__init__(url, *args, **kwargs)

    @staticmethod
    def _create_body(body, representation):
        if representation not in [
            "editor",
            "export_view",
            "view",
            "storage",
            "wiki",
        ]:
            raise ValueError("Wrong value for representation, it should be either wiki or storage")

        return {representation: {"value": body, "representation": representation}}

    def _get_paged(
        self,
        url,
        params=None,
        data=None,
        flags=None,
        trailing=None,
        absolute=False,
    ):
        """
        Used to get the paged data

        :param url: string:                        The url to retrieve
        :param params: dict (default is None):     The parameter's
        :param data: dict (default is None):       The data
        :param flags: string[] (default is None):  The flags
        :param trailing: bool (default is None):   If True, a trailing slash is added to the url
        :param absolute: bool (default is False):  If True, the url is used absolute and not relative to the root

        :return: A generator object for the data elements
        """

        if params is None:
            params = {}

        while True:
            response = self.get(
                url,
                trailing=trailing,
                params=params,
                data=data,
                flags=flags,
                absolute=absolute,
            )
            if "results" not in response:
                return

            for value in response.get("results", []):
                yield value

            # According to Cloud and Server documentation the links are returned the same way:
            # https://developer.atlassian.com/cloud/confluence/rest/api-group-content/#api-wiki-rest-api-content-get
            # https://developer.atlassian.com/server/confluence/pagination-in-the-rest-api/
            url = response.get("_links", {}).get("next")
            if url is None:
                break
            # From now on we have relative URLs with parameters
            absolute = False
            # Params are now provided by the url
            params = {}
            # Trailing should not be added as it is already part of the url
            trailing = False

        return

    def page_exists(self, space, title, type=None):
        """
        Check if title exists as page.
        :param space: Space key
        :param title: Title of the page
        :param type: type of the page, 'page' or 'blogpost'. Defaults to 'page'
        :return:
        """
        url = "rest/api/content"
        params = {}
        if space is not None:
            params["spaceKey"] = str(space)
        if title is not None:
            params["title"] = str(title)
        if type is not None:
            params["type"] = str(type)

        try:
            response = self.get(url, params=params)
        except HTTPError as e:
            if e.response.status_code == 404:
                raise ApiPermissionError(
                    "The calling user does not have permission to view the content",
                    reason=e,
                )

            raise

        if response.get("results"):
            return True
        else:
            return False

    def get_page_child_by_type(self, page_id, type="page", start=None, limit=None, expand=None):
        """
        Provide content by type (page, blog, comment)
        :param page_id: A string containing the id of the type content container.
        :param type:
        :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
        :param limit: OPTIONAL: how many items should be returned after the start index. Default: Site limit 200.
        :param expand: OPTIONAL: expand e.g. history
        :return:
        """
        params = {}
        if start is not None:
            params["start"] = int(start)
        if limit is not None:
            params["limit"] = int(limit)
        if expand is not None:
            params["expand"] = expand

        url = "rest/api/content/{page_id}/child/{type}".format(page_id=page_id, type=type)
        log.info(url)

        try:
            if not self.advanced_mode and start is None and limit is None:
                return self._get_paged(url, params=params)
            else:
                response = self.get(url, params=params)
                if self.advanced_mode:
                    return response
                return response.get("results")
        except HTTPError as e:
            if e.response.status_code == 404:
                # Raise ApiError as the documented reason is ambiguous
                raise ApiError(
                    "There is no content with the given id, "
                    "or the calling user does not have permission to view the content",
                    reason=e,
                )

            raise

    def get_child_title_list(self, page_id, type="page", start=None, limit=None):
        """
        Find a list of Child title
        :param page_id: A string containing the id of the type content container.
        :param type:
        :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
        :param limit: OPTIONAL: how many items should be returned after the start index. Default: Site limit 200.
        :return:
        """
        child_page = self.get_page_child_by_type(page_id, type, start, limit)
        child_title_list = [child["title"] for child in child_page]
        return child_title_list

    def get_child_id_list(self, page_id, type="page", start=None, limit=None):
        """
        Find a list of Child id
        :param page_id: A string containing the id of the type content container.
        :param type:
        :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
        :param limit: OPTIONAL: how many items should be returned after the start index. Default: Site limit 200.
        :return:
        """
        child_page = self.get_page_child_by_type(page_id, type, start, limit)
        child_id_list = [child["id"] for child in child_page]
        return child_id_list

    def get_child_pages(self, page_id):
        """
        Get child pages for the provided page_id
        :param page_id:
        :return:
        """
        return self.get_page_child_by_type(page_id=page_id, type="page")

    def get_page_id(self, space, title, type="page"):
        """
        Provide content id from search result by title and space.
        :param space: SPACE key
        :param title: title
        :param type: type of content: Page or Blogpost. Defaults to page
        :return:
        """
        return (self.get_page_by_title(space, title, type=type) or {}).get("id")

    def get_parent_content_id(self, page_id):
        """
        Provide parent content id from page id
        :type page_id: str
        :return:
        """
        parent_content_id = None
        try:
            parent_content_id = (self.get_page_by_id(page_id=page_id, expand="ancestors").get("ancestors") or {})[
                -1
            ].get("id") or None
        except Exception as e:
            log.error(e)
        return parent_content_id

    def get_parent_content_title(self, page_id):
        """
        Provide parent content title from page id
        :type page_id: str
        :return:
        """
        parent_content_title = None
        try:
            parent_content_title = (self.get_page_by_id(page_id=page_id, expand="ancestors").get("ancestors") or {})[
                -1
            ].get("title") or None
        except Exception as e:
            log.error(e)
        return parent_content_title

    def get_page_space(self, page_id):
        """
        Provide space key from content id.
        :param page_id: content ID
        :return:
        """
        return ((self.get_page_by_id(page_id, expand="space") or {}).get("space") or {}).get("key") or None

    def get_pages_by_title(self, space, title, start=0, limit=200, expand=None):
        """
        Provide pages by title search
        :param space: Space key
        :param title: Title of the page
        :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
        :param limit: OPTIONAL: The limit of the number of labels to return, this may be restricted by
                            fixed system limits. Default: 200.
        :param expand: OPTIONAL: expand e.g. history
        :return: The JSON data returned from searched results the content endpoint, or the results of the
                 callback. Will raise requests.HTTPError on bad input, potentially.
                 If it has IndexError then return the None.
        """
        return self.get_page_by_title(space, title, start, limit, expand)

    def get_page_by_title(self, space, title, start=0, limit=1, expand=None, type="page"):
        """
        Returns the first page  on a piece of Content.
        :param space: Space key
        :param title: Title of the page
        :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
        :param limit: OPTIONAL: The limit of the number of labels to return, this may be restricted by
                            fixed system limits. Default: 1.
        :param expand: OPTIONAL: expand e.g. history
        :param type: OPTIONAL: Type of content: Page or Blogpost. Defaults to page
        :return: The JSON data returned from searched results the content endpoint, or the results of the
                 callback. Will raise requests.HTTPError on bad input, potentially.
                 If it has IndexError then return the None.
        """
        url = "rest/api/content"
        params = {"type": type}
        if start is not None:
            params["start"] = int(start)
        if limit is not None:
            params["limit"] = int(limit)
        if expand is not None:
            params["expand"] = expand
        if space is not None:
            params["spaceKey"] = str(space)
        if title is not None:
            params["title"] = str(title)

        if self.advanced_mode:
            return self.get(url, params=params)
        try:
            response = self.get(url, params=params)
        except HTTPError as e:
            if e.response.status_code == 404:
                raise ApiPermissionError(
                    "The calling user does not have permission to view the content",
                    reason=e,
                )

            raise
        try:
            return response.get("results")[0]
        except (IndexError, TypeError) as e:
            log.error("Can't find '%s' page on the %s!", title, self.url)
            log.debug(e)
            return None

    def get_page_by_id(self, page_id, expand=None, status=None, version=None):
        """
        Returns a piece of Content.
        Example request URI(s):
        http://example.com/confluence/rest/api/content/1234?expand=space,body.view,version,container
        http://example.com/confluence/rest/api/content/1234?status=any
        :param page_id: Content ID
        :param status: (str) list of Content statuses to filter results on. Default value: [current]
        :param version: (int)
        :param expand: OPTIONAL: Default value: history,space,version
                       We can also specify some extensions such as extensions.inlineProperties
                       (for getting inline comment-specific properties) or extensions. Resolution
                       for the resolution status of each comment in the results
        :return:
        """
        params = {}
        if expand:
            params["expand"] = expand
        if status:
            params["status"] = status
        if version:
            params["version"] = version
        url = "rest/api/content/{page_id}".format(page_id=page_id)

        try:
            response = self.get(url, params=params)
        except HTTPError as e:
            if e.response.status_code == 404:
                # Raise ApiError as the documented reason is ambiguous
                raise ApiError(
                    "There is no content with the given id, "
                    "or the calling user does not have permission to view the content",
                    reason=e,
                )

            raise

        return response

    def get_tables_from_page(self, page_id):
        """
        Fetches html  tables added to  confluence page
        :param page_id: integer confluence page_id
        :return: json object with page_id, number_of_tables_in_page  and  list of list tables_content representing scrapepd tables
        """
        try:
            page_content = self.get_page_by_id(page_id, expand="body.storage")["body"]["storage"]["value"]

            if page_content:
                tables_raw = [
                    [[cell.text for cell in row("th") + row("td")] for row in table("tr")]
                    for table in BeautifulSoup(page_content, features="lxml")("table")
                ]
                if len(tables_raw) > 0:
                    return json.dumps(
                        {
                            "page_id": page_id,
                            "number_of_tables_in_page": len(tables_raw),
                            "tables_content": tables_raw,
                        }
                    )
                else:
                    return {
                        "No tables found for page: ": page_id,
                    }
            else:
                return {"Page content is empty"}
        except HTTPError as e:
            if e.response.status_code == 404:
                # Raise ApiError as the documented reason is ambiguous
                log.error("Couldn't retrieve tables  from page", page_id)
                raise ApiError(
                    "There is no content with the given pageid, pageid params is not an integer "
                    "or the calling user does not have permission to view the page",
                    reason=e,
                )
        except Exception as e:
            log.error("Error occured", e)

    def scrap_regex_from_page(self, page_id, regex):
        """
        Method scraps regex patterns from a Confluence page_id.

        :param page_id: The ID of the Confluence page.
        :param regex: The regex pattern to scrape.
        :return: A list of regex matches.
        """
        regex_output = []
        page_output = self.get_page_by_id(page_id, expand="body.storage")["body"]["storage"]["value"]
        try:
            if page_output is not None:
                description_matches = [x.group(0) for x in re.finditer(regex, page_output)]
                if description_matches:
                    regex_output.extend(description_matches)
            return regex_output
        except HTTPError as e:
            if e.response.status_code == 404:
                # Raise ApiError as the documented reason is ambiguous
                log.error("couldn't find page_id : ", page_id)
                raise ApiNotFoundError(
                    "There is no content with the given page id,"
                    "or the calling user does not have permission to view the page",
                    reason=e,
                )

    def get_page_labels(self, page_id, prefix=None, start=None, limit=None):
        """
        Returns the list of labels on a piece of Content.
        :param page_id: A string containing the id of the labels content container.
        :param prefix: OPTIONAL: The prefixes to filter the labels with {@see Label.Prefix}.
                                Default: None.
        :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
        :param limit: OPTIONAL: The limit of the number of labels to return, this may be restricted by
                            fixed system limits. Default: 200.
        :return: The JSON data returned from the content/{id}/label endpoint, or the results of the
                 callback. Will raise requests.HTTPError on bad input, potentially.
        """
        url = "rest/api/content/{id}/label".format(id=page_id)
        params = {}
        if prefix:
            params["prefix"] = prefix
        if start is not None:
            params["start"] = int(start)
        if limit is not None:
            params["limit"] = int(limit)

        try:
            response = self.get(url, params=params)
        except HTTPError as e:
            if e.response.status_code == 404:
                # Raise ApiError as the documented reason is ambiguous
                raise ApiError(
                    "There is no content with the given id, "
                    "or the calling user does not have permission to view the content",
                    reason=e,
                )

            raise

        return response

    def get_page_comments(
        self,
        content_id,
        expand=None,
        parent_version=None,
        start=0,
        limit=25,
        location=None,
        depth=None,
    ):
        """

        :param content_id:
        :param expand: extensions.inlineProperties,extensions.resolution
        :param parent_version:
        :param start:
        :param limit:
        :param location: inline or not
        :param depth:
        :return:
        """
        params = {"id": content_id, "start": start, "limit": limit}
        if expand:
            params["expand"] = expand
        if parent_version:
            params["parentVersion"] = parent_version
        if location:
            params["location"] = location
        if depth:
            params["depth"] = depth
        url = "rest/api/content/{id}/child/comment".format(id=content_id)

        try:
            response = self.get(url, params=params)
        except HTTPError as e:
            if e.response.status_code == 404:
                # Raise ApiError as the documented reason is ambiguous
                raise ApiError(
                    "There is no content with the given id, "
                    "or the calling user does not have permission to view the content",
                    reason=e,
                )

            raise

        return response

    def get_draft_page_by_id(self, page_id, status="draft", expand=None):
        """
        Gets content by id with status = draft
        :param page_id: Content ID
        :param status: (str) list of content statuses to filter results on. Default value: [draft]
        :param expand: OPTIONAL: Default value: history,space,version
                       We can also specify some extensions such as extensions.inlineProperties
                       (for getting inline comment-specific properties) or extensions. Resolution
                       for the resolution status of each comment in the results
        :return:
        """
        # Version not passed since draft versions don't match the page and
        # operate differently between different collaborative modes
        return self.get_page_by_id(page_id=page_id, expand=expand, status=status)

    def get_all_pages_by_label(self, label, start=0, limit=50):
        """
        Get all page by label
        :param label:
        :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
        :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
                      fixed system limits. Default: 50
        :return:
        """
        url = "rest/api/content/search"
        params = {}
        if label:
            params["cql"] = 'type={type} AND label="{label}"'.format(type="page", label=label)
        if start:
            params["start"] = start
        if limit:
            params["limit"] = limit

        try:
            response = self.get(url, params=params)
        except HTTPError as e:
            if e.response.status_code == 400:
                raise ApiValueError("The CQL is invalid or missing", reason=e)

            raise

        return response.get("results")

    def get_all_pages_from_space_raw(
        self,
        space,
        start=0,
        limit=50,
        status=None,
        expand=None,
        content_type="page",
    ):
        """
        Get all pages from space

        :param space:
        :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
        :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
                            fixed system limits. Default: 50
        :param status: OPTIONAL: list of statuses the content to be found is in.
                                 Defaults to current is not specified.
                                 If set to 'any', content in 'current' and 'trashed' status will be fetched.
                                 Does not support 'historical' status for now.
        :param expand: OPTIONAL: a comma separated list of properties to expand on the content.
                                 Default value: history,space,version.
        :param content_type: the content type to return. Default value: page. Valid values: page, blogpost.
        :return:
        """
        url = "rest/api/content"
        params = {}
        if space:
            params["spaceKey"] = space
        if start:
            params["start"] = start
        if limit:
            params["limit"] = limit
        if status:
            params["status"] = status
        if expand:
            params["expand"] = expand
        if content_type:
            params["type"] = content_type

        try:
            response = self.get(url, params=params)
        except HTTPError as e:
            if e.response.status_code == 404:
                raise ApiPermissionError(
                    "The calling user does not have permission to view the content",
                    reason=e,
                )

            raise

        return response

    def get_all_pages_from_space(
        self,
        space,
        start=0,
        limit=50,
        status=None,
        expand=None,
        content_type="page",
    ):
        """
        Get all pages from space

        :param space:
        :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
        :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
                            fixed system limits. Default: 50
        :param status: OPTIONAL: list of statuses the content to be found is in.
                                 Defaults to current is not specified.
                                 If set to 'any', content in 'current' and 'trashed' status will be fetched.
                                 Does not support 'historical' status for now.
        :param expand: OPTIONAL: a comma separated list of properties to expand on the content.
                                 Default value: history,space,version.
        :param content_type: the content type to return. Default value: page. Valid values: page, blogpost.
        :return:
        """
        return self.get_all_pages_from_space_raw(
            space=space, start=start, limit=limit, status=status, expand=expand, content_type=content_type
        ).get("results")

    def get_all_pages_from_space_trash(self, space, start=0, limit=500, status="trashed", content_type="page"):
        """
        Get list of pages from trash
        :param space:
        :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
        :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
                            fixed system limits. Default: 500
        :param status:
        :param content_type: the content type to return. Default value: page. Valid values: page, blogpost.
        :return:
        """
        return self.get_all_pages_from_space(space, start, limit, status, content_type=content_type)

    def get_all_draft_pages_from_space(self, space, start=0, limit=500, status="draft"):
        """
        Get list of draft pages from space
        Use case is cleanup old drafts from Confluence
        :param space:
        :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
        :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
                            fixed system limits. Default: 500
        :param status:
        :return:
        """
        return self.get_all_pages_from_space(space, start, limit, status)

    def get_all_draft_pages_from_space_through_cql(self, space, start=0, limit=500, status="draft"):
        """
        Search list of draft pages by space key
        Use case is cleanup old drafts from Confluence
        :param space: Space Key
        :param status: Can be changed
        :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
        :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
                            fixed system limits. Default: 500
        :return:
        """
        url = "rest/api/content?cql=space=spaceKey={space} and status={status}".format(space=space, status=status)
        params = {}
        if limit:
            params["limit"] = limit
        if start:
            params["start"] = start

        try:
            response = self.get(url, params=params)
        except HTTPError as e:
            if e.response.status_code == 404:
                raise ApiPermissionError(
                    "The calling user does not have permission to view the content",
                    reason=e,
                )

            raise

        return response.get("results")

    @deprecated(version="2.4.2", reason="Use get_all_restrictions_for_content()")
    def get_all_restictions_for_content(self, content_id):
        """Let's use the get_all_restrictions_for_content()"""
        log.warning("Please, be informed that is deprecated as typo naming")
        return self.get_all_restrictions_for_content(content_id=content_id)

    def get_all_restrictions_for_content(self, content_id):
        """
        Returns info about all restrictions by operation.
        :param content_id:
        :return: Return the raw json response
        """
        url = "rest/api/content/{}/restriction/byOperation".format(content_id)
        return self.get(url)

    def remove_page_from_trash(self, page_id):
        """
        This method removes a page from trash
        :param page_id:
        :return:
        """
        return self.remove_page(page_id=page_id, status="trashed")

    def remove_page_as_draft(self, page_id):
        """
        This method removes a page from trash if it is a draft
        :param page_id:
        :return:
        """
        return self.remove_page(page_id=page_id, status="draft")

    def remove_content(self, content_id):
        """
        Remove any content
        :param content_id:
        :return:
        """
        try:
            response = self.delete("rest/api/content/{}".format(content_id))
        except HTTPError as e:
            if e.response.status_code == 404:
                # Raise ApiError as the documented reason is ambiguous
                raise ApiError(
                    "There is no content with the given id, or the calling "
                    "user does not have permission to trash or purge the content",
                    reason=e,
                )
            if e.response.status_code == 409:
                raise ApiConflictError(
                    "There is a stale data object conflict when trying to delete a draft",
                    reason=e,
                )

            raise

        return response

    def remove_page(self, page_id, status=None, recursive=False):
        """
        This method removes a page, if it has recursive flag, method removes including child pages
        :param page_id:
        :param status: OPTIONAL: type of page
        :param recursive: OPTIONAL: if True - will recursively delete all children pages too
        :return:
        """
        url = "rest/api/content/{page_id}".format(page_id=page_id)
        if recursive:
            children_pages = self.get_page_child_by_type(page_id)
            for children_page in children_pages:
                self.remove_page(children_page.get("id"), status, recursive)
        params = {}
        if status:
            params["status"] = status

        try:
            response = self.delete(url, params=params)
        except HTTPError as e:
            if e.response.status_code == 404:
                # Raise ApiError as the documented reason is ambiguous
                raise ApiError(
                    "There is no content with the given id, or the calling "
                    "user does not have permission to trash or purge the content",
                    reason=e,
                )
            if e.response.status_code == 409:
                raise ApiConflictError(
                    "There is a stale data object conflict when trying to delete a draft",
                    reason=e,
                )

            raise

        return response

    def create_page(
        self,
        space,
        title,
        body,
        parent_id=None,
        type="page",
        representation="storage",
        editor=None,
        full_width=False,
    ):
        """
        Create page from scratch
        :param space:
        :param title:
        :param body:
        :param parent_id:
        :param type:
        :param representation: OPTIONAL: either Confluence 'storage' or 'wiki' markup format
        :param editor: OPTIONAL: v2 to be created in the new editor
        :param full_width: DEFAULT: False
        :return:
        """
        log.info('Creating %s "%s" -> "%s"', type, space, title)
        url = "rest/api/content/"
        data = {
            "type": type,
            "title": title,
            "space": {"key": space},
            "body": self._create_body(body, representation),
            "metadata": {"properties": {}},
        }
        if parent_id:
            data["ancestors"] = [{"type": type, "id": parent_id}]
        if editor is not None and editor in ["v1", "v2"]:
            data["metadata"]["properties"]["editor"] = {"value": editor}
        if full_width is True:
            data["metadata"]["properties"]["content-appearance-draft"] = {"value": "full-width"}
            data["metadata"]["properties"]["content-appearance-published"] = {"value": "full-width"}
        else:
            data["metadata"]["properties"]["content-appearance-draft"] = {"value": "fixed-width"}
            data["metadata"]["properties"]["content-appearance-published"] = {"value": "fixed-width"}

        try:
            response = self.post(url, data=data)
        except HTTPError as e:
            if e.response.status_code == 404:
                raise ApiPermissionError(
                    "The calling user does not have permission to view the content",
                    reason=e,
                )

            raise

        return response

    def move_page(
        self,
        space_key,
        page_id,
        target_id=None,
        target_title=None,
        position="append",
    ):
        """
        Move page method
        :param space_key:
        :param page_id:
        :param target_title:
        :param target_id:
        :param position: topLevel or append , above, below
        :return:
        """
        url = "/pages/movepage.action"
        params = {"spaceKey": space_key, "pageId": page_id}
        if target_title:
            params["targetTitle"] = target_title
        if target_id:
            params["targetId"] = target_id
        if position:
            params["position"] = position
        return self.post(url, params=params, headers=self.no_check_headers)

    def create_or_update_template(
        self,
        name,
        body,
        template_type="page",
        template_id=None,
        description=None,
        labels=None,
        space=None,
    ):
        """
        Creates a new or updates an existing content template.

        Note, blueprint templates cannot be created or updated via the REST API.

        If you provide a ``template_id`` then this method will update the template with the provided settings.
        If no ``template_id`` is provided, then this method assumes you are creating a new template.

        :param str name: If creating, the name of the new template. If updating, the name to change
            the template name to. Set to the current name if this field is not being updated.
        :param dict body: This object is used when creating or updating content.
            {
                "storage": {
                    "value": "<string>",
                    "representation": "view"
                }
            }
        :param str template_type: OPTIONAL: The type of the new template. Default: "page".
        :param str template_id: OPTIONAL: The ID of the template being updated. REQUIRED if updating a template.
        :param str description: OPTIONAL: A description of the new template. Max length 255.
        :param list labels: OPTIONAL: Labels for the new template. An array like:
            [
                {
                    "prefix": "<string>",
                    "name": "<string>",
                    "id": "<string>",
                    "label": "<string>",
                }
            ]
        :param dict space: OPTIONAL: The key for the space of the new template. Only applies to space templates.
            If not specified, the template will be created as a global template.
        :return:
        """
        data = {"name": name, "templateType": template_type, "body": body}

        if description:
            data["description"] = description

        if labels:
            data["labels"] = labels

        if space:
            data["space"] = {"key": space}

        if template_id:
            data["templateId"] = template_id
            return self.put("rest/api/template", data=json.dumps(data))

        return self.post("rest/api/template", json=data)

    @deprecated(version="3.7.0", reason="Use get_content_template()")
    def get_template_by_id(self, template_id):
        """
        Get user template by id. Experimental API
        Use case is get template body and create page from that
        """
        url = "rest/experimental/template/{template_id}".format(template_id=template_id)

        try:
            response = self.get(url)
        except HTTPError as e:
            if e.response.status_code == 403:
                # Raise ApiError as the documented reason is ambiguous
                raise ApiError(
                    "There is no content with the given id, "
                    "or the calling user does not have permission to view the content",
                    reason=e,
                )

            raise
        return response

    def get_content_template(self, template_id):
        """
        Get a content template.

        This includes information about the template, like the name, the space or blueprint
            that the template is in, the body of the template, and more.
        :param str template_id: The ID of the content template to be returned
        :return:
        """
        url = "rest/api/template/{template_id}".format(template_id=template_id)

        try:
            response = self.get(url)
        except HTTPError as e:
            if e.response.status_code == 403:
                # Raise ApiError as the documented reason is ambiguous
                raise ApiError(
                    "There is no content with the given id, "
                    "or the calling user does not have permission to view the content",
                    reason=e,
                )

            raise

        return response

    @deprecated(version="3.7.0", reason="Use get_blueprint_templates()")
    def get_all_blueprints_from_space(self, space, start=0, limit=None, expand=None):
        """
        Get all users blueprints from space. Experimental API
        :param space: Space Key
        :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
        :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
                            fixed system limits. Default: 20
        :param expand: OPTIONAL: expand e.g. body
        """
        url = "rest/experimental/template/blueprint"
        params = {}
        if space:
            params["spaceKey"] = space
        if start:
            params["start"] = start
        if limit:
            params["limit"] = limit
        if expand:
            params["expand"] = expand

        try:
            response = self.get(url, params=params)
        except HTTPError as e:
            if e.response.status_code == 403:
                raise ApiPermissionError(
                    "The calling user does not have permission to view the content",
                    reason=e,
                )

            raise

        return response.get("results") or []

    def get_blueprint_templates(self, space=None, start=0, limit=None, expand=None):
        """
        Gets all templates provided by blueprints.

        Use this method to retrieve all global blueprint templates or all blueprint templates in a space.
        :param space: OPTIONAL: The key of the space to be queried for templates. If ``space`` is not
            specified, global blueprint templates will be returned.
        :param start: OPTIONAL: The starting index of the returned templates. Default: None (0).
        :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
                            fixed system limits. Default: 25
        :param expand: OPTIONAL: A multi-value parameter indicating which properties of the template to expand.
        """
        url = "rest/api/template/blueprint"
        params = {}
        if space:
            params["spaceKey"] = space
        if start:
            params["start"] = start
        if limit:
            params["limit"] = limit
        if expand:
            params["expand"] = expand

        try:
            response = self.get(url, params=params)
        except HTTPError as e:
            if e.response.status_code == 403:
                raise ApiPermissionError(
                    "The calling user does not have permission to view the content",
                    reason=e,
                )

            raise

        return response.get("results") or []

    @deprecated(version="3.7.0", reason="Use get_content_templates()")
    def get_all_templates_from_space(self, space, start=0, limit=None, expand=None):
        """
        Get all users templates from space. Experimental API
        ref: https://docs.atlassian.com/atlassian-confluence/1000.73.0/com/atlassian/confluence/plugins/restapi\
    /resources/TemplateResource.html
        :param space: Space Key
        :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
        :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
                                fixed system limits. Default: 20
        :param expand: OPTIONAL: expand e.g. body
        """
        url = "rest/experimental/template/page"
        params = {}
        if space:
            params["spaceKey"] = space
        if start:
            params["start"] = start
        if limit:
            params["limit"] = limit
        if expand:
            params["expand"] = expand

        try:
            response = self.get(url, params=params)
        except HTTPError as e:
            if e.response.status_code == 403:
                raise ApiPermissionError(
                    "The calling user does not have permission to view the content",
                    reason=e,
                )
            raise

        return response.get("results") or []

    def get_content_templates(self, space=None, start=0, limit=None, expand=None):
        """
        Get all content templates.
        Use this method to retrieve all global content templates or all content templates in a space.
        :param space: OPTIONAL: The key of the space to be queried for templates. If ``space`` is not
            specified, global templates will be returned.
        :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
        :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
                            fixed system limits. Default: 25
        :param expand: OPTIONAL: A multi-value parameter indicating which properties of the template to expand.
            e.g. ``body``
        """
        url = "rest/api/template/page"
        params = {}
        if space:
            params["spaceKey"] = space
        if start:
            params["start"] = start
        if limit:
            params["limit"] = limit
        if expand:
            params["expand"] = expand

        try:
            response = self.get(url, params=params)
        except HTTPError as e:
            if e.response.status_code == 403:
                raise ApiPermissionError(
                    "The calling user does not have permission to view the content",
                    reason=e,
                )

            raise

        return response.get("results") or []

    def remove_template(self, template_id):
        """
        Deletes a template.

        This results in different actions depending on the type of template:
            * If the template is a content template, it is deleted.
            * If the template is a modified space-level blueprint template, it reverts to the template
                inherited from the global-level blueprint template.
            * If the template is a modified global-level blueprint template, it reverts to the default
                global-level blueprint template.
        Note: Unmodified blueprint templates cannot be deleted.

        :param str template_id: The ID of the template to be deleted.
        :return:
        """
        return self.delete("rest/api/template/{}".format(template_id))

    def get_all_spaces(
        self,
        start=0,
        limit=500,
        expand=None,
        space_type=None,
        space_status=None,
    ):
        """
        Get all spaces with provided limit
        :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
        :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
                            fixed system limits. Default: 500
        :param space_type: OPTIONAL: Filter the list of spaces returned by type (global, personal)
        :param space_status: OPTIONAL: Filter the list of spaces returned by status (current, archived)
        :param expand: OPTIONAL: additional info, e.g. metadata, icon, description, homepage
        """
        url = "rest/api/space"
        params = {}
        if start:
            params["start"] = start
        if limit:
            params["limit"] = limit
        if expand:
            params["expand"] = expand
        if space_type:
            params["type"] = space_type
        if space_status:
            params["status"] = space_status
        return self.get(url, params=params)

    def add_comment(self, page_id, text):
        """
        Add comment into page
        :param page_id
        :param text
        """
        data = {
            "type": "comment",
            "container": {"id": page_id, "type": "page", "status": "current"},
            "body": self._create_body(text, "storage"),
        }

        try:
            response = self.post("rest/api/content/", data=data)
        except HTTPError as e:
            if e.response.status_code == 404:
                raise ApiPermissionError(
                    "The calling user does not have permission to view the content",
                    reason=e,
                )

            raise

        return response

    def attach_content(
        self,
        content,
        name,
        content_type="application/binary",
        page_id=None,
        title=None,
        space=None,
        comment=None,
    ):
        """
        Attach (upload) a file to a page, if it exists it will update automatically the
        version the new file and keep the old one.
        :param title: The page name
        :type  title: ``str``
        :param space: The space name
        :type  space: ``str``
        :param page_id: The page id to which we would like to upload the file
        :type  page_id: ``str``
        :param name: The name of the attachment
        :type  name: ``str``
        :param content: Contains the content which should be uploaded
        :type  content: ``binary``
        :param content_type: Specify the HTTP content type. The default is
        :type  content_type: ``str``
        :param comment: A comment describing this upload/file
        :type  comment: ``str``
        """
        page_id = self.get_page_id(space=space, title=title) if page_id is None else page_id
        type = "attachment"
        if page_id is not None:
            comment = comment if comment else "Uploaded {filename}.".format(filename=name)
            data = {
                "type": type,
                "fileName": name,
                "contentType": content_type,
                "comment": comment,
                "minorEdit": "true",
            }
            headers = {
                "X-Atlassian-Token": "no-check",
                "Accept": "application/json",
            }
            path = "rest/api/content/{page_id}/child/attachment".format(page_id=page_id)
            # Check if there is already a file with the same name
            attachments = self.get(path=path, headers=headers, params={"filename": name})
            if attachments.get("size"):
                path = path + "/" + attachments["results"][0]["id"] + "/data"

            try:
                response = self.post(
                    path=path,
                    data=data,
                    headers=headers,
                    files={"file": (name, content, content_type)},
                )
            except HTTPError as e:
                if e.response.status_code == 403:
                    # Raise ApiError as the documented reason is ambiguous
                    raise ApiError(
                        "Attachments are disabled or the calling user does "
                        "not have permission to add attachments to this content",
                        reason=e,
                    )
                if e.response.status_code == 404:
                    # Raise ApiError as the documented reason is ambiguous
                    raise ApiError(
                        "The requested content is not found, the user does not have "
                        "permission to view it, or the attachments exceeds the maximum "
                        "configured attachment size",
                        reason=e,
                    )

                raise

            return response
        else:
            log.warning("No 'page_id' found, not uploading attachments")
            return None

    def attach_file(
        self,
        filename,
        name=None,
        content_type=None,
        page_id=None,
        title=None,
        space=None,
        comment=None,
    ):
        """
        Attach (upload) a file to a page, if it exists it will update automatically the
        version the new file and keep the old one.
        :param title: The page name
        :type  title: ``str``
        :param space: The space name
        :type  space: ``str``
        :param page_id: The page id to which we would like to upload the file
        :type  page_id: ``str``
        :param filename: The file to upload (Specifies the content)
        :type  filename: ``str``
        :param name: Specifies name of the attachment. This parameter is optional.
                     Is no name give the file name is used as name
        :type  name: ``str``
        :param content_type: Specify the HTTP content type. The default is
        :type  content_type: ``str``
        :param comment: A comment describing this upload/file
        :type  comment: ``str``
        """
        # get base name of the file to get the attachment from confluence.
        if name is None:
            name = os.path.basename(filename)
        if content_type is None:
            extension = os.path.splitext(filename)[-1]
            content_type = self.content_types.get(extension, "application/binary")

        with open(filename, "rb") as infile:
            content = infile.read()
        return self.attach_content(
            content,
            name,
            content_type,
            page_id=page_id,
            title=title,
            space=space,
            comment=comment,
        )

    def download_attachments_from_page(self, page_id, path=None, start=0, limit=50):
        """
        Downloads all attachments from a page
        :param page_id:
        :param path: OPTIONAL: path to directory where attachments will be saved. If None, current working directory will be used.
        :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
        :param limit: OPTIONAL: The limit of the number of attachments to return, this may be restricted by
                                fixed system limits. Default: 50
        :return info message: number of saved attachments + path to directory where attachments were saved:
        """
        if path is None:
            path = os.getcwd()
        try:
            attachments = self.get_attachments_from_content(page_id=page_id, start=start, limit=limit)["results"]
            if not attachments:
                return "No attachments found"
            for attachment in attachments:
                file_name = attachment["title"]
                if not file_name:
                    file_name = attachment["id"]  # if the attachment has no title, use attachment_id as a filename
                download_link = self.url + attachment["_links"]["download"]
                r = self._session.get(f"{download_link}")
                file_path = os.path.join(path, file_name)
                with open(file_path, "wb") as f:
                    f.write(r.content)
        except NotADirectoryError:
            raise NotADirectoryError("Verify if directory path is correct and/or if directory exists")
        except PermissionError:
            raise PermissionError(
                "Directory found, but there is a problem with saving file to this directory. Check directory permissions"
            )
        except Exception as e:
            raise e
        return {"attachments downloaded": len(attachments), " to path ": path}

    def delete_attachment(self, page_id, filename, version=None):
        """
        Remove completely a file if version is None or delete version
        :param version:
        :param page_id: file version
        :param filename:
        :return:
        """
        params = {"pageId": page_id, "fileName": filename}
        if version:
            params["version"] = version
        return self.post(
            "json/removeattachment.action",
            params=params,
            headers=self.form_token_headers,
        )

    def delete_attachment_by_id(self, attachment_id, version):
        """
        Remove completely a file if version is None or delete version
        :param attachment_id:
        :param version: file version
        :return:
        """
        return self.delete(
            "rest/experimental/content/{id}/version/{versionId}".format(id=attachment_id, versionId=version)
        )

    def remove_page_attachment_keep_version(self, page_id, filename, keep_last_versions):
        """
        Keep last versions
        :param filename:
        :param page_id:
        :param keep_last_versions:
        :return:
        """
        attachment = self.get_attachments_from_content(page_id=page_id, expand="version", filename=filename).get(
            "results"
        )[0]
        attachment_versions = self.get_attachment_history(attachment.get("id"))
        while len(attachment_versions) > keep_last_versions:
            remove_version_attachment_number = attachment_versions[keep_last_versions].get("number")
            self.delete_attachment_by_id(
                attachment_id=attachment.get("id"),
                version=remove_version_attachment_number,
            )
            log.info(
                "Removed oldest version for %s, now versions equal more than %s",
                attachment.get("title"),
                len(attachment_versions),
            )
            attachment_versions = self.get_attachment_history(attachment.get("id"))
        log.info("Kept versions %s for %s", keep_last_versions, attachment.get("title"))

    def get_attachment_history(self, attachment_id, limit=200, start=0):
        """
        Get attachment history
        :param attachment_id
        :param limit
        :param start
        :return
        """
        params = {"limit": limit, "start": start}
        url = "rest/experimental/content/{}/version".format(attachment_id)
        return (self.get(url, params=params) or {}).get("results")

    # @todo prepare more attachments info
    def get_attachments_from_content(
        self,
        page_id,
        start=0,
        limit=50,
        expand=None,
        filename=None,
        media_type=None,
    ):
        """
        Get attachments for page
        :param page_id:
        :param start:
        :param limit:
        :param expand:
        :param filename:
        :param media_type:
        :return:
        """
        params = {}
        if start:
            params["start"] = start
        if limit:
            params["limit"] = limit
        if expand:
            params["expand"] = expand
        if filename:
            params["filename"] = filename
        if media_type:
            params["mediaType"] = media_type
        url = "rest/api/content/{id}/child/attachment".format(id=page_id)

        try:
            response = self.get(url, params=params)
        except HTTPError as e:
            if e.response.status_code == 404:
                # Raise ApiError as the documented reason is ambiguous
                raise ApiError(
                    "There is no content with the given id, "
                    "or the calling user does not have permission to view the content",
                    reason=e,
                )

            raise

        return response

    def set_page_label(self, page_id, label):
        """
        Set a label on the page
        :param page_id: content_id format
        :param label: label to add
        :return:
        """
        url = "rest/api/content/{page_id}/label".format(page_id=page_id)
        data = {"prefix": "global", "name": label}

        try:
            response = self.post(path=url, data=data)
        except HTTPError as e:
            if e.response.status_code == 404:
                # Raise ApiError as the documented reason is ambiguous
                raise ApiError(
                    "There is no content with the given id, "
                    "or the calling user does not have permission to view the content",
                    reason=e,
                )

            raise

        return response

    def remove_page_label(self, page_id, label):
        """
        Delete Confluence page label
        :param page_id: content_id format
        :param label: label name
        :return:
        """
        url = "rest/api/content/{page_id}/label".format(page_id=page_id)
        params = {"id": page_id, "name": label}

        try:
            response = self.delete(path=url, params=params)
        except HTTPError as e:
            if e.response.status_code == 403:
                raise ApiPermissionError(
                    "The user has view permission, " "but no edit permission to the content",
                    reason=e,
                )
            if e.response.status_code == 404:
                # Raise ApiError as the documented reason is ambiguous
                raise ApiError(
                    "The content or label doesn't exist, "
                    "or the calling user doesn't have view permission to the content",
                    reason=e,
                )

            raise

        return response

    def history(self, page_id):
        url = "rest/api/content/{0}/history".format(page_id)
        try:
            response = self.get(url)
        except HTTPError as e:
            if e.response.status_code == 404:
                # Raise ApiError as the documented reason is ambiguous
                raise ApiError(
                    "There is no content with the given id, "
                    "or the calling user does not have permission to view the content",
                    reason=e,
                )

            raise

        return response

    def get_content_history(self, content_id):
        return self.history(content_id)

    def get_content_history_by_version_number(self, content_id, version_number):
        """
        Get content history by version number
        :param content_id:
        :param version_number:
        :return:
        """
        if self.cloud:
            url = "rest/api/content/{id}/version/{versionNumber}".format(id=content_id, versionNumber=version_number)
        else:
            url = "rest/experimental/content/{id}/version/{versionNumber}".format(
                id=content_id, versionNumber=version_number
            )
        return self.get(url)

    def remove_content_history(self, page_id, version_number):
        """
        Remove content history. It works as experimental method
        :param page_id:
        :param version_number: version number
        :return:
        """
        if self.cloud:
            url = "rest/api/content/{id}/version/{versionNumber}".format(id=page_id, versionNumber=version_number)
        else:
            url = "rest/experimental/content/{id}/version/{versionNumber}".format(
                id=page_id, versionNumber=version_number
            )
        self.delete(url)

    def remove_page_history(self, page_id, version_number):
        """
        Remove content history. It works as experimental method
        :param page_id:
        :param version_number: version number
        :return:
        """
        self.remove_content_history(page_id, version_number)

    def remove_content_history_in_cloud(self, page_id, version_id):
        """
        Remove content history. It works in CLOUD
        :param page_id:
        :param version_id:
        :return:
        """
        url = "rest/api/content/{id}/version/{versionId}".format(id=page_id, versionId=version_id)
        self.delete(url)

    def remove_page_history_keep_version(self, page_id, keep_last_versions):
        """
        Keep last versions
        :param page_id:
        :param keep_last_versions:
        :return:
        """
        page = self.get_page_by_id(page_id=page_id, expand="version")
        page_number = page.get("version").get("number")
        while page_number > keep_last_versions:
            self.remove_page_history(page_id=page_id, version_number=1)
            page = self.get_page_by_id(page_id=page_id, expand="version")
            page_number = page.get("version").get("number")
            log.info("Removed oldest version for %s, now it's %s", page.get("title"), page_number)
        log.info("Kept versions %s for %s", keep_last_versions, page.get("title"))

    def has_unknown_attachment_error(self, page_id):
        """
        Check has unknown attachment error on page
        :param page_id:
        :return:
        """
        unknown_attachment_identifier = "plugins/servlet/confluence/placeholder/unknown-attachment"
        result = self.get_page_by_id(page_id, expand="body.view")
        if len(result) == 0:
            return ""
        body = ((result.get("body") or {}).get("view") or {}).get("value") or {}
        if unknown_attachment_identifier in body:
            return result.get("_links").get("base") + result.get("_links").get("tinyui")
        return ""

    def is_page_content_is_already_updated(self, page_id, body, title=None):
        """
        Compare content and check is already updated or not
        :param page_id: Content ID for retrieve storage value
        :param body: Body for compare it
        :param title: Title to compare
        :return: True if the same
        """
        confluence_content = self.get_page_by_id(page_id)
        if title:
            current_title = confluence_content.get("title", None)
            if title != current_title:
                log.info("Title of %s is different", page_id)
                return False

        if self.advanced_mode:
            confluence_content = (
                (self.get_page_by_id(page_id, expand="body.storage").json() or {}).get("body") or {}
            ).get("storage") or {}
        else:
            confluence_content = ((self.get_page_by_id(page_id, expand="body.storage") or {}).get("body") or {}).get(
                "storage"
            ) or {}

        confluence_body_content = confluence_content.get("value")

        if confluence_body_content:
            # @todo move into utils
            confluence_body_content = utils.symbol_normalizer(confluence_body_content)

        log.debug('Old Content: """%s"""', confluence_body_content)
        log.debug('New Content: """%s"""', body)

        if confluence_body_content.strip() == body.strip():
            log.info("Content of %s is exactly the same", page_id)
            return True
        else:
            log.info("Content of %s differs", page_id)
            return False

    def update_existing_page(
        self,
        page_id,
        title,
        body,
        type="page",
        representation="storage",
        minor_edit=False,
        version_comment=None,
        full_width=False,
    ):
        """Duplicate update_page. Left for the people who used it before. Use update_page instead"""
        return self.update_page(
            page_id=page_id,
            title=title,
            body=body,
            type=type,
            representation=representation,
            minor_edit=minor_edit,
            version_comment=version_comment,
            full_width=full_width,
        )

    def update_page(
        self,
        page_id,
        title,
        body=None,
        parent_id=None,
        type="page",
        representation="storage",
        minor_edit=False,
        version_comment=None,
        always_update=False,
        full_width=False,
    ):
        """
        Update page if already exist
        :param page_id:
        :param title:
        :param body:
        :param parent_id:
        :param type:
        :param representation: OPTIONAL: either Confluence 'storage' or 'wiki' markup format
        :param minor_edit: Indicates whether to notify watchers about changes.
            If False then notifications will be sent.
        :param version_comment: Version comment
        :param always_update: Whether always to update (suppress content check)
        :param full_width: OPTIONAL: Default False
        :return:
        """
        # update current page
        params = {"status": "current"}
        log.info('Updating %s "%s" with %s', type, title, parent_id)

        if not always_update and body is not None and self.is_page_content_is_already_updated(page_id, body, title):
            return self.get_page_by_id(page_id)

        try:
            if self.advanced_mode:
                version = self.history(page_id).json()["lastUpdated"]["number"] + 1
            else:
                version = self.history(page_id)["lastUpdated"]["number"] + 1
        except (IndexError, TypeError) as e:
            log.error("Can't find '%s' %s!", title, type)
            log.debug(e)
            return None

        data = {
            "id": page_id,
            "type": type,
            "title": title,
            "version": {"number": version, "minorEdit": minor_edit},
            "metadata": {"properties": {}},
        }
        if body is not None:
            data["body"] = self._create_body(body, representation)

        if parent_id:
            data["ancestors"] = [{"type": "page", "id": parent_id}]
        if version_comment:
            data["version"]["message"] = version_comment

        if full_width is True:
            data["metadata"]["properties"]["content-appearance-draft"] = {"value": "full-width"}
            data["metadata"]["properties"]["content-appearance-published"] = {"value": "full-width"}
        else:
            data["metadata"]["properties"]["content-appearance-draft"] = {"value": "fixed-width"}
            data["metadata"]["properties"]["content-appearance-published"] = {"value": "fixed-width"}
        try:
            response = self.put(
                "rest/api/content/{0}".format(page_id),
                data=data,
                params=params,
            )
        except HTTPError as e:
            if e.response.status_code == 400:
                raise ApiValueError(
                    "No space or no content type, or setup a wrong version "
                    "type set to content, or status param is not draft and "
                    "status content is current",
                    reason=e,
                )
            if e.response.status_code == 404:
                raise ApiNotFoundError("Can not find draft with current content", reason=e)

            raise

        return response

    def _insert_to_existing_page(
        self,
        page_id,
        title,
        insert_body,
        parent_id=None,
        type="page",
        representation="storage",
        minor_edit=False,
        version_comment=None,
        top_of_page=False,
    ):
        """
        Insert body to a page if already exist
        :param parent_id:
        :param page_id:
        :param title:
        :param insert_body:
        :param type:
        :param representation: OPTIONAL: either Confluence 'storage' or 'wiki' markup format
        :param minor_edit: Indicates whether to notify watchers about changes.
            If False then notifications will be sent.
        :param top_of_page: Option to add the content to the end of page body
        :return:
        """
        log.info('Updating %s "%s"', type, title)
        # update current page
        params = {"status": "current"}

        if self.is_page_content_is_already_updated(page_id, insert_body, title):
            return self.get_page_by_id(page_id)
        else:
            version = self.history(page_id)["lastUpdated"]["number"] + 1
            previous_body = (
                (self.get_page_by_id(page_id, expand="body.storage").get("body") or {}).get("storage").get("value")
            )
            previous_body = previous_body.replace("&oacute;", "ó")
            body = insert_body + previous_body if top_of_page else previous_body + insert_body
            data = {
                "id": page_id,
                "type": type,
                "title": title,
                "body": self._create_body(body, representation),
                "version": {"number": version, "minorEdit": minor_edit},
            }

            if parent_id:
                data["ancestors"] = [{"type": "page", "id": parent_id}]
            if version_comment:
                data["version"]["message"] = version_comment

            try:
                response = self.put(
                    "rest/api/content/{0}".format(page_id),
                    data=data,
                    params=params,
                )
            except HTTPError as e:
                if e.response.status_code == 400:
                    raise ApiValueError(
                        "No space or no content type, or setup a wrong version "
                        "type set to content, or status param is not draft and "
                        "status content is current",
                        reason=e,
                    )
                if e.response.status_code == 404:
                    raise ApiNotFoundError("Can not find draft with current content", reason=e)

                raise

            return response

    def append_page(
        self,
        page_id,
        title,
        append_body,
        parent_id=None,
        type="page",
        representation="storage",
        minor_edit=False,
    ):
        """
        Append body to page if already exist
        :param parent_id:
        :param page_id:
        :param title:
        :param append_body:
        :param type:
        :param representation: OPTIONAL: either Confluence 'storage' or 'wiki' markup format
        :param minor_edit: Indicates whether to notify watchers about changes.
            If False then notifications will be sent.
        :return:
        """
        log.info('Updating %s "%s"', type, title)

        return self._insert_to_existing_page(
            page_id,
            title,
            append_body,
            parent_id=parent_id,
            type=type,
            representation=representation,
            minor_edit=minor_edit,
            top_of_page=False,
        )

    def prepend_page(
        self,
        page_id,
        title,
        prepend_body,
        parent_id=None,
        type="page",
        representation="storage",
        minor_edit=False,
    ):
        """
        Append body to page if already exist
        :param parent_id:
        :param page_id:
        :param title:
        :param prepend_body:
        :param type:
        :param representation: OPTIONAL: either Confluence 'storage' or 'wiki' markup format
        :param minor_edit: Indicates whether to notify watchers about changes.
            If False then notifications will be sent.
        :return:
        """
        log.info('Updating %s "%s"', type, title)

        return self._insert_to_existing_page(
            page_id,
            title,
            prepend_body,
            parent_id=parent_id,
            type=type,
            representation=representation,
            minor_edit=minor_edit,
            top_of_page=True,
        )

    def update_or_create(
        self,
        parent_id,
        title,
        body,
        representation="storage",
        minor_edit=False,
        version_comment=None,
        editor=None,
        full_width=False,
    ):
        """
        Update page or create a page if it is not exists
        :param parent_id:
        :param title:
        :param body:
        :param representation: OPTIONAL: either Confluence 'storage' or 'wiki' markup format
        :param minor_edit: Update page without notification
        :param version_comment: Version comment
        :param editor: OPTIONAL: v2 to be created in the new editor
        :param full_width: OPTIONAL: Default is False
        :return:
        """
        space = self.get_page_space(parent_id)

        if self.page_exists(space, title):
            page_id = self.get_page_id(space, title)
            parent_id = parent_id if parent_id is not None else self.get_parent_content_id(page_id)
            result = self.update_page(
                parent_id=parent_id,
                page_id=page_id,
                title=title,
                body=body,
                representation=representation,
                minor_edit=minor_edit,
                version_comment=version_comment,
                full_width=full_width,
            )
        else:
            result = self.create_page(
                space=space,
                parent_id=parent_id,
                title=title,
                body=body,
                representation=representation,
                editor=editor,
                full_width=full_width,
            )

        log.info(
            "You may access your page at: %s%s",
            self.url,
            ((result or {}).get("_links") or {}).get("tinyui"),
        )
        return result

    def convert_wiki_to_storage(self, wiki):
        """
        Convert to Confluence XHTML format from wiki style
        :param wiki:
        :return:
        """
        data = {"value": wiki, "representation": "wiki"}
        return self.post("rest/api/contentbody/convert/storage", data=data)

    def convert_storage_to_view(self, storage):
        """
        Convert from Confluence XHTML format to view format
        :param storage:
        :return:
        """
        data = {"value": storage, "representation": "storage"}
        return self.post("rest/api/contentbody/convert/view", data=data)

    def set_page_property(self, page_id, data):
        """
        Set the page (content) property e.g. add hash parameters
        :param page_id: content_id format
        :param data: data should be as json data
        :return:
        """
        url = "rest/api/content/{page_id}/property".format(page_id=page_id)
        json_data = data

        try:
            response = self.post(path=url, data=json_data)
        except HTTPError as e:
            if e.response.status_code == 400:
                raise ApiValueError(
                    "The given property has a different content id to the one in the "
                    "path, or the content already has a value with the given key, or "
                    "the value is missing, or the value is too long",
                    reason=e,
                )
            if e.response.status_code == 403:
                raise ApiPermissionError(
                    "The user does not have permission to " "edit the content with the given id",
                    reason=e,
                )
            if e.response.status_code == 413:
                raise ApiValueError("The value is too long", reason=e)

            raise

        return response

    def update_page_property(self, page_id, data):
        """
        Update the page (content) property.
        Use json data or independent keys
        :param data:
        :param page_id: content_id format
        :data: property data in json format
        :return:
        """
        url = "rest/api/content/{page_id}/property/{key}".format(page_id=page_id, key=data.get("key"))
        try:
            response = self.put(path=url, data=data)
        except HTTPError as e:
            if e.response.status_code == 400:
                raise ApiValueError(
                    "The given property has a different content id to the one in the "
                    "path, or the content already has a value with the given key, or "
                    "the value is missing, or the value is too long",
                    reason=e,
                )
            if e.response.status_code == 403:
                raise ApiPermissionError(
                    "The user does not have permission to " "edit the content with the given id",
                    reason=e,
                )
            if e.response.status_code == 404:
                raise ApiNotFoundError(
                    "There is no content with the given id, or no property with the given key, "
                    "or if the calling user does not have permission to view the content.",
                    reason=e,
                )
            if e.response.status_code == 409:
                raise ApiConflictError(
                    "The given version is does not match the expected " "target version of the updated property",
                    reason=e,
                )
            if e.response.status_code == 413:
                raise ApiValueError("The value is too long", reason=e)
            raise
        return response

    def delete_page_property(self, page_id, page_property):
        """
        Delete the page (content) property e.g. delete key of hash
        :param page_id: content_id format
        :param page_property: key of property
        :return:
        """
        url = "rest/api/content/{page_id}/property/{page_property}".format(
            page_id=page_id, page_property=str(page_property)
        )
        try:
            response = self.delete(path=url)
        except HTTPError as e:
            if e.response.status_code == 404:
                # Raise ApiError as the documented reason is ambiguous
                raise ApiError(
                    "There is no content with the given id, "
                    "or the calling user does not have permission to view the content",
                    reason=e,
                )

            raise

        return response

    def get_page_property(self, page_id, page_property_key):
        """
        Get the page (content) property e.g. get key of hash
        :param page_id: content_id format
        :param page_property_key: key of property
        :return:
        """
        url = "rest/api/content/{page_id}/property/{key}".format(page_id=page_id, key=str(page_property_key))
        try:
            response = self.get(path=url)
        except HTTPError as e:
            if e.response.status_code == 404:
                # Raise ApiError as the documented reason is ambiguous
                raise ApiError(
                    "There is no content with the given id, or no property with the "
                    "given key, or the calling user does not have permission to view "
                    "the content",
                    reason=e,
                )

            raise

        return response

    def get_page_properties(self, page_id):
        """
        Get the page (content) properties
        :param page_id: content_id format
        :return: get properties
        """
        url = "rest/api/content/{page_id}/property".format(page_id=page_id)

        try:
            response = self.get(path=url)
        except HTTPError as e:
            if e.response.status_code == 404:
                # Raise ApiError as the documented reason is ambiguous
                raise ApiError(
                    "There is no content with the given id, "
                    "or the calling user does not have permission to view the content",
                    reason=e,
                )

            raise

        return response

    def get_page_ancestors(self, page_id):
        """
        Provide the ancestors from the page (content) id
        :param page_id: content_id format
        :return: get properties
        """
        url = "rest/api/content/{page_id}?expand=ancestors".format(page_id=page_id)

        try:
            response = self.get(path=url)
        except HTTPError as e:
            if e.response.status_code == 404:
                raise ApiPermissionError(
                    "The calling user does not have permission to view the content",
                    reason=e,
                )

            raise

        return response.get("ancestors")

    def clean_all_caches(self):
        """Clean all caches from cache management"""
        headers = self.form_token_headers
        return self.delete("rest/cacheManagement/1.0/cacheEntries", headers=headers)

    def clean_package_cache(self, cache_name="com.gliffy.cache.gon"):
        """Clean caches from cache management
        e.g.
        com.gliffy.cache.gon
        org.hibernate.cache.internal.StandardQueryCache_v5
        """
        headers = self.form_token_headers
        data = {"cacheName": cache_name}
        return self.delete("rest/cacheManagement/1.0/cacheEntries", data=data, headers=headers)

    def get_all_groups(self, start=0, limit=1000):
        """
        Get all groups from Confluence User management
        :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
        :param limit: OPTIONAL: The limit of the number of groups to return, this may be restricted by
                                fixed system limits. Default: 1000
        :return:
        """
        url = "rest/api/group?limit={limit}&start={start}".format(limit=limit, start=start)

        try:
            response = self.get(url)
        except HTTPError as e:
            if e.response.status_code == 403:
                raise ApiPermissionError(
                    "The calling user does not have permission to view groups",
                    reason=e,
                )

            raise

        return response.get("results")

    def create_group(self, name):
        """
        Create a group by given group parameter

        :param name: str
        :return: New group params
        """
        url = "rest/api/admin/group"
        data = {"name": name, "type": "group"}
        return self.post(url, data=data)

    def remove_group(self, name):
        """
        Delete a group by given group parameter
        If you delete a group and content is restricted to that group, the content will be hidden from all users

        :param name: str
        :return:
        """
        log.warning("Removing group...")
        url = "rest/api/admin/group/{groupName}".format(groupName=name)

        try:
            response = self.delete(url)
        except HTTPError as e:
            if e.response.status_code == 404:
                # Raise ApiError as the documented reason is ambiguous
                raise ApiError(
                    "There is no group with the given name, "
                    "or the calling user does not have permission to delete it",
                    reason=e,
                )
            raise

        return response

    def get_group_members(self, group_name="confluence-users", start=0, limit=1000, expand=None):
        """
        Get a paginated collection of users in the given group
        :param group_name
        :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
        :param limit: OPTIONAL: The limit of the number of users to return, this may be restricted by
                            fixed system limits. Default: 1000
        :param expand: OPTIONAL: A comma separated list of properties to expand on the content. status
        :return:
        """
        url = "rest/api/group/{group_name}/member?limit={limit}&start={start}&expand={expand}".format(
            group_name=group_name, limit=limit, start=start, expand=expand
        )

        try:
            response = self.get(url)
        except HTTPError as e:
            if e.response.status_code == 403:
                raise ApiPermissionError(
                    "The calling user does not have permission to view users",
                    reason=e,
                )

            raise

        return response.get("results")

    def get_all_members(self, group_name="confluence-users", expand=None):
        """
        Get  collection of all users in the given group
        :param group_name
        :param expand: OPTIONAL: A comma separated list of properties to expand on the content. status
        :return:
        """
        limit = 50
        flag = True
        step = 0
        members = []
        while flag:
            values = self.get_group_members(
                group_name=group_name,
                start=len(members),
                limit=limit,
                expand=expand,
            )
            step += 1
            if len(values) == 0:
                flag = False
            else:
                members.extend(values)
        if not members:
            print("Did not get members from {} group, please check permissions or connectivity".format(group_name))
        return members

    def get_space(self, space_key, expand="description.plain,homepage", params=None):
        """
        Get information about a space through space key
        :param space_key: The unique space key name
        :param expand: OPTIONAL: additional info from description, homepage
        :param params: OPTIONAL: dictionary of additional URL parameters
        :return: Returns the space along with its ID
        """
        url = "rest/api/space/{space_key}".format(space_key=space_key)
        params = params or {}
        if expand:
            params["expand"] = expand
        try:
            response = self.get(url, params=params)
        except HTTPError as e:
            if e.response.status_code == 404:
                # Raise ApiError as the documented reason is ambiguous
                raise ApiError(
                    "There is no space with the given key, "
                    "or the calling user does not have permission to view the space",
                    reason=e,
                )
            raise
        return response

    def get_space_content(
        self,
        space_key,
        depth="all",
        start=0,
        limit=500,
        content_type=None,
        expand="body.storage",
    ):
        """
        Get space content.
        You can specify which type of content want to receive, or get all content types.
        Use expand to get specific content properties or page
        :param content_type:
        :param space_key: The unique space key name
        :param depth: OPTIONAL: all|root
                                Gets all space pages or only root pages
        :param start: OPTIONAL: The start point of the collection to return. Default: 0.
        :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
                                fixed system limits. Default: 500
        :param expand: OPTIONAL: by default expands page body in confluence storage format.
                                 See atlassian documentation for more information.
        :return: Returns the space along with its ID
        """

        content_type = "{}".format("/" + content_type if content_type else "")
        url = "rest/api/space/{space_key}/content{content_type}".format(space_key=space_key, content_type=content_type)
        params = {
            "depth": depth,
            "start": start,
            "limit": limit,
        }
        if expand:
            params["expand"] = expand
        try:
            response = self.get(url, params=params)
        except HTTPError as e:
            if e.response.status_code == 404:
                # Raise ApiError as the documented reason is ambiguous
                raise ApiError(
                    "There is no space with the given key, "
                    "or the calling user does not have permission to view the space",
                    reason=e,
                )
            raise
        return response

    def get_home_page_of_space(self, space_key):
        """
        Get information about a space through space key
        :param space_key: The unique space key name
        :return: Returns homepage
        """
        return self.get_space(space_key, expand="homepage").get("homepage")

    def create_space(self, space_key, space_name):
        """
        Create space
        :param space_key:
        :param space_name:
        :return:
        """
        data = {"key": space_key, "name": space_name}
        self.post("rest/api/space", data=data)

    def delete_space(self, space_key):
        """
        Delete space
        :param space_key:
        :return:
        """
        url = "rest/api/space/{}".format(space_key)

        try:
            response = self.delete(url)
        except HTTPError as e:
            if e.response.status_code == 404:
                # Raise ApiError as the documented reason is ambiguous
                raise ApiError(
                    "There is no space with the given key, "
                    "or the calling user does not have permission to delete it",
                    reason=e,
                )

            raise

        return response

    def get_space_property(self, space_key, expand=None):
        url = "rest/api/space/{space}/property".format(space=space_key)
        params = {}
        if expand:
            params["expand"] = expand

        try:
            response = self.get(url, params=params)
        except HTTPError as e:
            if e.response.status_code == 404:
                # Raise ApiError as the documented reason is ambiguous
                raise ApiError(
                    "There is no space with the given key, "
                    "or the calling user does not have permission to view the space",
                    reason=e,
                )

            raise

        return response

    def get_user_details_by_username(self, username, expand=None):
        """
        Get information about a user through username
        :param username: The username
        :param expand: OPTIONAL expand for get status of user.
                Possible param is "status". Results are "Active, Deactivated"
        :return: Returns the user details
        """
        url = "rest/api/user"
        params = {"username": username}
        if expand:
            params["expand"] = expand

        try:
            response = self.get(url, params=params)
        except HTTPError as e:
            if e.response.status_code == 403:
                raise ApiPermissionError(
                    "The calling user does not have permission to view users",
                    reason=e,
                )
            if e.response.status_code == 404:
                raise ApiNotFoundError(
                    "The user with the given username or userkey does not exist",
                    reason=e,
                )

            raise

        return response

    def get_user_details_by_accountid(self, accountid, expand=None):
        """
        Get information about a user through accountid
        :param accountid: The account id
        :param expand: OPTIONAL expand for get status of user.
                Possible param is "status". Results are "Active, Deactivated"
        :return: Returns the user details
        """
        url = "rest/api/user"
        params = {"accountId": accountid}
        if expand:
            params["expand"] = expand

        try:
            response = self.get(url, params=params)
        except HTTPError as e:
            if e.response.status_code == 403:
                raise ApiPermissionError(
                    "The calling user does not have permission to view users",
                    reason=e,
                )
            if e.response.status_code == 404:
                raise ApiNotFoundError(
                    "The user with the given account does not exist",
                    reason=e,
                )

            raise

        return response

    def get_user_details_by_userkey(self, userkey, expand=None):
        """
        Get information about a user through user key
        :param userkey: The user key
        :param expand: OPTIONAL expand for get status of user.
                Possible param is "status". Results are "Active, Deactivated"
        :return: Returns the user details
        """
        url = "rest/api/user"
        params = {"key": userkey}
        if expand:
            params["expand"] = expand

        try:
            response = self.get(url, params=params)
        except HTTPError as e:
            if e.response.status_code == 403:
                raise ApiPermissionError(
                    "The calling user does not have permission to view users",
                    reason=e,
                )
            if e.response.status_code == 404:
                raise ApiNotFoundError(
                    "The user with the given username or userkey does not exist",
                    reason=e,
                )

            raise

        return response

    def cql(
        self,
        cql,
        start=0,
        limit=None,
        expand=None,
        include_archived_spaces=None,
        excerpt=None,
    ):
        """
        Get results from cql search result with all related fields
        Search for entities in Confluence using the Confluence Query Language (CQL)
        :param cql:
        :param start: OPTIONAL: The start point of the collection to return. Default: 0.
        :param limit: OPTIONAL: The limit of the number of issues to return, this may be restricted by
                        fixed system limits. Default by built-in method: 25
        :param excerpt: the excerpt strategy to apply to the result, one of : indexed, highlight, none.
                        This defaults to highlight
        :param expand: OPTIONAL: the properties to expand on the search result,
                        this may cause database requests for some properties
        :param include_archived_spaces: OPTIONAL: whether to include content in archived spaces in the result,
                                    this defaults to false
        :return:
        """
        params = {}
        if start is not None:
            params["start"] = int(start)
        if limit is not None:
            params["limit"] = int(limit)
        if cql is not None:
            params["cql"] = cql
        if expand is not None:
            params["expand"] = expand
        if include_archived_spaces is not None:
            params["includeArchivedSpaces"] = include_archived_spaces
        if excerpt is not None:
            params["excerpt"] = excerpt

        try:
            response = self.get("rest/api/search", params=params)
        except HTTPError as e:
            if e.response.status_code == 400:
                raise ApiValueError("The query cannot be parsed", reason=e)

            raise

        return response

    def get_page_as_pdf(self, page_id):
        """
        Export page as standard pdf exporter
        :param page_id: Page ID
        :return: PDF File
        """
        headers = self.form_token_headers
        url = "spaces/flyingpdf/pdfpageexport.action?pageId={pageId}".format(pageId=page_id)
        if self.api_version == "cloud":
            url = self.get_pdf_download_url_for_confluence_cloud(url)
            if not url:
                log.error("Failed to get download PDF url.")
                raise ApiNotFoundError("Failed to export page as PDF", reason="Failed to get download PDF url.")
            # To download the PDF file, the request should be with no headers of authentications.
            return requests.get(url, timeout=75).content
        return self.get(url, headers=headers, not_json_response=True)

    def get_page_as_word(self, page_id):
        """
        Export page as standard word exporter.
        :param page_id: Page ID
        :return: Word File
        """
        headers = self.form_token_headers
        url = "exportword?pageId={pageId}".format(pageId=page_id)
        return self.get(url, headers=headers, not_json_response=True)

    def export_page(self, page_id):
        """
        Alias method for export page as pdf
        :param page_id: Page ID
        :return: PDF File
        """
        return self.get_page_as_pdf(page_id)

    def get_descendant_page_id(self, space, parent_id, title):
        """
        Provide  space, parent_id and title of the descendant page, it will return the descendant page_id
        :param space: str
        :param parent_id: int
        :param title: str
        :return: page_id of the page whose title is passed in argument
        """
        page_id = ""

        url = 'rest/api/content/search?cql=parent={}%20AND%20space="{}"'.format(parent_id, space)

        try:
            response = self.get(url, {})
        except HTTPError as e:
            if e.response.status_code == 400:
                raise ApiValueError("The CQL is invalid or missing", reason=e)

            raise

        for each_page in response.get("results", []):
            if each_page.get("title") == title:
                page_id = each_page.get("id")
                break
        return page_id

    def reindex(self):
        """
        It is not public method for reindex Confluence
        :return:
        """
        url = "rest/prototype/1/index/reindex"
        return self.post(url)

    def reindex_get_status(self):
        """
        Get reindex status of Confluence
        :return:
        """
        url = "rest/prototype/1/index/reindex"
        return self.get(url)

    def health_check(self):
        """
        Get health status
        https://confluence.atlassian.com/jirakb/how-to-retrieve-health-check-results-using-rest-api-867195158.html
        :return:
        """
        # check as Troubleshooting & Support Tools Plugin
        response = self.get("rest/troubleshooting/1.0/check/")
        if not response:
            # check as support tools
            response = self.get("rest/supportHealthCheck/1.0/check/")
        return response

    def synchrony_enable(self):
        """
        Enable Synchrony
        :return:
        """
        headers = {"X-Atlassian-Token": "no-check"}
        url = "rest/synchrony-interop/enable"
        return self.post(url, headers=headers)

    def synchrony_disable(self):
        """
        Disable Synchrony
        :return:
        """
        headers = {"X-Atlassian-Token": "no-check"}
        url = "rest/synchrony-interop/disable"
        return self.post(url, headers=headers)

    def check_access_mode(self):
        return self.get("rest/api/accessmode")

    def anonymous(self):
        """
        Get information about how anonymous is represented in confluence
        :return:
        """
        try:
            response = self.get("rest/api/user/anonymous")
        except HTTPError as e:
            if e.response.status_code == 403:
                raise ApiPermissionError(
                    "The calling user does not have permission to use Confluence",
                    reason=e,
                )

            raise

        return response

    def get_plugins_info(self):
        """
        Provide plugins info
        :return a json of installed plugins
        """
        url = "rest/plugins/1.0/"
        return self.get(url, headers=self.no_check_headers, trailing=True)

    def get_plugin_info(self, plugin_key):
        """
        Provide plugin info
        :return a json of installed plugins
        """
        url = "rest/plugins/1.0/{plugin_key}-key".format(plugin_key=plugin_key)
        return self.get(url, headers=self.no_check_headers, trailing=True)

    def get_plugin_license_info(self, plugin_key):
        """
        Provide plugin license info
        :return a json specific License query
        """
        url = "rest/plugins/1.0/{plugin_key}-key/license".format(plugin_key=plugin_key)
        return self.get(url, headers=self.no_check_headers, trailing=True)

    def upload_plugin(self, plugin_path):
        """
        Provide plugin path for upload into Jira e.g. useful for auto deploy
        :param plugin_path:
        :return:
        """
        files = {"plugin": open(plugin_path, "rb")}
        upm_token = self.request(
            method="GET",
            path="rest/plugins/1.0/",
            headers=self.no_check_headers,
            trailing=True,
        ).headers["upm-token"]
        url = "rest/plugins/1.0/?token={upm_token}".format(upm_token=upm_token)
        return self.post(url, files=files, headers=self.no_check_headers)

    def disable_plugin(self, plugin_key):
        """
        Disable a plugin
        :param plugin_key:
        :return:
        """
        app_headers = {
            "X-Atlassian-Token": "nocheck",
            "Content-Type": "application/vnd.atl.plugins+json",
        }
        url = "rest/plugins/1.0/{plugin_key}-key".format(plugin_key=plugin_key)
        data = {"status": "disabled"}
        return self.put(url, data=data, headers=app_headers)

    def enable_plugin(self, plugin_key):
        """
        Enable a plugin
        :param plugin_key:
        :return:
        """
        app_headers = {
            "X-Atlassian-Token": "nocheck",
            "Content-Type": "application/vnd.atl.plugins+json",
        }
        url = "rest/plugins/1.0/{plugin_key}-key".format(plugin_key=plugin_key)
        data = {"status": "enabled"}
        return self.put(url, data=data, headers=app_headers)

    def delete_plugin(self, plugin_key):
        """
        Delete plugin
        :param plugin_key:
        :return:
        """
        url = "rest/plugins/1.0/{}-key".format(plugin_key)
        return self.delete(url)

    def check_plugin_manager_status(self):
        url = "rest/plugins/latest/safe-mode"
        return self.request(method="GET", path=url, headers=self.safe_mode_headers)

    def update_plugin_license(self, plugin_key, raw_license):
        """
        Update license for plugin
        :param plugin_key:
        :param raw_license:
        :return:
        """
        app_headers = {
            "X-Atlassian-Token": "nocheck",
            "Content-Type": "application/vnd.atl.plugins+json",
        }
        url = "/plugins/1.0/{plugin_key}/license".format(plugin_key=plugin_key)
        data = {"rawLicense": raw_license}
        return self.put(url, data=data, headers=app_headers)

    def check_long_tasks_result(self, start=None, limit=None, expand=None):
        """
        Get result of long tasks
        :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
        :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
                            fixed system limits. Default: 50
        :param expand:
        :return:
        """
        params = {}
        if expand:
            params["expand"] = expand
        if start:
            params["start"] = start
        if limit:
            params["limit"] = limit
        return self.get("rest/api/longtask", params=params)

    def check_long_task_result(self, task_id, expand=None):
        """
        Get result of long tasks
        :param task_id: task id
        :param expand:
        :return:
        """
        params = None
        if expand:
            params = {"expand": expand}

        try:
            response = self.get("rest/api/longtask/{}".format(task_id), params=params)
        except HTTPError as e:
            if e.response.status_code == 404:
                # Raise ApiError as the documented reason is ambiguous
                raise ApiError(
                    "There is no task with the given key, " "or the calling user does not have permission to view it",
                    reason=e,
                )

            raise

        return response

    def get_pdf_download_url_for_confluence_cloud(self, url):
        """
        Confluence cloud does not return the PDF document when the PDF
        export is initiated. Instead, it starts a process in the background
        and provides a link to download the PDF once the process completes.
        This functions polls the long-running task page and returns the
        download url of the PDF.
        :param url: URL to initiate PDF export
        :return: Download url for PDF file
        """
        try:
            running_task = True
            headers = self.form_token_headers
            log.info("Initiate PDF export from Confluence Cloud")
            response = self.get(url, headers=headers, not_json_response=True)
            response_string = response.decode(encoding="utf-8", errors="ignore")
            task_id = response_string.split('name="ajs-taskId" content="')[1].split('">')[0]
            poll_url = "/services/api/v1/task/{0}/progress".format(task_id)
            while running_task:
                log.info("Check if export task has completed.")
                progress_response = self.get(poll_url)
                percentage_complete = int(progress_response.get("progress", 0))
                task_state = progress_response.get("state")
                if task_state == "FAILED":
                    log.error("PDF conversion not successful.")
                    return None
                elif percentage_complete == 100:
                    running_task = False
                    log.info("Task completed - {task_state}".format(task_state=task_state))
                    log.debug("Extract task results to download PDF.")
                    task_result_url = progress_response.get("result")
                else:
                    log.info(
                        "{percentage_complete}% - {task_state}".format(
                            percentage_complete=percentage_complete, task_state=task_state
                        )
                    )
                    time.sleep(3)
            log.debug("Task successfully done, querying the task result for the download url")
            # task result url starts with /wiki, remove it.
            task_content = self.get(task_result_url[5:], not_json_response=True)
            download_url = task_content.decode(encoding="utf-8", errors="strict")
            log.debug("Successfully got the download url")
            return download_url
        except IndexError as e:
            log.error(e)
            return None

    def audit(
        self,
        start_date=None,
        end_date=None,
        start=None,
        limit=None,
        search_string=None,
    ):
        """
        Fetch a paginated list of AuditRecord instances dating back to a certain time
        :param start_date:
        :param end_date:
        :param start:
        :param limit:
        :param search_string:
        :return:
        """
        url = "rest/api/audit"
        params = {}
        if start_date:
            params["startDate"] = start_date
        if end_date:
            params["endDate"] = end_date
        if start:
            params["start"] = start
        if limit:
            params["limit"] = limit
        if search_string:
            params["searchString"] = search_string
        return self.get(url, params=params)

    """
    ##############################################################################################
    #   Confluence whiteboards (cloud only!)  #
    ##############################################################################################
    """

    def create_whiteboard(self, spaceId, title=None, parentId=None):
        url = "/api/v2/whiteboards"
        data = {"spaceId": spaceId}
        if title is not None:
            data["title"] = title
        if parentId is not None:
            data["parentId"] = parentId
        return self.post(url, data=data)

    def get_whiteboard(self, whiteboard_id):
        try:
            url = f"/api/v2/whiteboards/{whiteboard_id}"
            return self.get(url)
        except HTTPError as e:
            # Default 404 error handling is ambiguous
            if e.response.status_code == 404:
                raise ApiValueError(
                    "Whiteboard not found. Check confluence instance url and/or if whiteboard id exists", reason=e
                )

            raise

    def delete_whiteboard(self, whiteboard_id):
        try:
            url = f"/api/v2/whiteboards/{whiteboard_id}"
            return self.delete(url)
        except HTTPError as e:
            # # Default 404 error handling is ambiguous
            if e.response.status_code == 404:
                raise ApiValueError(
                    "Whiteboard not found. Check confluence instance url and/or if whiteboard id exists", reason=e
                )

            raise

    """
    ##############################################################################################
    #   Team Calendars REST API implements  (https://jira.atlassian.com/browse/CONFSERVER-51003) #
    ##############################################################################################
    """

    def team_calendars_get_sub_calendars(self, include=None, viewing_space_key=None, calendar_context=None):
        """
        Get subscribed calendars
        :param include:
        :param viewing_space_key:
        :param calendar_context:
        :return:
        """
        url = "rest/calendar-services/1.0/calendar/subcalendars"
        params = {}
        if include:
            params["include"] = include
        if viewing_space_key:
            params["viewingSpaceKey"] = viewing_space_key
        if calendar_context:
            params["calendarContext"] = calendar_context
        return self.get(url, params=params)

    def team_calendars_get_sub_calendars_watching_status(self, include=None):
        url = "rest/calendar-services/1.0/calendar/subcalendars/watching/status"
        params = {}
        if include:
            params["include"] = include
        return self.get(url, params=params)

    def team_calendar_events(self, sub_calendar_id, start, end, user_time_zone_id=None):
        """
        Get calendar event status
        :param sub_calendar_id:
        :param start:
        :param end:
        :param user_time_zone_id:
        :return:
        """
        url = "rest/calendar-services/1.0/calendar/events"
        params = {}
        if sub_calendar_id:
            params["subCalendarId"] = sub_calendar_id
        if user_time_zone_id:
            params["userTimeZoneId"] = user_time_zone_id
        if start:
            params["start"] = start
        if end:
            params["end"] = end
        return self.get(url, params=params)

    def get_mobile_parameters(self, username):
        """
        Get mobile paramaters
        :param username:
        :return:
        """
        url = "rest/mobile/1.0/profile/{username}".format(username=username)
        return self.get(url)

    def avatar_upload_for_user(self, user_key, data):
        """

        :param user_key:
        :param data: json like {"avatarDataURI":"image in base64"}
        :return:
        """
        url = "rest/user-profile/1.0/{}/avatar/upload".format(user_key)
        return self.post(url, data=data)

    def avatar_set_default_for_user(self, user_key):
        """
        :param user_key:
        :return:
        """
        url = "rest/user-profile/1.0/{}/avatar/default".format(user_key)
        return self.get(url)

    def add_user(self, email, fullname, username, password):
        """
        That method related to creating user via json rpc for Confluence Server
        """
        params = {"email": email, "fullname": fullname, "name": username}
        url = "rpc/json-rpc/confluenceservice-v2"
        data = {
            "jsonrpc": "2.0",
            "method": "addUser",
            "params": [params, password],
        }
        self.post(url, data=data)

    def change_user_password(self, username, password):
        """
        That method related to changing user password via json rpc for Confluence Server
        """
        params = {"name": username}
        url = "rpc/json-rpc/confluenceservice-v2"
        data = {
            "jsonrpc": "2.0",
            "method": "changeUserPassword",
            "params": [params, password],
        }
        self.post(url, data=data)

    def change_my_password(self, oldpass, newpass):
        """
        That method related to changing calling user's own password via json rpc for Confluence Server
        """
        url = "rpc/json-rpc/confluenceservice-v2"
        data = {
            "jsonrpc": "2.0",
            "method": "changeMyPassword",
            "params": [oldpass, newpass],
        }
        self.post(url, data=data)

    def add_user_to_group(self, username, group_name):
        """
        Add given user to a group

        :param username: str - username of user to add to group
        :param group_name: str - name of group to add user to
        :return: Current state of the group
        """
        url = "rest/api/2/group/user"
        params = {"groupname": group_name}
        data = {"name": username}
        return self.post(url, params=params, data=data)

    def add_space_permissions(
        self,
        space_key,
        subject_type,
        subject_id,
        operation_key,
        operation_target,
    ):
        """
        Add permissions to a space

        :param space_key: str - key of space to add permissions to
        :param subject_type: str - type of subject to add permissions for
        :param subject_id: str - id of subject to add permissions for
        :param operation_key: str - key of operation to add permissions for
        :param operation_target: str - target of operation to add permissions for
        :return: Current permissions of space
        """
        url = "rest/api/space/{}/permission".format(space_key)
        data = {
            "subject": {"type": subject_type, "identifier": subject_id},
            "operation": {"key": operation_key, "target": operation_target},
            "_links": {},
        }

        return self.post(url, data=data, headers=self.experimental_headers)

    def remove_space_permission(self, space_key, user, permission):
        """
        The JSON-RPC APIs for Confluence are provided here to help you browse and discover APIs you have access to.
        JSON-RPC APIs operate differently than REST APIs.
        To learn more about how to use these APIs,
        please refer to the Confluence JSON-RPC documentation on Atlassian Developers.
        """
        if self.api_version == "cloud":
            return {}
        url = "rpc/json-rpc/confluenceservice-v2"
        data = {
            "jsonrpc": "2.0",
            "method": "removePermissionFromSpace",
            "id": 9,
            "params": [permission, user, space_key],
        }
        return self.post(url, data=data).get("result") or {}

    def get_space_permissions(self, space_key):
        """
        The JSON-RPC APIs for Confluence are provided here to help you browse and discover APIs you have access to.
        JSON-RPC APIs operate differently than REST APIs.
        To learn more about how to use these APIs,
        please refer to the Confluence JSON-RPC documentation on Atlassian Developers.
        """
        if self.api_version == "cloud":
            return self.get_space(space_key=space_key, expand="permissions")
        url = "rpc/json-rpc/confluenceservice-v2"
        data = {
            "jsonrpc": "2.0",
            "method": "getSpacePermissionSets",
            "id": 7,
            "params": [space_key],
        }
        return self.post(url, data=data).get("result") or {}

    def get_subtree_of_content_ids(self, page_id):
        """
        Get subtree of page ids
        :param page_id:
        :return: Set of page ID
        """
        output = list()
        output.append(page_id)
        children_pages = self.get_page_child_by_type(page_id)
        for page in children_pages:
            child_subtree = self.get_subtree_of_content_ids(page.get("id"))
            if child_subtree:
                output.extend([p for p in child_subtree])
        return set(output)

    def set_inline_tasks_checkbox(self, page_id, task_id, status):
        """
        Set inline task element value
        status is CHECKED or UNCHECKED
        :return:
        """
        url = "rest/inlinetasks/1/task/{page_id}/{task_id}/".format(page_id=page_id, task_id=task_id)
        data = {"status": status, "trigger": "VIEW_PAGE"}
        return self.post(url, json=data)

    def get_jira_metadata(self, page_id):
        """
        Get linked Jira ticket metadata
        PRIVATE method
        :param page_id: Page Id
        :return:
        """
        url = "rest/jira-metadata/1.0/metadata"
        params = {"pageId": page_id}
        return self.get(url, params=params)

    def get_jira_metadata_aggregated(self, page_id):
        """
        Get linked Jira ticket aggregated metadata
        PRIVATE method
        :param page_id: Page Id
        :return:
        """
        url = "rest/jira-metadata/1.0/metadata/aggregate"
        params = {"pageId": page_id}
        return self.get(url, params=params)

    def clean_jira_metadata_cache(self, global_id):
        """
        Clean cache for linked Jira app link
        PRIVATE method
        :param global_id: ID of Jira app link
        :return:
        """
        url = "rest/jira-metadata/1.0/metadata/cache"
        params = {"globalId": global_id}
        return self.delete(url, params=params)

    # Collaborative editing
    def collaborative_editing_get_configuration(self):
        """
        Get collaborative editing configuration
        Related to the on-prem setup Confluence Data Center
        :return:
        """
        if self.cloud:
            return ApiNotAcceptable
        url = "rest/synchrony-interop/configuration"
        return self.get(url, headers=self.no_check_headers)

    def collaborative_editing_disable(self):
        """
        Disable collaborative editing
        Related to the on-prem setup Confluence Data Center
        :return:
        """
        if self.cloud:
            return ApiNotAcceptable
        url = "rest/synchrony-interop/disable"
        return self.post(url, headers=self.no_check_headers)

    def collaborative_editing_enable(self):
        """
        Disable collaborative editing
        Related to the on-prem setup Confluence Data Center
        :return:
        """
        if self.cloud:
            return ApiNotAcceptable
        url = "rest/synchrony-interop/enable"
        return self.post(url, headers=self.no_check_headers)

    def collaborative_editing_restart(self):
        """
        Disable collaborative editing
        Related to the on-prem setup Confluence Data Center
        :return:
        """
        if self.cloud:
            return ApiNotAcceptable
        url = "rest/synchrony-interop/restart"
        return self.post(url, headers=self.no_check_headers)

    def collaborative_editing_shared_draft_status(self):
        """
        Status of collaborative editing
        Related to the on-prem setup Confluence Data Center
        :return: false or true parameter in json
                {
                     "sharedDraftsEnabled": false
                }
        """
        if self.cloud:
            return ApiNotAcceptable
        url = "rest/synchrony-interop/status"
        return self.get(url, headers=self.no_check_headers)

    def collaborative_editing_synchrony_status(self):
        """
        Status of collaborative editing
        Related to the on-prem setup Confluence Data Center
        :return: stopped or running parameter in json
            {
                "status": "stopped"
            }
        """
        if self.cloud:
            return ApiNotAcceptable
        url = "rest/synchrony-interop/synchrony-status"
        return self.get(url, headers=self.no_check_headers)

    def synchrony_get_configuration(self):
        """
        Status of collaborative editing
        Related to the on-prem setup Confluence Data Center
        :return:
        """
        if self.cloud:
            return ApiNotAcceptable
        url = "rest/synchrony/1.0/config/status"
        return self.get(url, headers=self.no_check_headers)

    def synchrony_remove_draft(self, page_id):
        """
        Status of collaborative editing
        Related to the on-prem setup Confluence Data Center
        :return:
        """
        if self.cloud:
            return ApiNotAcceptable
        url = "rest/synchrony/1.0/content/{pageId}/changes/unpublished".format(pageId=page_id)
        return self.delete(url)

    def get_license_details(self):
        """
        Returns the license detailed information
        """
        url = "rest/license/1.0/license/details"
        return self.get(url)

    def get_license_user_count(self):
        """
        Returns the total used seats in the license
        """
        url = "rest/license/1.0/license/userCount"
        return self.get(url)

    def get_license_remaining(self):
        """
        Returns the available license seats remaining
        """
        url = "rest/license/1.0/license/remainingSeats"
        return self.get(url)

    def get_license_max_users(self):
        """
        Returns the license max users
        """
        url = "rest/license/1.0/license/maxUsers"
        return self.get(url)

    def raise_for_status(self, response):
        """
        Checks the response for an error status and raises an exception with the error message provided by the server
        :param response:
        :return:
        """
        if response.status_code == 401 and response.headers.get("Content-Type") != "application/json;charset=UTF-8":
            raise HTTPError("Unauthorized (401)", response=response)

        if 400 <= response.status_code < 600:
            try:
                j = response.json()
                error_msg = j["message"]
            except Exception as e:
                log.error(e)
                response.raise_for_status()
            else:
                raise HTTPError(error_msg, response=response)

add_comment(page_id, text)

Add comment into page :param page_id :param text

Source code in server/vendor/atlassian/confluence.py
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
def add_comment(self, page_id, text):
    """
    Add comment into page
    :param page_id
    :param text
    """
    data = {
        "type": "comment",
        "container": {"id": page_id, "type": "page", "status": "current"},
        "body": self._create_body(text, "storage"),
    }

    try:
        response = self.post("rest/api/content/", data=data)
    except HTTPError as e:
        if e.response.status_code == 404:
            raise ApiPermissionError(
                "The calling user does not have permission to view the content",
                reason=e,
            )

        raise

    return response

add_space_permissions(space_key, subject_type, subject_id, operation_key, operation_target)

Add permissions to a space

:param space_key: str - key of space to add permissions to :param subject_type: str - type of subject to add permissions for :param subject_id: str - id of subject to add permissions for :param operation_key: str - key of operation to add permissions for :param operation_target: str - target of operation to add permissions for :return: Current permissions of space

Source code in server/vendor/atlassian/confluence.py
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
def add_space_permissions(
    self,
    space_key,
    subject_type,
    subject_id,
    operation_key,
    operation_target,
):
    """
    Add permissions to a space

    :param space_key: str - key of space to add permissions to
    :param subject_type: str - type of subject to add permissions for
    :param subject_id: str - id of subject to add permissions for
    :param operation_key: str - key of operation to add permissions for
    :param operation_target: str - target of operation to add permissions for
    :return: Current permissions of space
    """
    url = "rest/api/space/{}/permission".format(space_key)
    data = {
        "subject": {"type": subject_type, "identifier": subject_id},
        "operation": {"key": operation_key, "target": operation_target},
        "_links": {},
    }

    return self.post(url, data=data, headers=self.experimental_headers)

add_user(email, fullname, username, password)

That method related to creating user via json rpc for Confluence Server

Source code in server/vendor/atlassian/confluence.py
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
def add_user(self, email, fullname, username, password):
    """
    That method related to creating user via json rpc for Confluence Server
    """
    params = {"email": email, "fullname": fullname, "name": username}
    url = "rpc/json-rpc/confluenceservice-v2"
    data = {
        "jsonrpc": "2.0",
        "method": "addUser",
        "params": [params, password],
    }
    self.post(url, data=data)

add_user_to_group(username, group_name)

Add given user to a group

:param username: str - username of user to add to group :param group_name: str - name of group to add user to :return: Current state of the group

Source code in server/vendor/atlassian/confluence.py
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
def add_user_to_group(self, username, group_name):
    """
    Add given user to a group

    :param username: str - username of user to add to group
    :param group_name: str - name of group to add user to
    :return: Current state of the group
    """
    url = "rest/api/2/group/user"
    params = {"groupname": group_name}
    data = {"name": username}
    return self.post(url, params=params, data=data)

anonymous()

Get information about how anonymous is represented in confluence :return:

Source code in server/vendor/atlassian/confluence.py
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
def anonymous(self):
    """
    Get information about how anonymous is represented in confluence
    :return:
    """
    try:
        response = self.get("rest/api/user/anonymous")
    except HTTPError as e:
        if e.response.status_code == 403:
            raise ApiPermissionError(
                "The calling user does not have permission to use Confluence",
                reason=e,
            )

        raise

    return response

append_page(page_id, title, append_body, parent_id=None, type='page', representation='storage', minor_edit=False)

Append body to page if already exist :param parent_id: :param page_id: :param title: :param append_body: :param type: :param representation: OPTIONAL: either Confluence 'storage' or 'wiki' markup format :param minor_edit: Indicates whether to notify watchers about changes. If False then notifications will be sent. :return:

Source code in server/vendor/atlassian/confluence.py
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
def append_page(
    self,
    page_id,
    title,
    append_body,
    parent_id=None,
    type="page",
    representation="storage",
    minor_edit=False,
):
    """
    Append body to page if already exist
    :param parent_id:
    :param page_id:
    :param title:
    :param append_body:
    :param type:
    :param representation: OPTIONAL: either Confluence 'storage' or 'wiki' markup format
    :param minor_edit: Indicates whether to notify watchers about changes.
        If False then notifications will be sent.
    :return:
    """
    log.info('Updating %s "%s"', type, title)

    return self._insert_to_existing_page(
        page_id,
        title,
        append_body,
        parent_id=parent_id,
        type=type,
        representation=representation,
        minor_edit=minor_edit,
        top_of_page=False,
    )

attach_content(content, name, content_type='application/binary', page_id=None, title=None, space=None, comment=None)

Attach (upload) a file to a page, if it exists it will update automatically the version the new file and keep the old one. :param title: The page name :type title: str :param space: The space name :type space: str :param page_id: The page id to which we would like to upload the file :type page_id: str :param name: The name of the attachment :type name: str :param content: Contains the content which should be uploaded :type content: binary :param content_type: Specify the HTTP content type. The default is :type content_type: str :param comment: A comment describing this upload/file :type comment: str

Source code in server/vendor/atlassian/confluence.py
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
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
def attach_content(
    self,
    content,
    name,
    content_type="application/binary",
    page_id=None,
    title=None,
    space=None,
    comment=None,
):
    """
    Attach (upload) a file to a page, if it exists it will update automatically the
    version the new file and keep the old one.
    :param title: The page name
    :type  title: ``str``
    :param space: The space name
    :type  space: ``str``
    :param page_id: The page id to which we would like to upload the file
    :type  page_id: ``str``
    :param name: The name of the attachment
    :type  name: ``str``
    :param content: Contains the content which should be uploaded
    :type  content: ``binary``
    :param content_type: Specify the HTTP content type. The default is
    :type  content_type: ``str``
    :param comment: A comment describing this upload/file
    :type  comment: ``str``
    """
    page_id = self.get_page_id(space=space, title=title) if page_id is None else page_id
    type = "attachment"
    if page_id is not None:
        comment = comment if comment else "Uploaded {filename}.".format(filename=name)
        data = {
            "type": type,
            "fileName": name,
            "contentType": content_type,
            "comment": comment,
            "minorEdit": "true",
        }
        headers = {
            "X-Atlassian-Token": "no-check",
            "Accept": "application/json",
        }
        path = "rest/api/content/{page_id}/child/attachment".format(page_id=page_id)
        # Check if there is already a file with the same name
        attachments = self.get(path=path, headers=headers, params={"filename": name})
        if attachments.get("size"):
            path = path + "/" + attachments["results"][0]["id"] + "/data"

        try:
            response = self.post(
                path=path,
                data=data,
                headers=headers,
                files={"file": (name, content, content_type)},
            )
        except HTTPError as e:
            if e.response.status_code == 403:
                # Raise ApiError as the documented reason is ambiguous
                raise ApiError(
                    "Attachments are disabled or the calling user does "
                    "not have permission to add attachments to this content",
                    reason=e,
                )
            if e.response.status_code == 404:
                # Raise ApiError as the documented reason is ambiguous
                raise ApiError(
                    "The requested content is not found, the user does not have "
                    "permission to view it, or the attachments exceeds the maximum "
                    "configured attachment size",
                    reason=e,
                )

            raise

        return response
    else:
        log.warning("No 'page_id' found, not uploading attachments")
        return None

attach_file(filename, name=None, content_type=None, page_id=None, title=None, space=None, comment=None)

Attach (upload) a file to a page, if it exists it will update automatically the version the new file and keep the old one. :param title: The page name :type title: str :param space: The space name :type space: str :param page_id: The page id to which we would like to upload the file :type page_id: str :param filename: The file to upload (Specifies the content) :type filename: str :param name: Specifies name of the attachment. This parameter is optional. Is no name give the file name is used as name :type name: str :param content_type: Specify the HTTP content type. The default is :type content_type: str :param comment: A comment describing this upload/file :type comment: str

Source code in server/vendor/atlassian/confluence.py
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
def attach_file(
    self,
    filename,
    name=None,
    content_type=None,
    page_id=None,
    title=None,
    space=None,
    comment=None,
):
    """
    Attach (upload) a file to a page, if it exists it will update automatically the
    version the new file and keep the old one.
    :param title: The page name
    :type  title: ``str``
    :param space: The space name
    :type  space: ``str``
    :param page_id: The page id to which we would like to upload the file
    :type  page_id: ``str``
    :param filename: The file to upload (Specifies the content)
    :type  filename: ``str``
    :param name: Specifies name of the attachment. This parameter is optional.
                 Is no name give the file name is used as name
    :type  name: ``str``
    :param content_type: Specify the HTTP content type. The default is
    :type  content_type: ``str``
    :param comment: A comment describing this upload/file
    :type  comment: ``str``
    """
    # get base name of the file to get the attachment from confluence.
    if name is None:
        name = os.path.basename(filename)
    if content_type is None:
        extension = os.path.splitext(filename)[-1]
        content_type = self.content_types.get(extension, "application/binary")

    with open(filename, "rb") as infile:
        content = infile.read()
    return self.attach_content(
        content,
        name,
        content_type,
        page_id=page_id,
        title=title,
        space=space,
        comment=comment,
    )

audit(start_date=None, end_date=None, start=None, limit=None, search_string=None)

Fetch a paginated list of AuditRecord instances dating back to a certain time :param start_date: :param end_date: :param start: :param limit: :param search_string: :return:

Source code in server/vendor/atlassian/confluence.py
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
def audit(
    self,
    start_date=None,
    end_date=None,
    start=None,
    limit=None,
    search_string=None,
):
    """
    Fetch a paginated list of AuditRecord instances dating back to a certain time
    :param start_date:
    :param end_date:
    :param start:
    :param limit:
    :param search_string:
    :return:
    """
    url = "rest/api/audit"
    params = {}
    if start_date:
        params["startDate"] = start_date
    if end_date:
        params["endDate"] = end_date
    if start:
        params["start"] = start
    if limit:
        params["limit"] = limit
    if search_string:
        params["searchString"] = search_string
    return self.get(url, params=params)

avatar_set_default_for_user(user_key)

:param user_key: :return:

Source code in server/vendor/atlassian/confluence.py
3016
3017
3018
3019
3020
3021
3022
def avatar_set_default_for_user(self, user_key):
    """
    :param user_key:
    :return:
    """
    url = "rest/user-profile/1.0/{}/avatar/default".format(user_key)
    return self.get(url)

avatar_upload_for_user(user_key, data)

:param user_key: :param data: json like {"avatarDataURI":"image in base64"} :return:

Source code in server/vendor/atlassian/confluence.py
3006
3007
3008
3009
3010
3011
3012
3013
3014
def avatar_upload_for_user(self, user_key, data):
    """

    :param user_key:
    :param data: json like {"avatarDataURI":"image in base64"}
    :return:
    """
    url = "rest/user-profile/1.0/{}/avatar/upload".format(user_key)
    return self.post(url, data=data)

change_my_password(oldpass, newpass)

That method related to changing calling user's own password via json rpc for Confluence Server

Source code in server/vendor/atlassian/confluence.py
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
def change_my_password(self, oldpass, newpass):
    """
    That method related to changing calling user's own password via json rpc for Confluence Server
    """
    url = "rpc/json-rpc/confluenceservice-v2"
    data = {
        "jsonrpc": "2.0",
        "method": "changeMyPassword",
        "params": [oldpass, newpass],
    }
    self.post(url, data=data)

change_user_password(username, password)

That method related to changing user password via json rpc for Confluence Server

Source code in server/vendor/atlassian/confluence.py
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
def change_user_password(self, username, password):
    """
    That method related to changing user password via json rpc for Confluence Server
    """
    params = {"name": username}
    url = "rpc/json-rpc/confluenceservice-v2"
    data = {
        "jsonrpc": "2.0",
        "method": "changeUserPassword",
        "params": [params, password],
    }
    self.post(url, data=data)

check_long_task_result(task_id, expand=None)

Get result of long tasks :param task_id: task id :param expand: :return:

Source code in server/vendor/atlassian/confluence.py
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
def check_long_task_result(self, task_id, expand=None):
    """
    Get result of long tasks
    :param task_id: task id
    :param expand:
    :return:
    """
    params = None
    if expand:
        params = {"expand": expand}

    try:
        response = self.get("rest/api/longtask/{}".format(task_id), params=params)
    except HTTPError as e:
        if e.response.status_code == 404:
            # Raise ApiError as the documented reason is ambiguous
            raise ApiError(
                "There is no task with the given key, " "or the calling user does not have permission to view it",
                reason=e,
            )

        raise

    return response

check_long_tasks_result(start=None, limit=None, expand=None)

Get result of long tasks :param start: OPTIONAL: The start point of the collection to return. Default: None (0). :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by fixed system limits. Default: 50 :param expand: :return:

Source code in server/vendor/atlassian/confluence.py
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
def check_long_tasks_result(self, start=None, limit=None, expand=None):
    """
    Get result of long tasks
    :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
    :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
                        fixed system limits. Default: 50
    :param expand:
    :return:
    """
    params = {}
    if expand:
        params["expand"] = expand
    if start:
        params["start"] = start
    if limit:
        params["limit"] = limit
    return self.get("rest/api/longtask", params=params)

clean_all_caches()

Clean all caches from cache management

Source code in server/vendor/atlassian/confluence.py
2154
2155
2156
2157
def clean_all_caches(self):
    """Clean all caches from cache management"""
    headers = self.form_token_headers
    return self.delete("rest/cacheManagement/1.0/cacheEntries", headers=headers)

clean_jira_metadata_cache(global_id)

Clean cache for linked Jira app link PRIVATE method :param global_id: ID of Jira app link :return:

Source code in server/vendor/atlassian/confluence.py
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
def clean_jira_metadata_cache(self, global_id):
    """
    Clean cache for linked Jira app link
    PRIVATE method
    :param global_id: ID of Jira app link
    :return:
    """
    url = "rest/jira-metadata/1.0/metadata/cache"
    params = {"globalId": global_id}
    return self.delete(url, params=params)

clean_package_cache(cache_name='com.gliffy.cache.gon')

Clean caches from cache management e.g. com.gliffy.cache.gon org.hibernate.cache.internal.StandardQueryCache_v5

Source code in server/vendor/atlassian/confluence.py
2159
2160
2161
2162
2163
2164
2165
2166
2167
def clean_package_cache(self, cache_name="com.gliffy.cache.gon"):
    """Clean caches from cache management
    e.g.
    com.gliffy.cache.gon
    org.hibernate.cache.internal.StandardQueryCache_v5
    """
    headers = self.form_token_headers
    data = {"cacheName": cache_name}
    return self.delete("rest/cacheManagement/1.0/cacheEntries", data=data, headers=headers)

collaborative_editing_disable()

Disable collaborative editing Related to the on-prem setup Confluence Data Center :return:

Source code in server/vendor/atlassian/confluence.py
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
def collaborative_editing_disable(self):
    """
    Disable collaborative editing
    Related to the on-prem setup Confluence Data Center
    :return:
    """
    if self.cloud:
        return ApiNotAcceptable
    url = "rest/synchrony-interop/disable"
    return self.post(url, headers=self.no_check_headers)

collaborative_editing_enable()

Disable collaborative editing Related to the on-prem setup Confluence Data Center :return:

Source code in server/vendor/atlassian/confluence.py
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
def collaborative_editing_enable(self):
    """
    Disable collaborative editing
    Related to the on-prem setup Confluence Data Center
    :return:
    """
    if self.cloud:
        return ApiNotAcceptable
    url = "rest/synchrony-interop/enable"
    return self.post(url, headers=self.no_check_headers)

collaborative_editing_get_configuration()

Get collaborative editing configuration Related to the on-prem setup Confluence Data Center :return:

Source code in server/vendor/atlassian/confluence.py
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
def collaborative_editing_get_configuration(self):
    """
    Get collaborative editing configuration
    Related to the on-prem setup Confluence Data Center
    :return:
    """
    if self.cloud:
        return ApiNotAcceptable
    url = "rest/synchrony-interop/configuration"
    return self.get(url, headers=self.no_check_headers)

collaborative_editing_restart()

Disable collaborative editing Related to the on-prem setup Confluence Data Center :return:

Source code in server/vendor/atlassian/confluence.py
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
def collaborative_editing_restart(self):
    """
    Disable collaborative editing
    Related to the on-prem setup Confluence Data Center
    :return:
    """
    if self.cloud:
        return ApiNotAcceptable
    url = "rest/synchrony-interop/restart"
    return self.post(url, headers=self.no_check_headers)

collaborative_editing_shared_draft_status()

Status of collaborative editing Related to the on-prem setup Confluence Data Center :return: false or true parameter in json { "sharedDraftsEnabled": false }

Source code in server/vendor/atlassian/confluence.py
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
def collaborative_editing_shared_draft_status(self):
    """
    Status of collaborative editing
    Related to the on-prem setup Confluence Data Center
    :return: false or true parameter in json
            {
                 "sharedDraftsEnabled": false
            }
    """
    if self.cloud:
        return ApiNotAcceptable
    url = "rest/synchrony-interop/status"
    return self.get(url, headers=self.no_check_headers)

collaborative_editing_synchrony_status()

Status of collaborative editing Related to the on-prem setup Confluence Data Center :return: stopped or running parameter in json { "status": "stopped" }

Source code in server/vendor/atlassian/confluence.py
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
def collaborative_editing_synchrony_status(self):
    """
    Status of collaborative editing
    Related to the on-prem setup Confluence Data Center
    :return: stopped or running parameter in json
        {
            "status": "stopped"
        }
    """
    if self.cloud:
        return ApiNotAcceptable
    url = "rest/synchrony-interop/synchrony-status"
    return self.get(url, headers=self.no_check_headers)

convert_storage_to_view(storage)

Convert from Confluence XHTML format to view format :param storage: :return:

Source code in server/vendor/atlassian/confluence.py
1979
1980
1981
1982
1983
1984
1985
1986
def convert_storage_to_view(self, storage):
    """
    Convert from Confluence XHTML format to view format
    :param storage:
    :return:
    """
    data = {"value": storage, "representation": "storage"}
    return self.post("rest/api/contentbody/convert/view", data=data)

convert_wiki_to_storage(wiki)

Convert to Confluence XHTML format from wiki style :param wiki: :return:

Source code in server/vendor/atlassian/confluence.py
1970
1971
1972
1973
1974
1975
1976
1977
def convert_wiki_to_storage(self, wiki):
    """
    Convert to Confluence XHTML format from wiki style
    :param wiki:
    :return:
    """
    data = {"value": wiki, "representation": "wiki"}
    return self.post("rest/api/contentbody/convert/storage", data=data)

cql(cql, start=0, limit=None, expand=None, include_archived_spaces=None, excerpt=None)

Get results from cql search result with all related fields Search for entities in Confluence using the Confluence Query Language (CQL) :param cql: :param start: OPTIONAL: The start point of the collection to return. Default: 0. :param limit: OPTIONAL: The limit of the number of issues to return, this may be restricted by fixed system limits. Default by built-in method: 25 :param excerpt: the excerpt strategy to apply to the result, one of : indexed, highlight, none. This defaults to highlight :param expand: OPTIONAL: the properties to expand on the search result, this may cause database requests for some properties :param include_archived_spaces: OPTIONAL: whether to include content in archived spaces in the result, this defaults to false :return:

Source code in server/vendor/atlassian/confluence.py
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
def cql(
    self,
    cql,
    start=0,
    limit=None,
    expand=None,
    include_archived_spaces=None,
    excerpt=None,
):
    """
    Get results from cql search result with all related fields
    Search for entities in Confluence using the Confluence Query Language (CQL)
    :param cql:
    :param start: OPTIONAL: The start point of the collection to return. Default: 0.
    :param limit: OPTIONAL: The limit of the number of issues to return, this may be restricted by
                    fixed system limits. Default by built-in method: 25
    :param excerpt: the excerpt strategy to apply to the result, one of : indexed, highlight, none.
                    This defaults to highlight
    :param expand: OPTIONAL: the properties to expand on the search result,
                    this may cause database requests for some properties
    :param include_archived_spaces: OPTIONAL: whether to include content in archived spaces in the result,
                                this defaults to false
    :return:
    """
    params = {}
    if start is not None:
        params["start"] = int(start)
    if limit is not None:
        params["limit"] = int(limit)
    if cql is not None:
        params["cql"] = cql
    if expand is not None:
        params["expand"] = expand
    if include_archived_spaces is not None:
        params["includeArchivedSpaces"] = include_archived_spaces
    if excerpt is not None:
        params["excerpt"] = excerpt

    try:
        response = self.get("rest/api/search", params=params)
    except HTTPError as e:
        if e.response.status_code == 400:
            raise ApiValueError("The query cannot be parsed", reason=e)

        raise

    return response

create_group(name)

Create a group by given group parameter

:param name: str :return: New group params

Source code in server/vendor/atlassian/confluence.py
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
def create_group(self, name):
    """
    Create a group by given group parameter

    :param name: str
    :return: New group params
    """
    url = "rest/api/admin/group"
    data = {"name": name, "type": "group"}
    return self.post(url, data=data)

create_or_update_template(name, body, template_type='page', template_id=None, description=None, labels=None, space=None)

Creates a new or updates an existing content template.

Note, blueprint templates cannot be created or updated via the REST API.

If you provide a template_id then this method will update the template with the provided settings. If no template_id is provided, then this method assumes you are creating a new template.

:param str name: If creating, the name of the new template. If updating, the name to change the template name to. Set to the current name if this field is not being updated. :param dict body: This object is used when creating or updating content. { "storage": { "value": "", "representation": "view" } } :param str template_type: OPTIONAL: The type of the new template. Default: "page". :param str template_id: OPTIONAL: The ID of the template being updated. REQUIRED if updating a template. :param str description: OPTIONAL: A description of the new template. Max length 255. :param list labels: OPTIONAL: Labels for the new template. An array like: [ { "prefix": "", "name": "", "id": "", "label": "", } ] :param dict space: OPTIONAL: The key for the space of the new template. Only applies to space templates. If not specified, the template will be created as a global template. :return:

Source code in server/vendor/atlassian/confluence.py
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
def create_or_update_template(
    self,
    name,
    body,
    template_type="page",
    template_id=None,
    description=None,
    labels=None,
    space=None,
):
    """
    Creates a new or updates an existing content template.

    Note, blueprint templates cannot be created or updated via the REST API.

    If you provide a ``template_id`` then this method will update the template with the provided settings.
    If no ``template_id`` is provided, then this method assumes you are creating a new template.

    :param str name: If creating, the name of the new template. If updating, the name to change
        the template name to. Set to the current name if this field is not being updated.
    :param dict body: This object is used when creating or updating content.
        {
            "storage": {
                "value": "<string>",
                "representation": "view"
            }
        }
    :param str template_type: OPTIONAL: The type of the new template. Default: "page".
    :param str template_id: OPTIONAL: The ID of the template being updated. REQUIRED if updating a template.
    :param str description: OPTIONAL: A description of the new template. Max length 255.
    :param list labels: OPTIONAL: Labels for the new template. An array like:
        [
            {
                "prefix": "<string>",
                "name": "<string>",
                "id": "<string>",
                "label": "<string>",
            }
        ]
    :param dict space: OPTIONAL: The key for the space of the new template. Only applies to space templates.
        If not specified, the template will be created as a global template.
    :return:
    """
    data = {"name": name, "templateType": template_type, "body": body}

    if description:
        data["description"] = description

    if labels:
        data["labels"] = labels

    if space:
        data["space"] = {"key": space}

    if template_id:
        data["templateId"] = template_id
        return self.put("rest/api/template", data=json.dumps(data))

    return self.post("rest/api/template", json=data)

create_page(space, title, body, parent_id=None, type='page', representation='storage', editor=None, full_width=False)

Create page from scratch :param space: :param title: :param body: :param parent_id: :param type: :param representation: OPTIONAL: either Confluence 'storage' or 'wiki' markup format :param editor: OPTIONAL: v2 to be created in the new editor :param full_width: DEFAULT: False :return:

Source code in server/vendor/atlassian/confluence.py
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
def create_page(
    self,
    space,
    title,
    body,
    parent_id=None,
    type="page",
    representation="storage",
    editor=None,
    full_width=False,
):
    """
    Create page from scratch
    :param space:
    :param title:
    :param body:
    :param parent_id:
    :param type:
    :param representation: OPTIONAL: either Confluence 'storage' or 'wiki' markup format
    :param editor: OPTIONAL: v2 to be created in the new editor
    :param full_width: DEFAULT: False
    :return:
    """
    log.info('Creating %s "%s" -> "%s"', type, space, title)
    url = "rest/api/content/"
    data = {
        "type": type,
        "title": title,
        "space": {"key": space},
        "body": self._create_body(body, representation),
        "metadata": {"properties": {}},
    }
    if parent_id:
        data["ancestors"] = [{"type": type, "id": parent_id}]
    if editor is not None and editor in ["v1", "v2"]:
        data["metadata"]["properties"]["editor"] = {"value": editor}
    if full_width is True:
        data["metadata"]["properties"]["content-appearance-draft"] = {"value": "full-width"}
        data["metadata"]["properties"]["content-appearance-published"] = {"value": "full-width"}
    else:
        data["metadata"]["properties"]["content-appearance-draft"] = {"value": "fixed-width"}
        data["metadata"]["properties"]["content-appearance-published"] = {"value": "fixed-width"}

    try:
        response = self.post(url, data=data)
    except HTTPError as e:
        if e.response.status_code == 404:
            raise ApiPermissionError(
                "The calling user does not have permission to view the content",
                reason=e,
            )

        raise

    return response

create_space(space_key, space_name)

Create space :param space_key: :param space_name: :return:

Source code in server/vendor/atlassian/confluence.py
2362
2363
2364
2365
2366
2367
2368
2369
2370
def create_space(self, space_key, space_name):
    """
    Create space
    :param space_key:
    :param space_name:
    :return:
    """
    data = {"key": space_key, "name": space_name}
    self.post("rest/api/space", data=data)

delete_attachment(page_id, filename, version=None)

Remove completely a file if version is None or delete version :param version: :param page_id: file version :param filename: :return:

Source code in server/vendor/atlassian/confluence.py
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
def delete_attachment(self, page_id, filename, version=None):
    """
    Remove completely a file if version is None or delete version
    :param version:
    :param page_id: file version
    :param filename:
    :return:
    """
    params = {"pageId": page_id, "fileName": filename}
    if version:
        params["version"] = version
    return self.post(
        "json/removeattachment.action",
        params=params,
        headers=self.form_token_headers,
    )

delete_attachment_by_id(attachment_id, version)

Remove completely a file if version is None or delete version :param attachment_id: :param version: file version :return:

Source code in server/vendor/atlassian/confluence.py
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
def delete_attachment_by_id(self, attachment_id, version):
    """
    Remove completely a file if version is None or delete version
    :param attachment_id:
    :param version: file version
    :return:
    """
    return self.delete(
        "rest/experimental/content/{id}/version/{versionId}".format(id=attachment_id, versionId=version)
    )

delete_page_property(page_id, page_property)

Delete the page (content) property e.g. delete key of hash :param page_id: content_id format :param page_property: key of property :return:

Source code in server/vendor/atlassian/confluence.py
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
def delete_page_property(self, page_id, page_property):
    """
    Delete the page (content) property e.g. delete key of hash
    :param page_id: content_id format
    :param page_property: key of property
    :return:
    """
    url = "rest/api/content/{page_id}/property/{page_property}".format(
        page_id=page_id, page_property=str(page_property)
    )
    try:
        response = self.delete(path=url)
    except HTTPError as e:
        if e.response.status_code == 404:
            # Raise ApiError as the documented reason is ambiguous
            raise ApiError(
                "There is no content with the given id, "
                "or the calling user does not have permission to view the content",
                reason=e,
            )

        raise

    return response

delete_plugin(plugin_key)

Delete plugin :param plugin_key: :return:

Source code in server/vendor/atlassian/confluence.py
2754
2755
2756
2757
2758
2759
2760
2761
def delete_plugin(self, plugin_key):
    """
    Delete plugin
    :param plugin_key:
    :return:
    """
    url = "rest/plugins/1.0/{}-key".format(plugin_key)
    return self.delete(url)

delete_space(space_key)

Delete space :param space_key: :return:

Source code in server/vendor/atlassian/confluence.py
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
def delete_space(self, space_key):
    """
    Delete space
    :param space_key:
    :return:
    """
    url = "rest/api/space/{}".format(space_key)

    try:
        response = self.delete(url)
    except HTTPError as e:
        if e.response.status_code == 404:
            # Raise ApiError as the documented reason is ambiguous
            raise ApiError(
                "There is no space with the given key, "
                "or the calling user does not have permission to delete it",
                reason=e,
            )

        raise

    return response

disable_plugin(plugin_key)

Disable a plugin :param plugin_key: :return:

Source code in server/vendor/atlassian/confluence.py
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
def disable_plugin(self, plugin_key):
    """
    Disable a plugin
    :param plugin_key:
    :return:
    """
    app_headers = {
        "X-Atlassian-Token": "nocheck",
        "Content-Type": "application/vnd.atl.plugins+json",
    }
    url = "rest/plugins/1.0/{plugin_key}-key".format(plugin_key=plugin_key)
    data = {"status": "disabled"}
    return self.put(url, data=data, headers=app_headers)

download_attachments_from_page(page_id, path=None, start=0, limit=50)

Downloads all attachments from a page :param page_id: :param path: OPTIONAL: path to directory where attachments will be saved. If None, current working directory will be used. :param start: OPTIONAL: The start point of the collection to return. Default: None (0). :param limit: OPTIONAL: The limit of the number of attachments to return, this may be restricted by fixed system limits. Default: 50 :return info message: number of saved attachments + path to directory where attachments were saved:

Source code in server/vendor/atlassian/confluence.py
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
def download_attachments_from_page(self, page_id, path=None, start=0, limit=50):
    """
    Downloads all attachments from a page
    :param page_id:
    :param path: OPTIONAL: path to directory where attachments will be saved. If None, current working directory will be used.
    :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
    :param limit: OPTIONAL: The limit of the number of attachments to return, this may be restricted by
                            fixed system limits. Default: 50
    :return info message: number of saved attachments + path to directory where attachments were saved:
    """
    if path is None:
        path = os.getcwd()
    try:
        attachments = self.get_attachments_from_content(page_id=page_id, start=start, limit=limit)["results"]
        if not attachments:
            return "No attachments found"
        for attachment in attachments:
            file_name = attachment["title"]
            if not file_name:
                file_name = attachment["id"]  # if the attachment has no title, use attachment_id as a filename
            download_link = self.url + attachment["_links"]["download"]
            r = self._session.get(f"{download_link}")
            file_path = os.path.join(path, file_name)
            with open(file_path, "wb") as f:
                f.write(r.content)
    except NotADirectoryError:
        raise NotADirectoryError("Verify if directory path is correct and/or if directory exists")
    except PermissionError:
        raise PermissionError(
            "Directory found, but there is a problem with saving file to this directory. Check directory permissions"
        )
    except Exception as e:
        raise e
    return {"attachments downloaded": len(attachments), " to path ": path}

enable_plugin(plugin_key)

Enable a plugin :param plugin_key: :return:

Source code in server/vendor/atlassian/confluence.py
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
def enable_plugin(self, plugin_key):
    """
    Enable a plugin
    :param plugin_key:
    :return:
    """
    app_headers = {
        "X-Atlassian-Token": "nocheck",
        "Content-Type": "application/vnd.atl.plugins+json",
    }
    url = "rest/plugins/1.0/{plugin_key}-key".format(plugin_key=plugin_key)
    data = {"status": "enabled"}
    return self.put(url, data=data, headers=app_headers)

export_page(page_id)

Alias method for export page as pdf :param page_id: Page ID :return: PDF File

Source code in server/vendor/atlassian/confluence.py
2584
2585
2586
2587
2588
2589
2590
def export_page(self, page_id):
    """
    Alias method for export page as pdf
    :param page_id: Page ID
    :return: PDF File
    """
    return self.get_page_as_pdf(page_id)

get_all_blueprints_from_space(space, start=0, limit=None, expand=None)

Get all users blueprints from space. Experimental API :param space: Space Key :param start: OPTIONAL: The start point of the collection to return. Default: None (0). :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by fixed system limits. Default: 20 :param expand: OPTIONAL: expand e.g. body

Source code in server/vendor/atlassian/confluence.py
 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
@deprecated(version="3.7.0", reason="Use get_blueprint_templates()")
def get_all_blueprints_from_space(self, space, start=0, limit=None, expand=None):
    """
    Get all users blueprints from space. Experimental API
    :param space: Space Key
    :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
    :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
                        fixed system limits. Default: 20
    :param expand: OPTIONAL: expand e.g. body
    """
    url = "rest/experimental/template/blueprint"
    params = {}
    if space:
        params["spaceKey"] = space
    if start:
        params["start"] = start
    if limit:
        params["limit"] = limit
    if expand:
        params["expand"] = expand

    try:
        response = self.get(url, params=params)
    except HTTPError as e:
        if e.response.status_code == 403:
            raise ApiPermissionError(
                "The calling user does not have permission to view the content",
                reason=e,
            )

        raise

    return response.get("results") or []

get_all_draft_pages_from_space(space, start=0, limit=500, status='draft')

Get list of draft pages from space Use case is cleanup old drafts from Confluence :param space: :param start: OPTIONAL: The start point of the collection to return. Default: None (0). :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by fixed system limits. Default: 500 :param status: :return:

Source code in server/vendor/atlassian/confluence.py
647
648
649
650
651
652
653
654
655
656
657
658
def get_all_draft_pages_from_space(self, space, start=0, limit=500, status="draft"):
    """
    Get list of draft pages from space
    Use case is cleanup old drafts from Confluence
    :param space:
    :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
    :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
                        fixed system limits. Default: 500
    :param status:
    :return:
    """
    return self.get_all_pages_from_space(space, start, limit, status)

get_all_draft_pages_from_space_through_cql(space, start=0, limit=500, status='draft')

Search list of draft pages by space key Use case is cleanup old drafts from Confluence :param space: Space Key :param status: Can be changed :param start: OPTIONAL: The start point of the collection to return. Default: None (0). :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by fixed system limits. Default: 500 :return:

Source code in server/vendor/atlassian/confluence.py
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
def get_all_draft_pages_from_space_through_cql(self, space, start=0, limit=500, status="draft"):
    """
    Search list of draft pages by space key
    Use case is cleanup old drafts from Confluence
    :param space: Space Key
    :param status: Can be changed
    :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
    :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
                        fixed system limits. Default: 500
    :return:
    """
    url = "rest/api/content?cql=space=spaceKey={space} and status={status}".format(space=space, status=status)
    params = {}
    if limit:
        params["limit"] = limit
    if start:
        params["start"] = start

    try:
        response = self.get(url, params=params)
    except HTTPError as e:
        if e.response.status_code == 404:
            raise ApiPermissionError(
                "The calling user does not have permission to view the content",
                reason=e,
            )

        raise

    return response.get("results")

get_all_groups(start=0, limit=1000)

Get all groups from Confluence User management :param start: OPTIONAL: The start point of the collection to return. Default: None (0). :param limit: OPTIONAL: The limit of the number of groups to return, this may be restricted by fixed system limits. Default: 1000 :return:

Source code in server/vendor/atlassian/confluence.py
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
def get_all_groups(self, start=0, limit=1000):
    """
    Get all groups from Confluence User management
    :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
    :param limit: OPTIONAL: The limit of the number of groups to return, this may be restricted by
                            fixed system limits. Default: 1000
    :return:
    """
    url = "rest/api/group?limit={limit}&start={start}".format(limit=limit, start=start)

    try:
        response = self.get(url)
    except HTTPError as e:
        if e.response.status_code == 403:
            raise ApiPermissionError(
                "The calling user does not have permission to view groups",
                reason=e,
            )

        raise

    return response.get("results")

get_all_members(group_name='confluence-users', expand=None)

Get collection of all users in the given group :param group_name :param expand: OPTIONAL: A comma separated list of properties to expand on the content. status :return:

Source code in server/vendor/atlassian/confluence.py
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
def get_all_members(self, group_name="confluence-users", expand=None):
    """
    Get  collection of all users in the given group
    :param group_name
    :param expand: OPTIONAL: A comma separated list of properties to expand on the content. status
    :return:
    """
    limit = 50
    flag = True
    step = 0
    members = []
    while flag:
        values = self.get_group_members(
            group_name=group_name,
            start=len(members),
            limit=limit,
            expand=expand,
        )
        step += 1
        if len(values) == 0:
            flag = False
        else:
            members.extend(values)
    if not members:
        print("Did not get members from {} group, please check permissions or connectivity".format(group_name))
    return members

get_all_pages_by_label(label, start=0, limit=50)

Get all page by label :param label: :param start: OPTIONAL: The start point of the collection to return. Default: None (0). :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by fixed system limits. Default: 50 :return:

Source code in server/vendor/atlassian/confluence.py
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
def get_all_pages_by_label(self, label, start=0, limit=50):
    """
    Get all page by label
    :param label:
    :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
    :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
                  fixed system limits. Default: 50
    :return:
    """
    url = "rest/api/content/search"
    params = {}
    if label:
        params["cql"] = 'type={type} AND label="{label}"'.format(type="page", label=label)
    if start:
        params["start"] = start
    if limit:
        params["limit"] = limit

    try:
        response = self.get(url, params=params)
    except HTTPError as e:
        if e.response.status_code == 400:
            raise ApiValueError("The CQL is invalid or missing", reason=e)

        raise

    return response.get("results")

get_all_pages_from_space(space, start=0, limit=50, status=None, expand=None, content_type='page')

Get all pages from space

:param space: :param start: OPTIONAL: The start point of the collection to return. Default: None (0). :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by fixed system limits. Default: 50 :param status: OPTIONAL: list of statuses the content to be found is in. Defaults to current is not specified. If set to 'any', content in 'current' and 'trashed' status will be fetched. Does not support 'historical' status for now. :param expand: OPTIONAL: a comma separated list of properties to expand on the content. Default value: history,space,version. :param content_type: the content type to return. Default value: page. Valid values: page, blogpost. :return:

Source code in server/vendor/atlassian/confluence.py
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
def get_all_pages_from_space(
    self,
    space,
    start=0,
    limit=50,
    status=None,
    expand=None,
    content_type="page",
):
    """
    Get all pages from space

    :param space:
    :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
    :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
                        fixed system limits. Default: 50
    :param status: OPTIONAL: list of statuses the content to be found is in.
                             Defaults to current is not specified.
                             If set to 'any', content in 'current' and 'trashed' status will be fetched.
                             Does not support 'historical' status for now.
    :param expand: OPTIONAL: a comma separated list of properties to expand on the content.
                             Default value: history,space,version.
    :param content_type: the content type to return. Default value: page. Valid values: page, blogpost.
    :return:
    """
    return self.get_all_pages_from_space_raw(
        space=space, start=start, limit=limit, status=status, expand=expand, content_type=content_type
    ).get("results")

get_all_pages_from_space_raw(space, start=0, limit=50, status=None, expand=None, content_type='page')

Get all pages from space

:param space: :param start: OPTIONAL: The start point of the collection to return. Default: None (0). :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by fixed system limits. Default: 50 :param status: OPTIONAL: list of statuses the content to be found is in. Defaults to current is not specified. If set to 'any', content in 'current' and 'trashed' status will be fetched. Does not support 'historical' status for now. :param expand: OPTIONAL: a comma separated list of properties to expand on the content. Default value: history,space,version. :param content_type: the content type to return. Default value: page. Valid values: page, blogpost. :return:

Source code in server/vendor/atlassian/confluence.py
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
def get_all_pages_from_space_raw(
    self,
    space,
    start=0,
    limit=50,
    status=None,
    expand=None,
    content_type="page",
):
    """
    Get all pages from space

    :param space:
    :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
    :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
                        fixed system limits. Default: 50
    :param status: OPTIONAL: list of statuses the content to be found is in.
                             Defaults to current is not specified.
                             If set to 'any', content in 'current' and 'trashed' status will be fetched.
                             Does not support 'historical' status for now.
    :param expand: OPTIONAL: a comma separated list of properties to expand on the content.
                             Default value: history,space,version.
    :param content_type: the content type to return. Default value: page. Valid values: page, blogpost.
    :return:
    """
    url = "rest/api/content"
    params = {}
    if space:
        params["spaceKey"] = space
    if start:
        params["start"] = start
    if limit:
        params["limit"] = limit
    if status:
        params["status"] = status
    if expand:
        params["expand"] = expand
    if content_type:
        params["type"] = content_type

    try:
        response = self.get(url, params=params)
    except HTTPError as e:
        if e.response.status_code == 404:
            raise ApiPermissionError(
                "The calling user does not have permission to view the content",
                reason=e,
            )

        raise

    return response

get_all_pages_from_space_trash(space, start=0, limit=500, status='trashed', content_type='page')

Get list of pages from trash :param space: :param start: OPTIONAL: The start point of the collection to return. Default: None (0). :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by fixed system limits. Default: 500 :param status: :param content_type: the content type to return. Default value: page. Valid values: page, blogpost. :return:

Source code in server/vendor/atlassian/confluence.py
634
635
636
637
638
639
640
641
642
643
644
645
def get_all_pages_from_space_trash(self, space, start=0, limit=500, status="trashed", content_type="page"):
    """
    Get list of pages from trash
    :param space:
    :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
    :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
                        fixed system limits. Default: 500
    :param status:
    :param content_type: the content type to return. Default value: page. Valid values: page, blogpost.
    :return:
    """
    return self.get_all_pages_from_space(space, start, limit, status, content_type=content_type)

get_all_restictions_for_content(content_id)

Let's use the get_all_restrictions_for_content()

Source code in server/vendor/atlassian/confluence.py
691
692
693
694
695
@deprecated(version="2.4.2", reason="Use get_all_restrictions_for_content()")
def get_all_restictions_for_content(self, content_id):
    """Let's use the get_all_restrictions_for_content()"""
    log.warning("Please, be informed that is deprecated as typo naming")
    return self.get_all_restrictions_for_content(content_id=content_id)

get_all_restrictions_for_content(content_id)

Returns info about all restrictions by operation. :param content_id: :return: Return the raw json response

Source code in server/vendor/atlassian/confluence.py
697
698
699
700
701
702
703
704
def get_all_restrictions_for_content(self, content_id):
    """
    Returns info about all restrictions by operation.
    :param content_id:
    :return: Return the raw json response
    """
    url = "rest/api/content/{}/restriction/byOperation".format(content_id)
    return self.get(url)

get_all_spaces(start=0, limit=500, expand=None, space_type=None, space_status=None)

Get all spaces with provided limit :param start: OPTIONAL: The start point of the collection to return. Default: None (0). :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by fixed system limits. Default: 500 :param space_type: OPTIONAL: Filter the list of spaces returned by type (global, personal) :param space_status: OPTIONAL: Filter the list of spaces returned by status (current, archived) :param expand: OPTIONAL: additional info, e.g. metadata, icon, description, homepage

Source code in server/vendor/atlassian/confluence.py
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
def get_all_spaces(
    self,
    start=0,
    limit=500,
    expand=None,
    space_type=None,
    space_status=None,
):
    """
    Get all spaces with provided limit
    :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
    :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
                        fixed system limits. Default: 500
    :param space_type: OPTIONAL: Filter the list of spaces returned by type (global, personal)
    :param space_status: OPTIONAL: Filter the list of spaces returned by status (current, archived)
    :param expand: OPTIONAL: additional info, e.g. metadata, icon, description, homepage
    """
    url = "rest/api/space"
    params = {}
    if start:
        params["start"] = start
    if limit:
        params["limit"] = limit
    if expand:
        params["expand"] = expand
    if space_type:
        params["type"] = space_type
    if space_status:
        params["status"] = space_status
    return self.get(url, params=params)

get_all_templates_from_space(space, start=0, limit=None, expand=None)

Get all users templates from space. Experimental API ref: https://docs.atlassian.com/atlassian-confluence/1000.73.0/com/atlassian/confluence/plugins/restapi /resources/TemplateResource.html :param space: Space Key :param start: OPTIONAL: The start point of the collection to return. Default: None (0). :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by fixed system limits. Default: 20 :param expand: OPTIONAL: expand e.g. body

Source code in server/vendor/atlassian/confluence.py
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
@deprecated(version="3.7.0", reason="Use get_content_templates()")
def get_all_templates_from_space(self, space, start=0, limit=None, expand=None):
    """
    Get all users templates from space. Experimental API
    ref: https://docs.atlassian.com/atlassian-confluence/1000.73.0/com/atlassian/confluence/plugins/restapi\
/resources/TemplateResource.html
    :param space: Space Key
    :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
    :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
                            fixed system limits. Default: 20
    :param expand: OPTIONAL: expand e.g. body
    """
    url = "rest/experimental/template/page"
    params = {}
    if space:
        params["spaceKey"] = space
    if start:
        params["start"] = start
    if limit:
        params["limit"] = limit
    if expand:
        params["expand"] = expand

    try:
        response = self.get(url, params=params)
    except HTTPError as e:
        if e.response.status_code == 403:
            raise ApiPermissionError(
                "The calling user does not have permission to view the content",
                reason=e,
            )
        raise

    return response.get("results") or []

get_attachment_history(attachment_id, limit=200, start=0)

Get attachment history :param attachment_id :param limit :param start :return

Source code in server/vendor/atlassian/confluence.py
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
def get_attachment_history(self, attachment_id, limit=200, start=0):
    """
    Get attachment history
    :param attachment_id
    :param limit
    :param start
    :return
    """
    params = {"limit": limit, "start": start}
    url = "rest/experimental/content/{}/version".format(attachment_id)
    return (self.get(url, params=params) or {}).get("results")

get_attachments_from_content(page_id, start=0, limit=50, expand=None, filename=None, media_type=None)

Get attachments for page :param page_id: :param start: :param limit: :param expand: :param filename: :param media_type: :return:

Source code in server/vendor/atlassian/confluence.py
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
def get_attachments_from_content(
    self,
    page_id,
    start=0,
    limit=50,
    expand=None,
    filename=None,
    media_type=None,
):
    """
    Get attachments for page
    :param page_id:
    :param start:
    :param limit:
    :param expand:
    :param filename:
    :param media_type:
    :return:
    """
    params = {}
    if start:
        params["start"] = start
    if limit:
        params["limit"] = limit
    if expand:
        params["expand"] = expand
    if filename:
        params["filename"] = filename
    if media_type:
        params["mediaType"] = media_type
    url = "rest/api/content/{id}/child/attachment".format(id=page_id)

    try:
        response = self.get(url, params=params)
    except HTTPError as e:
        if e.response.status_code == 404:
            # Raise ApiError as the documented reason is ambiguous
            raise ApiError(
                "There is no content with the given id, "
                "or the calling user does not have permission to view the content",
                reason=e,
            )

        raise

    return response

get_blueprint_templates(space=None, start=0, limit=None, expand=None)

Gets all templates provided by blueprints.

Use this method to retrieve all global blueprint templates or all blueprint templates in a space. :param space: OPTIONAL: The key of the space to be queried for templates. If space is not specified, global blueprint templates will be returned. :param start: OPTIONAL: The starting index of the returned templates. Default: None (0). :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by fixed system limits. Default: 25 :param expand: OPTIONAL: A multi-value parameter indicating which properties of the template to expand.

Source code in server/vendor/atlassian/confluence.py
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
def get_blueprint_templates(self, space=None, start=0, limit=None, expand=None):
    """
    Gets all templates provided by blueprints.

    Use this method to retrieve all global blueprint templates or all blueprint templates in a space.
    :param space: OPTIONAL: The key of the space to be queried for templates. If ``space`` is not
        specified, global blueprint templates will be returned.
    :param start: OPTIONAL: The starting index of the returned templates. Default: None (0).
    :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
                        fixed system limits. Default: 25
    :param expand: OPTIONAL: A multi-value parameter indicating which properties of the template to expand.
    """
    url = "rest/api/template/blueprint"
    params = {}
    if space:
        params["spaceKey"] = space
    if start:
        params["start"] = start
    if limit:
        params["limit"] = limit
    if expand:
        params["expand"] = expand

    try:
        response = self.get(url, params=params)
    except HTTPError as e:
        if e.response.status_code == 403:
            raise ApiPermissionError(
                "The calling user does not have permission to view the content",
                reason=e,
            )

        raise

    return response.get("results") or []

get_child_id_list(page_id, type='page', start=None, limit=None)

Find a list of Child id :param page_id: A string containing the id of the type content container. :param type: :param start: OPTIONAL: The start point of the collection to return. Default: None (0). :param limit: OPTIONAL: how many items should be returned after the start index. Default: Site limit 200. :return:

Source code in server/vendor/atlassian/confluence.py
191
192
193
194
195
196
197
198
199
200
201
202
def get_child_id_list(self, page_id, type="page", start=None, limit=None):
    """
    Find a list of Child id
    :param page_id: A string containing the id of the type content container.
    :param type:
    :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
    :param limit: OPTIONAL: how many items should be returned after the start index. Default: Site limit 200.
    :return:
    """
    child_page = self.get_page_child_by_type(page_id, type, start, limit)
    child_id_list = [child["id"] for child in child_page]
    return child_id_list

get_child_pages(page_id)

Get child pages for the provided page_id :param page_id: :return:

Source code in server/vendor/atlassian/confluence.py
204
205
206
207
208
209
210
def get_child_pages(self, page_id):
    """
    Get child pages for the provided page_id
    :param page_id:
    :return:
    """
    return self.get_page_child_by_type(page_id=page_id, type="page")

get_child_title_list(page_id, type='page', start=None, limit=None)

Find a list of Child title :param page_id: A string containing the id of the type content container. :param type: :param start: OPTIONAL: The start point of the collection to return. Default: None (0). :param limit: OPTIONAL: how many items should be returned after the start index. Default: Site limit 200. :return:

Source code in server/vendor/atlassian/confluence.py
178
179
180
181
182
183
184
185
186
187
188
189
def get_child_title_list(self, page_id, type="page", start=None, limit=None):
    """
    Find a list of Child title
    :param page_id: A string containing the id of the type content container.
    :param type:
    :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
    :param limit: OPTIONAL: how many items should be returned after the start index. Default: Site limit 200.
    :return:
    """
    child_page = self.get_page_child_by_type(page_id, type, start, limit)
    child_title_list = [child["title"] for child in child_page]
    return child_title_list

get_content_history_by_version_number(content_id, version_number)

Get content history by version number :param content_id: :param version_number: :return:

Source code in server/vendor/atlassian/confluence.py
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
def get_content_history_by_version_number(self, content_id, version_number):
    """
    Get content history by version number
    :param content_id:
    :param version_number:
    :return:
    """
    if self.cloud:
        url = "rest/api/content/{id}/version/{versionNumber}".format(id=content_id, versionNumber=version_number)
    else:
        url = "rest/experimental/content/{id}/version/{versionNumber}".format(
            id=content_id, versionNumber=version_number
        )
    return self.get(url)

get_content_template(template_id)

Get a content template.

This includes information about the template, like the name, the space or blueprint that the template is in, the body of the template, and more. :param str template_id: The ID of the content template to be returned :return:

Source code in server/vendor/atlassian/confluence.py
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
def get_content_template(self, template_id):
    """
    Get a content template.

    This includes information about the template, like the name, the space or blueprint
        that the template is in, the body of the template, and more.
    :param str template_id: The ID of the content template to be returned
    :return:
    """
    url = "rest/api/template/{template_id}".format(template_id=template_id)

    try:
        response = self.get(url)
    except HTTPError as e:
        if e.response.status_code == 403:
            # Raise ApiError as the documented reason is ambiguous
            raise ApiError(
                "There is no content with the given id, "
                "or the calling user does not have permission to view the content",
                reason=e,
            )

        raise

    return response

get_content_templates(space=None, start=0, limit=None, expand=None)

Get all content templates. Use this method to retrieve all global content templates or all content templates in a space. :param space: OPTIONAL: The key of the space to be queried for templates. If space is not specified, global templates will be returned. :param start: OPTIONAL: The start point of the collection to return. Default: None (0). :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by fixed system limits. Default: 25 :param expand: OPTIONAL: A multi-value parameter indicating which properties of the template to expand. e.g. body

Source code in server/vendor/atlassian/confluence.py
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
def get_content_templates(self, space=None, start=0, limit=None, expand=None):
    """
    Get all content templates.
    Use this method to retrieve all global content templates or all content templates in a space.
    :param space: OPTIONAL: The key of the space to be queried for templates. If ``space`` is not
        specified, global templates will be returned.
    :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
    :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
                        fixed system limits. Default: 25
    :param expand: OPTIONAL: A multi-value parameter indicating which properties of the template to expand.
        e.g. ``body``
    """
    url = "rest/api/template/page"
    params = {}
    if space:
        params["spaceKey"] = space
    if start:
        params["start"] = start
    if limit:
        params["limit"] = limit
    if expand:
        params["expand"] = expand

    try:
        response = self.get(url, params=params)
    except HTTPError as e:
        if e.response.status_code == 403:
            raise ApiPermissionError(
                "The calling user does not have permission to view the content",
                reason=e,
            )

        raise

    return response.get("results") or []

get_descendant_page_id(space, parent_id, title)

Provide space, parent_id and title of the descendant page, it will return the descendant page_id :param space: str :param parent_id: int :param title: str :return: page_id of the page whose title is passed in argument

Source code in server/vendor/atlassian/confluence.py
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
def get_descendant_page_id(self, space, parent_id, title):
    """
    Provide  space, parent_id and title of the descendant page, it will return the descendant page_id
    :param space: str
    :param parent_id: int
    :param title: str
    :return: page_id of the page whose title is passed in argument
    """
    page_id = ""

    url = 'rest/api/content/search?cql=parent={}%20AND%20space="{}"'.format(parent_id, space)

    try:
        response = self.get(url, {})
    except HTTPError as e:
        if e.response.status_code == 400:
            raise ApiValueError("The CQL is invalid or missing", reason=e)

        raise

    for each_page in response.get("results", []):
        if each_page.get("title") == title:
            page_id = each_page.get("id")
            break
    return page_id

get_draft_page_by_id(page_id, status='draft', expand=None)

Gets content by id with status = draft :param page_id: Content ID :param status: (str) list of content statuses to filter results on. Default value: [draft] :param expand: OPTIONAL: Default value: history,space,version We can also specify some extensions such as extensions.inlineProperties (for getting inline comment-specific properties) or extensions. Resolution for the resolution status of each comment in the results :return:

Source code in server/vendor/atlassian/confluence.py
509
510
511
512
513
514
515
516
517
518
519
520
521
522
def get_draft_page_by_id(self, page_id, status="draft", expand=None):
    """
    Gets content by id with status = draft
    :param page_id: Content ID
    :param status: (str) list of content statuses to filter results on. Default value: [draft]
    :param expand: OPTIONAL: Default value: history,space,version
                   We can also specify some extensions such as extensions.inlineProperties
                   (for getting inline comment-specific properties) or extensions. Resolution
                   for the resolution status of each comment in the results
    :return:
    """
    # Version not passed since draft versions don't match the page and
    # operate differently between different collaborative modes
    return self.get_page_by_id(page_id=page_id, expand=expand, status=status)

get_group_members(group_name='confluence-users', start=0, limit=1000, expand=None)

Get a paginated collection of users in the given group :param group_name :param start: OPTIONAL: The start point of the collection to return. Default: None (0). :param limit: OPTIONAL: The limit of the number of users to return, this may be restricted by fixed system limits. Default: 1000 :param expand: OPTIONAL: A comma separated list of properties to expand on the content. status :return:

Source code in server/vendor/atlassian/confluence.py
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
def get_group_members(self, group_name="confluence-users", start=0, limit=1000, expand=None):
    """
    Get a paginated collection of users in the given group
    :param group_name
    :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
    :param limit: OPTIONAL: The limit of the number of users to return, this may be restricted by
                        fixed system limits. Default: 1000
    :param expand: OPTIONAL: A comma separated list of properties to expand on the content. status
    :return:
    """
    url = "rest/api/group/{group_name}/member?limit={limit}&start={start}&expand={expand}".format(
        group_name=group_name, limit=limit, start=start, expand=expand
    )

    try:
        response = self.get(url)
    except HTTPError as e:
        if e.response.status_code == 403:
            raise ApiPermissionError(
                "The calling user does not have permission to view users",
                reason=e,
            )

        raise

    return response.get("results")

get_home_page_of_space(space_key)

Get information about a space through space key :param space_key: The unique space key name :return: Returns homepage

Source code in server/vendor/atlassian/confluence.py
2354
2355
2356
2357
2358
2359
2360
def get_home_page_of_space(self, space_key):
    """
    Get information about a space through space key
    :param space_key: The unique space key name
    :return: Returns homepage
    """
    return self.get_space(space_key, expand="homepage").get("homepage")

get_jira_metadata(page_id)

Get linked Jira ticket metadata PRIVATE method :param page_id: Page Id :return:

Source code in server/vendor/atlassian/confluence.py
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
def get_jira_metadata(self, page_id):
    """
    Get linked Jira ticket metadata
    PRIVATE method
    :param page_id: Page Id
    :return:
    """
    url = "rest/jira-metadata/1.0/metadata"
    params = {"pageId": page_id}
    return self.get(url, params=params)

get_jira_metadata_aggregated(page_id)

Get linked Jira ticket aggregated metadata PRIVATE method :param page_id: Page Id :return:

Source code in server/vendor/atlassian/confluence.py
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
def get_jira_metadata_aggregated(self, page_id):
    """
    Get linked Jira ticket aggregated metadata
    PRIVATE method
    :param page_id: Page Id
    :return:
    """
    url = "rest/jira-metadata/1.0/metadata/aggregate"
    params = {"pageId": page_id}
    return self.get(url, params=params)

get_license_details()

Returns the license detailed information

Source code in server/vendor/atlassian/confluence.py
3291
3292
3293
3294
3295
3296
def get_license_details(self):
    """
    Returns the license detailed information
    """
    url = "rest/license/1.0/license/details"
    return self.get(url)

get_license_max_users()

Returns the license max users

Source code in server/vendor/atlassian/confluence.py
3312
3313
3314
3315
3316
3317
def get_license_max_users(self):
    """
    Returns the license max users
    """
    url = "rest/license/1.0/license/maxUsers"
    return self.get(url)

get_license_remaining()

Returns the available license seats remaining

Source code in server/vendor/atlassian/confluence.py
3305
3306
3307
3308
3309
3310
def get_license_remaining(self):
    """
    Returns the available license seats remaining
    """
    url = "rest/license/1.0/license/remainingSeats"
    return self.get(url)

get_license_user_count()

Returns the total used seats in the license

Source code in server/vendor/atlassian/confluence.py
3298
3299
3300
3301
3302
3303
def get_license_user_count(self):
    """
    Returns the total used seats in the license
    """
    url = "rest/license/1.0/license/userCount"
    return self.get(url)

get_mobile_parameters(username)

Get mobile paramaters :param username: :return:

Source code in server/vendor/atlassian/confluence.py
2997
2998
2999
3000
3001
3002
3003
3004
def get_mobile_parameters(self, username):
    """
    Get mobile paramaters
    :param username:
    :return:
    """
    url = "rest/mobile/1.0/profile/{username}".format(username=username)
    return self.get(url)

get_page_ancestors(page_id)

Provide the ancestors from the page (content) id :param page_id: content_id format :return: get properties

Source code in server/vendor/atlassian/confluence.py
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
def get_page_ancestors(self, page_id):
    """
    Provide the ancestors from the page (content) id
    :param page_id: content_id format
    :return: get properties
    """
    url = "rest/api/content/{page_id}?expand=ancestors".format(page_id=page_id)

    try:
        response = self.get(path=url)
    except HTTPError as e:
        if e.response.status_code == 404:
            raise ApiPermissionError(
                "The calling user does not have permission to view the content",
                reason=e,
            )

        raise

    return response.get("ancestors")

get_page_as_pdf(page_id)

Export page as standard pdf exporter :param page_id: Page ID :return: PDF File

Source code in server/vendor/atlassian/confluence.py
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
def get_page_as_pdf(self, page_id):
    """
    Export page as standard pdf exporter
    :param page_id: Page ID
    :return: PDF File
    """
    headers = self.form_token_headers
    url = "spaces/flyingpdf/pdfpageexport.action?pageId={pageId}".format(pageId=page_id)
    if self.api_version == "cloud":
        url = self.get_pdf_download_url_for_confluence_cloud(url)
        if not url:
            log.error("Failed to get download PDF url.")
            raise ApiNotFoundError("Failed to export page as PDF", reason="Failed to get download PDF url.")
        # To download the PDF file, the request should be with no headers of authentications.
        return requests.get(url, timeout=75).content
    return self.get(url, headers=headers, not_json_response=True)

get_page_as_word(page_id)

Export page as standard word exporter. :param page_id: Page ID :return: Word File

Source code in server/vendor/atlassian/confluence.py
2574
2575
2576
2577
2578
2579
2580
2581
2582
def get_page_as_word(self, page_id):
    """
    Export page as standard word exporter.
    :param page_id: Page ID
    :return: Word File
    """
    headers = self.form_token_headers
    url = "exportword?pageId={pageId}".format(pageId=page_id)
    return self.get(url, headers=headers, not_json_response=True)

get_page_by_id(page_id, expand=None, status=None, version=None)

Returns a piece of Content. Example request URI(s): http://example.com/confluence/rest/api/content/1234?expand=space,body.view,version,container http://example.com/confluence/rest/api/content/1234?status=any :param page_id: Content ID :param status: (str) list of Content statuses to filter results on. Default value: [current] :param version: (int) :param expand: OPTIONAL: Default value: history,space,version We can also specify some extensions such as extensions.inlineProperties (for getting inline comment-specific properties) or extensions. Resolution for the resolution status of each comment in the results :return:

Source code in server/vendor/atlassian/confluence.py
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
def get_page_by_id(self, page_id, expand=None, status=None, version=None):
    """
    Returns a piece of Content.
    Example request URI(s):
    http://example.com/confluence/rest/api/content/1234?expand=space,body.view,version,container
    http://example.com/confluence/rest/api/content/1234?status=any
    :param page_id: Content ID
    :param status: (str) list of Content statuses to filter results on. Default value: [current]
    :param version: (int)
    :param expand: OPTIONAL: Default value: history,space,version
                   We can also specify some extensions such as extensions.inlineProperties
                   (for getting inline comment-specific properties) or extensions. Resolution
                   for the resolution status of each comment in the results
    :return:
    """
    params = {}
    if expand:
        params["expand"] = expand
    if status:
        params["status"] = status
    if version:
        params["version"] = version
    url = "rest/api/content/{page_id}".format(page_id=page_id)

    try:
        response = self.get(url, params=params)
    except HTTPError as e:
        if e.response.status_code == 404:
            # Raise ApiError as the documented reason is ambiguous
            raise ApiError(
                "There is no content with the given id, "
                "or the calling user does not have permission to view the content",
                reason=e,
            )

        raise

    return response

get_page_by_title(space, title, start=0, limit=1, expand=None, type='page')

Returns the first page on a piece of Content. :param space: Space key :param title: Title of the page :param start: OPTIONAL: The start point of the collection to return. Default: None (0). :param limit: OPTIONAL: The limit of the number of labels to return, this may be restricted by fixed system limits. Default: 1. :param expand: OPTIONAL: expand e.g. history :param type: OPTIONAL: Type of content: Page or Blogpost. Defaults to page :return: The JSON data returned from searched results the content endpoint, or the results of the callback. Will raise requests.HTTPError on bad input, potentially. If it has IndexError then return the None.

Source code in server/vendor/atlassian/confluence.py
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
def get_page_by_title(self, space, title, start=0, limit=1, expand=None, type="page"):
    """
    Returns the first page  on a piece of Content.
    :param space: Space key
    :param title: Title of the page
    :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
    :param limit: OPTIONAL: The limit of the number of labels to return, this may be restricted by
                        fixed system limits. Default: 1.
    :param expand: OPTIONAL: expand e.g. history
    :param type: OPTIONAL: Type of content: Page or Blogpost. Defaults to page
    :return: The JSON data returned from searched results the content endpoint, or the results of the
             callback. Will raise requests.HTTPError on bad input, potentially.
             If it has IndexError then return the None.
    """
    url = "rest/api/content"
    params = {"type": type}
    if start is not None:
        params["start"] = int(start)
    if limit is not None:
        params["limit"] = int(limit)
    if expand is not None:
        params["expand"] = expand
    if space is not None:
        params["spaceKey"] = str(space)
    if title is not None:
        params["title"] = str(title)

    if self.advanced_mode:
        return self.get(url, params=params)
    try:
        response = self.get(url, params=params)
    except HTTPError as e:
        if e.response.status_code == 404:
            raise ApiPermissionError(
                "The calling user does not have permission to view the content",
                reason=e,
            )

        raise
    try:
        return response.get("results")[0]
    except (IndexError, TypeError) as e:
        log.error("Can't find '%s' page on the %s!", title, self.url)
        log.debug(e)
        return None

get_page_child_by_type(page_id, type='page', start=None, limit=None, expand=None)

Provide content by type (page, blog, comment) :param page_id: A string containing the id of the type content container. :param type: :param start: OPTIONAL: The start point of the collection to return. Default: None (0). :param limit: OPTIONAL: how many items should be returned after the start index. Default: Site limit 200. :param expand: OPTIONAL: expand e.g. history :return:

Source code in server/vendor/atlassian/confluence.py
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
def get_page_child_by_type(self, page_id, type="page", start=None, limit=None, expand=None):
    """
    Provide content by type (page, blog, comment)
    :param page_id: A string containing the id of the type content container.
    :param type:
    :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
    :param limit: OPTIONAL: how many items should be returned after the start index. Default: Site limit 200.
    :param expand: OPTIONAL: expand e.g. history
    :return:
    """
    params = {}
    if start is not None:
        params["start"] = int(start)
    if limit is not None:
        params["limit"] = int(limit)
    if expand is not None:
        params["expand"] = expand

    url = "rest/api/content/{page_id}/child/{type}".format(page_id=page_id, type=type)
    log.info(url)

    try:
        if not self.advanced_mode and start is None and limit is None:
            return self._get_paged(url, params=params)
        else:
            response = self.get(url, params=params)
            if self.advanced_mode:
                return response
            return response.get("results")
    except HTTPError as e:
        if e.response.status_code == 404:
            # Raise ApiError as the documented reason is ambiguous
            raise ApiError(
                "There is no content with the given id, "
                "or the calling user does not have permission to view the content",
                reason=e,
            )

        raise

get_page_comments(content_id, expand=None, parent_version=None, start=0, limit=25, location=None, depth=None)

:param content_id: :param expand: extensions.inlineProperties,extensions.resolution :param parent_version: :param start: :param limit: :param location: inline or not :param depth: :return:

Source code in server/vendor/atlassian/confluence.py
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
def get_page_comments(
    self,
    content_id,
    expand=None,
    parent_version=None,
    start=0,
    limit=25,
    location=None,
    depth=None,
):
    """

    :param content_id:
    :param expand: extensions.inlineProperties,extensions.resolution
    :param parent_version:
    :param start:
    :param limit:
    :param location: inline or not
    :param depth:
    :return:
    """
    params = {"id": content_id, "start": start, "limit": limit}
    if expand:
        params["expand"] = expand
    if parent_version:
        params["parentVersion"] = parent_version
    if location:
        params["location"] = location
    if depth:
        params["depth"] = depth
    url = "rest/api/content/{id}/child/comment".format(id=content_id)

    try:
        response = self.get(url, params=params)
    except HTTPError as e:
        if e.response.status_code == 404:
            # Raise ApiError as the documented reason is ambiguous
            raise ApiError(
                "There is no content with the given id, "
                "or the calling user does not have permission to view the content",
                reason=e,
            )

        raise

    return response

get_page_id(space, title, type='page')

Provide content id from search result by title and space. :param space: SPACE key :param title: title :param type: type of content: Page or Blogpost. Defaults to page :return:

Source code in server/vendor/atlassian/confluence.py
212
213
214
215
216
217
218
219
220
def get_page_id(self, space, title, type="page"):
    """
    Provide content id from search result by title and space.
    :param space: SPACE key
    :param title: title
    :param type: type of content: Page or Blogpost. Defaults to page
    :return:
    """
    return (self.get_page_by_title(space, title, type=type) or {}).get("id")

get_page_labels(page_id, prefix=None, start=None, limit=None)

Returns the list of labels on a piece of Content. :param page_id: A string containing the id of the labels content container. :param prefix: OPTIONAL: The prefixes to filter the labels with {@see Label.Prefix}. Default: None. :param start: OPTIONAL: The start point of the collection to return. Default: None (0). :param limit: OPTIONAL: The limit of the number of labels to return, this may be restricted by fixed system limits. Default: 200. :return: The JSON data returned from the content/{id}/label endpoint, or the results of the callback. Will raise requests.HTTPError on bad input, potentially.

Source code in server/vendor/atlassian/confluence.py
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
def get_page_labels(self, page_id, prefix=None, start=None, limit=None):
    """
    Returns the list of labels on a piece of Content.
    :param page_id: A string containing the id of the labels content container.
    :param prefix: OPTIONAL: The prefixes to filter the labels with {@see Label.Prefix}.
                            Default: None.
    :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
    :param limit: OPTIONAL: The limit of the number of labels to return, this may be restricted by
                        fixed system limits. Default: 200.
    :return: The JSON data returned from the content/{id}/label endpoint, or the results of the
             callback. Will raise requests.HTTPError on bad input, potentially.
    """
    url = "rest/api/content/{id}/label".format(id=page_id)
    params = {}
    if prefix:
        params["prefix"] = prefix
    if start is not None:
        params["start"] = int(start)
    if limit is not None:
        params["limit"] = int(limit)

    try:
        response = self.get(url, params=params)
    except HTTPError as e:
        if e.response.status_code == 404:
            # Raise ApiError as the documented reason is ambiguous
            raise ApiError(
                "There is no content with the given id, "
                "or the calling user does not have permission to view the content",
                reason=e,
            )

        raise

    return response

get_page_properties(page_id)

Get the page (content) properties :param page_id: content_id format :return: get properties

Source code in server/vendor/atlassian/confluence.py
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
def get_page_properties(self, page_id):
    """
    Get the page (content) properties
    :param page_id: content_id format
    :return: get properties
    """
    url = "rest/api/content/{page_id}/property".format(page_id=page_id)

    try:
        response = self.get(path=url)
    except HTTPError as e:
        if e.response.status_code == 404:
            # Raise ApiError as the documented reason is ambiguous
            raise ApiError(
                "There is no content with the given id, "
                "or the calling user does not have permission to view the content",
                reason=e,
            )

        raise

    return response

get_page_property(page_id, page_property_key)

Get the page (content) property e.g. get key of hash :param page_id: content_id format :param page_property_key: key of property :return:

Source code in server/vendor/atlassian/confluence.py
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
def get_page_property(self, page_id, page_property_key):
    """
    Get the page (content) property e.g. get key of hash
    :param page_id: content_id format
    :param page_property_key: key of property
    :return:
    """
    url = "rest/api/content/{page_id}/property/{key}".format(page_id=page_id, key=str(page_property_key))
    try:
        response = self.get(path=url)
    except HTTPError as e:
        if e.response.status_code == 404:
            # Raise ApiError as the documented reason is ambiguous
            raise ApiError(
                "There is no content with the given id, or no property with the "
                "given key, or the calling user does not have permission to view "
                "the content",
                reason=e,
            )

        raise

    return response

get_page_space(page_id)

Provide space key from content id. :param page_id: content ID :return:

Source code in server/vendor/atlassian/confluence.py
252
253
254
255
256
257
258
def get_page_space(self, page_id):
    """
    Provide space key from content id.
    :param page_id: content ID
    :return:
    """
    return ((self.get_page_by_id(page_id, expand="space") or {}).get("space") or {}).get("key") or None

get_pages_by_title(space, title, start=0, limit=200, expand=None)

Provide pages by title search :param space: Space key :param title: Title of the page :param start: OPTIONAL: The start point of the collection to return. Default: None (0). :param limit: OPTIONAL: The limit of the number of labels to return, this may be restricted by fixed system limits. Default: 200. :param expand: OPTIONAL: expand e.g. history :return: The JSON data returned from searched results the content endpoint, or the results of the callback. Will raise requests.HTTPError on bad input, potentially. If it has IndexError then return the None.

Source code in server/vendor/atlassian/confluence.py
260
261
262
263
264
265
266
267
268
269
270
271
272
273
def get_pages_by_title(self, space, title, start=0, limit=200, expand=None):
    """
    Provide pages by title search
    :param space: Space key
    :param title: Title of the page
    :param start: OPTIONAL: The start point of the collection to return. Default: None (0).
    :param limit: OPTIONAL: The limit of the number of labels to return, this may be restricted by
                        fixed system limits. Default: 200.
    :param expand: OPTIONAL: expand e.g. history
    :return: The JSON data returned from searched results the content endpoint, or the results of the
             callback. Will raise requests.HTTPError on bad input, potentially.
             If it has IndexError then return the None.
    """
    return self.get_page_by_title(space, title, start, limit, expand)

get_parent_content_id(page_id)

Provide parent content id from page id :type page_id: str :return:

Source code in server/vendor/atlassian/confluence.py
222
223
224
225
226
227
228
229
230
231
232
233
234
235
def get_parent_content_id(self, page_id):
    """
    Provide parent content id from page id
    :type page_id: str
    :return:
    """
    parent_content_id = None
    try:
        parent_content_id = (self.get_page_by_id(page_id=page_id, expand="ancestors").get("ancestors") or {})[
            -1
        ].get("id") or None
    except Exception as e:
        log.error(e)
    return parent_content_id

get_parent_content_title(page_id)

Provide parent content title from page id :type page_id: str :return:

Source code in server/vendor/atlassian/confluence.py
237
238
239
240
241
242
243
244
245
246
247
248
249
250
def get_parent_content_title(self, page_id):
    """
    Provide parent content title from page id
    :type page_id: str
    :return:
    """
    parent_content_title = None
    try:
        parent_content_title = (self.get_page_by_id(page_id=page_id, expand="ancestors").get("ancestors") or {})[
            -1
        ].get("title") or None
    except Exception as e:
        log.error(e)
    return parent_content_title

get_pdf_download_url_for_confluence_cloud(url)

Confluence cloud does not return the PDF document when the PDF export is initiated. Instead, it starts a process in the background and provides a link to download the PDF once the process completes. This functions polls the long-running task page and returns the download url of the PDF. :param url: URL to initiate PDF export :return: Download url for PDF file

Source code in server/vendor/atlassian/confluence.py
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
def get_pdf_download_url_for_confluence_cloud(self, url):
    """
    Confluence cloud does not return the PDF document when the PDF
    export is initiated. Instead, it starts a process in the background
    and provides a link to download the PDF once the process completes.
    This functions polls the long-running task page and returns the
    download url of the PDF.
    :param url: URL to initiate PDF export
    :return: Download url for PDF file
    """
    try:
        running_task = True
        headers = self.form_token_headers
        log.info("Initiate PDF export from Confluence Cloud")
        response = self.get(url, headers=headers, not_json_response=True)
        response_string = response.decode(encoding="utf-8", errors="ignore")
        task_id = response_string.split('name="ajs-taskId" content="')[1].split('">')[0]
        poll_url = "/services/api/v1/task/{0}/progress".format(task_id)
        while running_task:
            log.info("Check if export task has completed.")
            progress_response = self.get(poll_url)
            percentage_complete = int(progress_response.get("progress", 0))
            task_state = progress_response.get("state")
            if task_state == "FAILED":
                log.error("PDF conversion not successful.")
                return None
            elif percentage_complete == 100:
                running_task = False
                log.info("Task completed - {task_state}".format(task_state=task_state))
                log.debug("Extract task results to download PDF.")
                task_result_url = progress_response.get("result")
            else:
                log.info(
                    "{percentage_complete}% - {task_state}".format(
                        percentage_complete=percentage_complete, task_state=task_state
                    )
                )
                time.sleep(3)
        log.debug("Task successfully done, querying the task result for the download url")
        # task result url starts with /wiki, remove it.
        task_content = self.get(task_result_url[5:], not_json_response=True)
        download_url = task_content.decode(encoding="utf-8", errors="strict")
        log.debug("Successfully got the download url")
        return download_url
    except IndexError as e:
        log.error(e)
        return None

get_plugin_info(plugin_key)

Provide plugin info :return a json of installed plugins

Source code in server/vendor/atlassian/confluence.py
2694
2695
2696
2697
2698
2699
2700
def get_plugin_info(self, plugin_key):
    """
    Provide plugin info
    :return a json of installed plugins
    """
    url = "rest/plugins/1.0/{plugin_key}-key".format(plugin_key=plugin_key)
    return self.get(url, headers=self.no_check_headers, trailing=True)

get_plugin_license_info(plugin_key)

Provide plugin license info :return a json specific License query

Source code in server/vendor/atlassian/confluence.py
2702
2703
2704
2705
2706
2707
2708
def get_plugin_license_info(self, plugin_key):
    """
    Provide plugin license info
    :return a json specific License query
    """
    url = "rest/plugins/1.0/{plugin_key}-key/license".format(plugin_key=plugin_key)
    return self.get(url, headers=self.no_check_headers, trailing=True)

get_plugins_info()

Provide plugins info :return a json of installed plugins

Source code in server/vendor/atlassian/confluence.py
2686
2687
2688
2689
2690
2691
2692
def get_plugins_info(self):
    """
    Provide plugins info
    :return a json of installed plugins
    """
    url = "rest/plugins/1.0/"
    return self.get(url, headers=self.no_check_headers, trailing=True)

get_space(space_key, expand='description.plain,homepage', params=None)

Get information about a space through space key :param space_key: The unique space key name :param expand: OPTIONAL: additional info from description, homepage :param params: OPTIONAL: dictionary of additional URL parameters :return: Returns the space along with its ID

Source code in server/vendor/atlassian/confluence.py
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
def get_space(self, space_key, expand="description.plain,homepage", params=None):
    """
    Get information about a space through space key
    :param space_key: The unique space key name
    :param expand: OPTIONAL: additional info from description, homepage
    :param params: OPTIONAL: dictionary of additional URL parameters
    :return: Returns the space along with its ID
    """
    url = "rest/api/space/{space_key}".format(space_key=space_key)
    params = params or {}
    if expand:
        params["expand"] = expand
    try:
        response = self.get(url, params=params)
    except HTTPError as e:
        if e.response.status_code == 404:
            # Raise ApiError as the documented reason is ambiguous
            raise ApiError(
                "There is no space with the given key, "
                "or the calling user does not have permission to view the space",
                reason=e,
            )
        raise
    return response

get_space_content(space_key, depth='all', start=0, limit=500, content_type=None, expand='body.storage')

Get space content. You can specify which type of content want to receive, or get all content types. Use expand to get specific content properties or page :param content_type: :param space_key: The unique space key name :param depth: OPTIONAL: all|root Gets all space pages or only root pages :param start: OPTIONAL: The start point of the collection to return. Default: 0. :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by fixed system limits. Default: 500 :param expand: OPTIONAL: by default expands page body in confluence storage format. See atlassian documentation for more information. :return: Returns the space along with its ID

Source code in server/vendor/atlassian/confluence.py
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
def get_space_content(
    self,
    space_key,
    depth="all",
    start=0,
    limit=500,
    content_type=None,
    expand="body.storage",
):
    """
    Get space content.
    You can specify which type of content want to receive, or get all content types.
    Use expand to get specific content properties or page
    :param content_type:
    :param space_key: The unique space key name
    :param depth: OPTIONAL: all|root
                            Gets all space pages or only root pages
    :param start: OPTIONAL: The start point of the collection to return. Default: 0.
    :param limit: OPTIONAL: The limit of the number of pages to return, this may be restricted by
                            fixed system limits. Default: 500
    :param expand: OPTIONAL: by default expands page body in confluence storage format.
                             See atlassian documentation for more information.
    :return: Returns the space along with its ID
    """

    content_type = "{}".format("/" + content_type if content_type else "")
    url = "rest/api/space/{space_key}/content{content_type}".format(space_key=space_key, content_type=content_type)
    params = {
        "depth": depth,
        "start": start,
        "limit": limit,
    }
    if expand:
        params["expand"] = expand
    try:
        response = self.get(url, params=params)
    except HTTPError as e:
        if e.response.status_code == 404:
            # Raise ApiError as the documented reason is ambiguous
            raise ApiError(
                "There is no space with the given key, "
                "or the calling user does not have permission to view the space",
                reason=e,
            )
        raise
    return response

get_space_permissions(space_key)

The JSON-RPC APIs for Confluence are provided here to help you browse and discover APIs you have access to. JSON-RPC APIs operate differently than REST APIs. To learn more about how to use these APIs, please refer to the Confluence JSON-RPC documentation on Atlassian Developers.

Source code in server/vendor/atlassian/confluence.py
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
def get_space_permissions(self, space_key):
    """
    The JSON-RPC APIs for Confluence are provided here to help you browse and discover APIs you have access to.
    JSON-RPC APIs operate differently than REST APIs.
    To learn more about how to use these APIs,
    please refer to the Confluence JSON-RPC documentation on Atlassian Developers.
    """
    if self.api_version == "cloud":
        return self.get_space(space_key=space_key, expand="permissions")
    url = "rpc/json-rpc/confluenceservice-v2"
    data = {
        "jsonrpc": "2.0",
        "method": "getSpacePermissionSets",
        "id": 7,
        "params": [space_key],
    }
    return self.post(url, data=data).get("result") or {}

get_subtree_of_content_ids(page_id)

Get subtree of page ids :param page_id: :return: Set of page ID

Source code in server/vendor/atlassian/confluence.py
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
def get_subtree_of_content_ids(self, page_id):
    """
    Get subtree of page ids
    :param page_id:
    :return: Set of page ID
    """
    output = list()
    output.append(page_id)
    children_pages = self.get_page_child_by_type(page_id)
    for page in children_pages:
        child_subtree = self.get_subtree_of_content_ids(page.get("id"))
        if child_subtree:
            output.extend([p for p in child_subtree])
    return set(output)

get_tables_from_page(page_id)

Fetches html tables added to confluence page :param page_id: integer confluence page_id :return: json object with page_id, number_of_tables_in_page and list of list tables_content representing scrapepd tables

Source code in server/vendor/atlassian/confluence.py
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
def get_tables_from_page(self, page_id):
    """
    Fetches html  tables added to  confluence page
    :param page_id: integer confluence page_id
    :return: json object with page_id, number_of_tables_in_page  and  list of list tables_content representing scrapepd tables
    """
    try:
        page_content = self.get_page_by_id(page_id, expand="body.storage")["body"]["storage"]["value"]

        if page_content:
            tables_raw = [
                [[cell.text for cell in row("th") + row("td")] for row in table("tr")]
                for table in BeautifulSoup(page_content, features="lxml")("table")
            ]
            if len(tables_raw) > 0:
                return json.dumps(
                    {
                        "page_id": page_id,
                        "number_of_tables_in_page": len(tables_raw),
                        "tables_content": tables_raw,
                    }
                )
            else:
                return {
                    "No tables found for page: ": page_id,
                }
        else:
            return {"Page content is empty"}
    except HTTPError as e:
        if e.response.status_code == 404:
            # Raise ApiError as the documented reason is ambiguous
            log.error("Couldn't retrieve tables  from page", page_id)
            raise ApiError(
                "There is no content with the given pageid, pageid params is not an integer "
                "or the calling user does not have permission to view the page",
                reason=e,
            )
    except Exception as e:
        log.error("Error occured", e)

get_template_by_id(template_id)

Get user template by id. Experimental API Use case is get template body and create page from that

Source code in server/vendor/atlassian/confluence.py
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
@deprecated(version="3.7.0", reason="Use get_content_template()")
def get_template_by_id(self, template_id):
    """
    Get user template by id. Experimental API
    Use case is get template body and create page from that
    """
    url = "rest/experimental/template/{template_id}".format(template_id=template_id)

    try:
        response = self.get(url)
    except HTTPError as e:
        if e.response.status_code == 403:
            # Raise ApiError as the documented reason is ambiguous
            raise ApiError(
                "There is no content with the given id, "
                "or the calling user does not have permission to view the content",
                reason=e,
            )

        raise
    return response

get_user_details_by_accountid(accountid, expand=None)

Get information about a user through accountid :param accountid: The account id :param expand: OPTIONAL expand for get status of user. Possible param is "status". Results are "Active, Deactivated" :return: Returns the user details

Source code in server/vendor/atlassian/confluence.py
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
def get_user_details_by_accountid(self, accountid, expand=None):
    """
    Get information about a user through accountid
    :param accountid: The account id
    :param expand: OPTIONAL expand for get status of user.
            Possible param is "status". Results are "Active, Deactivated"
    :return: Returns the user details
    """
    url = "rest/api/user"
    params = {"accountId": accountid}
    if expand:
        params["expand"] = expand

    try:
        response = self.get(url, params=params)
    except HTTPError as e:
        if e.response.status_code == 403:
            raise ApiPermissionError(
                "The calling user does not have permission to view users",
                reason=e,
            )
        if e.response.status_code == 404:
            raise ApiNotFoundError(
                "The user with the given account does not exist",
                reason=e,
            )

        raise

    return response

get_user_details_by_userkey(userkey, expand=None)

Get information about a user through user key :param userkey: The user key :param expand: OPTIONAL expand for get status of user. Possible param is "status". Results are "Active, Deactivated" :return: Returns the user details

Source code in server/vendor/atlassian/confluence.py
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
def get_user_details_by_userkey(self, userkey, expand=None):
    """
    Get information about a user through user key
    :param userkey: The user key
    :param expand: OPTIONAL expand for get status of user.
            Possible param is "status". Results are "Active, Deactivated"
    :return: Returns the user details
    """
    url = "rest/api/user"
    params = {"key": userkey}
    if expand:
        params["expand"] = expand

    try:
        response = self.get(url, params=params)
    except HTTPError as e:
        if e.response.status_code == 403:
            raise ApiPermissionError(
                "The calling user does not have permission to view users",
                reason=e,
            )
        if e.response.status_code == 404:
            raise ApiNotFoundError(
                "The user with the given username or userkey does not exist",
                reason=e,
            )

        raise

    return response

get_user_details_by_username(username, expand=None)

Get information about a user through username :param username: The username :param expand: OPTIONAL expand for get status of user. Possible param is "status". Results are "Active, Deactivated" :return: Returns the user details

Source code in server/vendor/atlassian/confluence.py
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
def get_user_details_by_username(self, username, expand=None):
    """
    Get information about a user through username
    :param username: The username
    :param expand: OPTIONAL expand for get status of user.
            Possible param is "status". Results are "Active, Deactivated"
    :return: Returns the user details
    """
    url = "rest/api/user"
    params = {"username": username}
    if expand:
        params["expand"] = expand

    try:
        response = self.get(url, params=params)
    except HTTPError as e:
        if e.response.status_code == 403:
            raise ApiPermissionError(
                "The calling user does not have permission to view users",
                reason=e,
            )
        if e.response.status_code == 404:
            raise ApiNotFoundError(
                "The user with the given username or userkey does not exist",
                reason=e,
            )

        raise

    return response

has_unknown_attachment_error(page_id)

Check has unknown attachment error on page :param page_id: :return:

Source code in server/vendor/atlassian/confluence.py
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
def has_unknown_attachment_error(self, page_id):
    """
    Check has unknown attachment error on page
    :param page_id:
    :return:
    """
    unknown_attachment_identifier = "plugins/servlet/confluence/placeholder/unknown-attachment"
    result = self.get_page_by_id(page_id, expand="body.view")
    if len(result) == 0:
        return ""
    body = ((result.get("body") or {}).get("view") or {}).get("value") or {}
    if unknown_attachment_identifier in body:
        return result.get("_links").get("base") + result.get("_links").get("tinyui")
    return ""

health_check()

Get health status https://confluence.atlassian.com/jirakb/how-to-retrieve-health-check-results-using-rest-api-867195158.html :return:

Source code in server/vendor/atlassian/confluence.py
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
def health_check(self):
    """
    Get health status
    https://confluence.atlassian.com/jirakb/how-to-retrieve-health-check-results-using-rest-api-867195158.html
    :return:
    """
    # check as Troubleshooting & Support Tools Plugin
    response = self.get("rest/troubleshooting/1.0/check/")
    if not response:
        # check as support tools
        response = self.get("rest/supportHealthCheck/1.0/check/")
    return response

is_page_content_is_already_updated(page_id, body, title=None)

Compare content and check is already updated or not :param page_id: Content ID for retrieve storage value :param body: Body for compare it :param title: Title to compare :return: True if the same

Source code in server/vendor/atlassian/confluence.py
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
def is_page_content_is_already_updated(self, page_id, body, title=None):
    """
    Compare content and check is already updated or not
    :param page_id: Content ID for retrieve storage value
    :param body: Body for compare it
    :param title: Title to compare
    :return: True if the same
    """
    confluence_content = self.get_page_by_id(page_id)
    if title:
        current_title = confluence_content.get("title", None)
        if title != current_title:
            log.info("Title of %s is different", page_id)
            return False

    if self.advanced_mode:
        confluence_content = (
            (self.get_page_by_id(page_id, expand="body.storage").json() or {}).get("body") or {}
        ).get("storage") or {}
    else:
        confluence_content = ((self.get_page_by_id(page_id, expand="body.storage") or {}).get("body") or {}).get(
            "storage"
        ) or {}

    confluence_body_content = confluence_content.get("value")

    if confluence_body_content:
        # @todo move into utils
        confluence_body_content = utils.symbol_normalizer(confluence_body_content)

    log.debug('Old Content: """%s"""', confluence_body_content)
    log.debug('New Content: """%s"""', body)

    if confluence_body_content.strip() == body.strip():
        log.info("Content of %s is exactly the same", page_id)
        return True
    else:
        log.info("Content of %s differs", page_id)
        return False

move_page(space_key, page_id, target_id=None, target_title=None, position='append')

Move page method :param space_key: :param page_id: :param target_title: :param target_id: :param position: topLevel or append , above, below :return:

Source code in server/vendor/atlassian/confluence.py
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
def move_page(
    self,
    space_key,
    page_id,
    target_id=None,
    target_title=None,
    position="append",
):
    """
    Move page method
    :param space_key:
    :param page_id:
    :param target_title:
    :param target_id:
    :param position: topLevel or append , above, below
    :return:
    """
    url = "/pages/movepage.action"
    params = {"spaceKey": space_key, "pageId": page_id}
    if target_title:
        params["targetTitle"] = target_title
    if target_id:
        params["targetId"] = target_id
    if position:
        params["position"] = position
    return self.post(url, params=params, headers=self.no_check_headers)

page_exists(space, title, type=None)

Check if title exists as page. :param space: Space key :param title: Title of the page :param type: type of the page, 'page' or 'blogpost'. Defaults to 'page' :return:

Source code in server/vendor/atlassian/confluence.py
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
def page_exists(self, space, title, type=None):
    """
    Check if title exists as page.
    :param space: Space key
    :param title: Title of the page
    :param type: type of the page, 'page' or 'blogpost'. Defaults to 'page'
    :return:
    """
    url = "rest/api/content"
    params = {}
    if space is not None:
        params["spaceKey"] = str(space)
    if title is not None:
        params["title"] = str(title)
    if type is not None:
        params["type"] = str(type)

    try:
        response = self.get(url, params=params)
    except HTTPError as e:
        if e.response.status_code == 404:
            raise ApiPermissionError(
                "The calling user does not have permission to view the content",
                reason=e,
            )

        raise

    if response.get("results"):
        return True
    else:
        return False

prepend_page(page_id, title, prepend_body, parent_id=None, type='page', representation='storage', minor_edit=False)

Append body to page if already exist :param parent_id: :param page_id: :param title: :param prepend_body: :param type: :param representation: OPTIONAL: either Confluence 'storage' or 'wiki' markup format :param minor_edit: Indicates whether to notify watchers about changes. If False then notifications will be sent. :return:

Source code in server/vendor/atlassian/confluence.py
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
def prepend_page(
    self,
    page_id,
    title,
    prepend_body,
    parent_id=None,
    type="page",
    representation="storage",
    minor_edit=False,
):
    """
    Append body to page if already exist
    :param parent_id:
    :param page_id:
    :param title:
    :param prepend_body:
    :param type:
    :param representation: OPTIONAL: either Confluence 'storage' or 'wiki' markup format
    :param minor_edit: Indicates whether to notify watchers about changes.
        If False then notifications will be sent.
    :return:
    """
    log.info('Updating %s "%s"', type, title)

    return self._insert_to_existing_page(
        page_id,
        title,
        prepend_body,
        parent_id=parent_id,
        type=type,
        representation=representation,
        minor_edit=minor_edit,
        top_of_page=True,
    )

raise_for_status(response)

Checks the response for an error status and raises an exception with the error message provided by the server :param response: :return:

Source code in server/vendor/atlassian/confluence.py
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
def raise_for_status(self, response):
    """
    Checks the response for an error status and raises an exception with the error message provided by the server
    :param response:
    :return:
    """
    if response.status_code == 401 and response.headers.get("Content-Type") != "application/json;charset=UTF-8":
        raise HTTPError("Unauthorized (401)", response=response)

    if 400 <= response.status_code < 600:
        try:
            j = response.json()
            error_msg = j["message"]
        except Exception as e:
            log.error(e)
            response.raise_for_status()
        else:
            raise HTTPError(error_msg, response=response)

reindex()

It is not public method for reindex Confluence :return:

Source code in server/vendor/atlassian/confluence.py
2618
2619
2620
2621
2622
2623
2624
def reindex(self):
    """
    It is not public method for reindex Confluence
    :return:
    """
    url = "rest/prototype/1/index/reindex"
    return self.post(url)

reindex_get_status()

Get reindex status of Confluence :return:

Source code in server/vendor/atlassian/confluence.py
2626
2627
2628
2629
2630
2631
2632
def reindex_get_status(self):
    """
    Get reindex status of Confluence
    :return:
    """
    url = "rest/prototype/1/index/reindex"
    return self.get(url)

remove_content(content_id)

Remove any content :param content_id: :return:

Source code in server/vendor/atlassian/confluence.py
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
def remove_content(self, content_id):
    """
    Remove any content
    :param content_id:
    :return:
    """
    try:
        response = self.delete("rest/api/content/{}".format(content_id))
    except HTTPError as e:
        if e.response.status_code == 404:
            # Raise ApiError as the documented reason is ambiguous
            raise ApiError(
                "There is no content with the given id, or the calling "
                "user does not have permission to trash or purge the content",
                reason=e,
            )
        if e.response.status_code == 409:
            raise ApiConflictError(
                "There is a stale data object conflict when trying to delete a draft",
                reason=e,
            )

        raise

    return response

remove_content_history(page_id, version_number)

Remove content history. It works as experimental method :param page_id: :param version_number: version number :return:

Source code in server/vendor/atlassian/confluence.py
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
def remove_content_history(self, page_id, version_number):
    """
    Remove content history. It works as experimental method
    :param page_id:
    :param version_number: version number
    :return:
    """
    if self.cloud:
        url = "rest/api/content/{id}/version/{versionNumber}".format(id=page_id, versionNumber=version_number)
    else:
        url = "rest/experimental/content/{id}/version/{versionNumber}".format(
            id=page_id, versionNumber=version_number
        )
    self.delete(url)

remove_content_history_in_cloud(page_id, version_id)

Remove content history. It works in CLOUD :param page_id: :param version_id: :return:

Source code in server/vendor/atlassian/confluence.py
1581
1582
1583
1584
1585
1586
1587
1588
1589
def remove_content_history_in_cloud(self, page_id, version_id):
    """
    Remove content history. It works in CLOUD
    :param page_id:
    :param version_id:
    :return:
    """
    url = "rest/api/content/{id}/version/{versionId}".format(id=page_id, versionId=version_id)
    self.delete(url)

remove_group(name)

Delete a group by given group parameter If you delete a group and content is restricted to that group, the content will be hidden from all users

:param name: str :return:

Source code in server/vendor/atlassian/confluence.py
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
def remove_group(self, name):
    """
    Delete a group by given group parameter
    If you delete a group and content is restricted to that group, the content will be hidden from all users

    :param name: str
    :return:
    """
    log.warning("Removing group...")
    url = "rest/api/admin/group/{groupName}".format(groupName=name)

    try:
        response = self.delete(url)
    except HTTPError as e:
        if e.response.status_code == 404:
            # Raise ApiError as the documented reason is ambiguous
            raise ApiError(
                "There is no group with the given name, "
                "or the calling user does not have permission to delete it",
                reason=e,
            )
        raise

    return response

remove_page(page_id, status=None, recursive=False)

This method removes a page, if it has recursive flag, method removes including child pages :param page_id: :param status: OPTIONAL: type of page :param recursive: OPTIONAL: if True - will recursively delete all children pages too :return:

Source code in server/vendor/atlassian/confluence.py
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
def remove_page(self, page_id, status=None, recursive=False):
    """
    This method removes a page, if it has recursive flag, method removes including child pages
    :param page_id:
    :param status: OPTIONAL: type of page
    :param recursive: OPTIONAL: if True - will recursively delete all children pages too
    :return:
    """
    url = "rest/api/content/{page_id}".format(page_id=page_id)
    if recursive:
        children_pages = self.get_page_child_by_type(page_id)
        for children_page in children_pages:
            self.remove_page(children_page.get("id"), status, recursive)
    params = {}
    if status:
        params["status"] = status

    try:
        response = self.delete(url, params=params)
    except HTTPError as e:
        if e.response.status_code == 404:
            # Raise ApiError as the documented reason is ambiguous
            raise ApiError(
                "There is no content with the given id, or the calling "
                "user does not have permission to trash or purge the content",
                reason=e,
            )
        if e.response.status_code == 409:
            raise ApiConflictError(
                "There is a stale data object conflict when trying to delete a draft",
                reason=e,
            )

        raise

    return response

remove_page_as_draft(page_id)

This method removes a page from trash if it is a draft :param page_id: :return:

Source code in server/vendor/atlassian/confluence.py
714
715
716
717
718
719
720
def remove_page_as_draft(self, page_id):
    """
    This method removes a page from trash if it is a draft
    :param page_id:
    :return:
    """
    return self.remove_page(page_id=page_id, status="draft")

remove_page_attachment_keep_version(page_id, filename, keep_last_versions)

Keep last versions :param filename: :param page_id: :param keep_last_versions: :return:

Source code in server/vendor/atlassian/confluence.py
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
def remove_page_attachment_keep_version(self, page_id, filename, keep_last_versions):
    """
    Keep last versions
    :param filename:
    :param page_id:
    :param keep_last_versions:
    :return:
    """
    attachment = self.get_attachments_from_content(page_id=page_id, expand="version", filename=filename).get(
        "results"
    )[0]
    attachment_versions = self.get_attachment_history(attachment.get("id"))
    while len(attachment_versions) > keep_last_versions:
        remove_version_attachment_number = attachment_versions[keep_last_versions].get("number")
        self.delete_attachment_by_id(
            attachment_id=attachment.get("id"),
            version=remove_version_attachment_number,
        )
        log.info(
            "Removed oldest version for %s, now versions equal more than %s",
            attachment.get("title"),
            len(attachment_versions),
        )
        attachment_versions = self.get_attachment_history(attachment.get("id"))
    log.info("Kept versions %s for %s", keep_last_versions, attachment.get("title"))

remove_page_from_trash(page_id)

This method removes a page from trash :param page_id: :return:

Source code in server/vendor/atlassian/confluence.py
706
707
708
709
710
711
712
def remove_page_from_trash(self, page_id):
    """
    This method removes a page from trash
    :param page_id:
    :return:
    """
    return self.remove_page(page_id=page_id, status="trashed")

remove_page_history(page_id, version_number)

Remove content history. It works as experimental method :param page_id: :param version_number: version number :return:

Source code in server/vendor/atlassian/confluence.py
1572
1573
1574
1575
1576
1577
1578
1579
def remove_page_history(self, page_id, version_number):
    """
    Remove content history. It works as experimental method
    :param page_id:
    :param version_number: version number
    :return:
    """
    self.remove_content_history(page_id, version_number)

remove_page_history_keep_version(page_id, keep_last_versions)

Keep last versions :param page_id: :param keep_last_versions: :return:

Source code in server/vendor/atlassian/confluence.py
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
def remove_page_history_keep_version(self, page_id, keep_last_versions):
    """
    Keep last versions
    :param page_id:
    :param keep_last_versions:
    :return:
    """
    page = self.get_page_by_id(page_id=page_id, expand="version")
    page_number = page.get("version").get("number")
    while page_number > keep_last_versions:
        self.remove_page_history(page_id=page_id, version_number=1)
        page = self.get_page_by_id(page_id=page_id, expand="version")
        page_number = page.get("version").get("number")
        log.info("Removed oldest version for %s, now it's %s", page.get("title"), page_number)
    log.info("Kept versions %s for %s", keep_last_versions, page.get("title"))

remove_page_label(page_id, label)

Delete Confluence page label :param page_id: content_id format :param label: label name :return:

Source code in server/vendor/atlassian/confluence.py
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
def remove_page_label(self, page_id, label):
    """
    Delete Confluence page label
    :param page_id: content_id format
    :param label: label name
    :return:
    """
    url = "rest/api/content/{page_id}/label".format(page_id=page_id)
    params = {"id": page_id, "name": label}

    try:
        response = self.delete(path=url, params=params)
    except HTTPError as e:
        if e.response.status_code == 403:
            raise ApiPermissionError(
                "The user has view permission, " "but no edit permission to the content",
                reason=e,
            )
        if e.response.status_code == 404:
            # Raise ApiError as the documented reason is ambiguous
            raise ApiError(
                "The content or label doesn't exist, "
                "or the calling user doesn't have view permission to the content",
                reason=e,
            )

        raise

    return response

remove_space_permission(space_key, user, permission)

The JSON-RPC APIs for Confluence are provided here to help you browse and discover APIs you have access to. JSON-RPC APIs operate differently than REST APIs. To learn more about how to use these APIs, please refer to the Confluence JSON-RPC documentation on Atlassian Developers.

Source code in server/vendor/atlassian/confluence.py
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
def remove_space_permission(self, space_key, user, permission):
    """
    The JSON-RPC APIs for Confluence are provided here to help you browse and discover APIs you have access to.
    JSON-RPC APIs operate differently than REST APIs.
    To learn more about how to use these APIs,
    please refer to the Confluence JSON-RPC documentation on Atlassian Developers.
    """
    if self.api_version == "cloud":
        return {}
    url = "rpc/json-rpc/confluenceservice-v2"
    data = {
        "jsonrpc": "2.0",
        "method": "removePermissionFromSpace",
        "id": 9,
        "params": [permission, user, space_key],
    }
    return self.post(url, data=data).get("result") or {}

remove_template(template_id)

Deletes a template.

This results in different actions depending on the type of template
  • If the template is a content template, it is deleted.
  • If the template is a modified space-level blueprint template, it reverts to the template inherited from the global-level blueprint template.
  • If the template is a modified global-level blueprint template, it reverts to the default global-level blueprint template.

Note: Unmodified blueprint templates cannot be deleted.

:param str template_id: The ID of the template to be deleted. :return:

Source code in server/vendor/atlassian/confluence.py
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
def remove_template(self, template_id):
    """
    Deletes a template.

    This results in different actions depending on the type of template:
        * If the template is a content template, it is deleted.
        * If the template is a modified space-level blueprint template, it reverts to the template
            inherited from the global-level blueprint template.
        * If the template is a modified global-level blueprint template, it reverts to the default
            global-level blueprint template.
    Note: Unmodified blueprint templates cannot be deleted.

    :param str template_id: The ID of the template to be deleted.
    :return:
    """
    return self.delete("rest/api/template/{}".format(template_id))

scrap_regex_from_page(page_id, regex)

Method scraps regex patterns from a Confluence page_id.

:param page_id: The ID of the Confluence page. :param regex: The regex pattern to scrape. :return: A list of regex matches.

Source code in server/vendor/atlassian/confluence.py
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
def scrap_regex_from_page(self, page_id, regex):
    """
    Method scraps regex patterns from a Confluence page_id.

    :param page_id: The ID of the Confluence page.
    :param regex: The regex pattern to scrape.
    :return: A list of regex matches.
    """
    regex_output = []
    page_output = self.get_page_by_id(page_id, expand="body.storage")["body"]["storage"]["value"]
    try:
        if page_output is not None:
            description_matches = [x.group(0) for x in re.finditer(regex, page_output)]
            if description_matches:
                regex_output.extend(description_matches)
        return regex_output
    except HTTPError as e:
        if e.response.status_code == 404:
            # Raise ApiError as the documented reason is ambiguous
            log.error("couldn't find page_id : ", page_id)
            raise ApiNotFoundError(
                "There is no content with the given page id,"
                "or the calling user does not have permission to view the page",
                reason=e,
            )

set_inline_tasks_checkbox(page_id, task_id, status)

Set inline task element value status is CHECKED or UNCHECKED :return:

Source code in server/vendor/atlassian/confluence.py
3153
3154
3155
3156
3157
3158
3159
3160
3161
def set_inline_tasks_checkbox(self, page_id, task_id, status):
    """
    Set inline task element value
    status is CHECKED or UNCHECKED
    :return:
    """
    url = "rest/inlinetasks/1/task/{page_id}/{task_id}/".format(page_id=page_id, task_id=task_id)
    data = {"status": status, "trigger": "VIEW_PAGE"}
    return self.post(url, json=data)

set_page_label(page_id, label)

Set a label on the page :param page_id: content_id format :param label: label to add :return:

Source code in server/vendor/atlassian/confluence.py
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
def set_page_label(self, page_id, label):
    """
    Set a label on the page
    :param page_id: content_id format
    :param label: label to add
    :return:
    """
    url = "rest/api/content/{page_id}/label".format(page_id=page_id)
    data = {"prefix": "global", "name": label}

    try:
        response = self.post(path=url, data=data)
    except HTTPError as e:
        if e.response.status_code == 404:
            # Raise ApiError as the documented reason is ambiguous
            raise ApiError(
                "There is no content with the given id, "
                "or the calling user does not have permission to view the content",
                reason=e,
            )

        raise

    return response

set_page_property(page_id, data)

Set the page (content) property e.g. add hash parameters :param page_id: content_id format :param data: data should be as json data :return:

Source code in server/vendor/atlassian/confluence.py
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
def set_page_property(self, page_id, data):
    """
    Set the page (content) property e.g. add hash parameters
    :param page_id: content_id format
    :param data: data should be as json data
    :return:
    """
    url = "rest/api/content/{page_id}/property".format(page_id=page_id)
    json_data = data

    try:
        response = self.post(path=url, data=json_data)
    except HTTPError as e:
        if e.response.status_code == 400:
            raise ApiValueError(
                "The given property has a different content id to the one in the "
                "path, or the content already has a value with the given key, or "
                "the value is missing, or the value is too long",
                reason=e,
            )
        if e.response.status_code == 403:
            raise ApiPermissionError(
                "The user does not have permission to " "edit the content with the given id",
                reason=e,
            )
        if e.response.status_code == 413:
            raise ApiValueError("The value is too long", reason=e)

        raise

    return response

synchrony_disable()

Disable Synchrony :return:

Source code in server/vendor/atlassian/confluence.py
2656
2657
2658
2659
2660
2661
2662
2663
def synchrony_disable(self):
    """
    Disable Synchrony
    :return:
    """
    headers = {"X-Atlassian-Token": "no-check"}
    url = "rest/synchrony-interop/disable"
    return self.post(url, headers=headers)

synchrony_enable()

Enable Synchrony :return:

Source code in server/vendor/atlassian/confluence.py
2647
2648
2649
2650
2651
2652
2653
2654
def synchrony_enable(self):
    """
    Enable Synchrony
    :return:
    """
    headers = {"X-Atlassian-Token": "no-check"}
    url = "rest/synchrony-interop/enable"
    return self.post(url, headers=headers)

synchrony_get_configuration()

Status of collaborative editing Related to the on-prem setup Confluence Data Center :return:

Source code in server/vendor/atlassian/confluence.py
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
def synchrony_get_configuration(self):
    """
    Status of collaborative editing
    Related to the on-prem setup Confluence Data Center
    :return:
    """
    if self.cloud:
        return ApiNotAcceptable
    url = "rest/synchrony/1.0/config/status"
    return self.get(url, headers=self.no_check_headers)

synchrony_remove_draft(page_id)

Status of collaborative editing Related to the on-prem setup Confluence Data Center :return:

Source code in server/vendor/atlassian/confluence.py
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
def synchrony_remove_draft(self, page_id):
    """
    Status of collaborative editing
    Related to the on-prem setup Confluence Data Center
    :return:
    """
    if self.cloud:
        return ApiNotAcceptable
    url = "rest/synchrony/1.0/content/{pageId}/changes/unpublished".format(pageId=page_id)
    return self.delete(url)

team_calendar_events(sub_calendar_id, start, end, user_time_zone_id=None)

Get calendar event status :param sub_calendar_id: :param start: :param end: :param user_time_zone_id: :return:

Source code in server/vendor/atlassian/confluence.py
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
def team_calendar_events(self, sub_calendar_id, start, end, user_time_zone_id=None):
    """
    Get calendar event status
    :param sub_calendar_id:
    :param start:
    :param end:
    :param user_time_zone_id:
    :return:
    """
    url = "rest/calendar-services/1.0/calendar/events"
    params = {}
    if sub_calendar_id:
        params["subCalendarId"] = sub_calendar_id
    if user_time_zone_id:
        params["userTimeZoneId"] = user_time_zone_id
    if start:
        params["start"] = start
    if end:
        params["end"] = end
    return self.get(url, params=params)

team_calendars_get_sub_calendars(include=None, viewing_space_key=None, calendar_context=None)

Get subscribed calendars :param include: :param viewing_space_key: :param calendar_context: :return:

Source code in server/vendor/atlassian/confluence.py
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
def team_calendars_get_sub_calendars(self, include=None, viewing_space_key=None, calendar_context=None):
    """
    Get subscribed calendars
    :param include:
    :param viewing_space_key:
    :param calendar_context:
    :return:
    """
    url = "rest/calendar-services/1.0/calendar/subcalendars"
    params = {}
    if include:
        params["include"] = include
    if viewing_space_key:
        params["viewingSpaceKey"] = viewing_space_key
    if calendar_context:
        params["calendarContext"] = calendar_context
    return self.get(url, params=params)

update_existing_page(page_id, title, body, type='page', representation='storage', minor_edit=False, version_comment=None, full_width=False)

Duplicate update_page. Left for the people who used it before. Use update_page instead

Source code in server/vendor/atlassian/confluence.py
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
def update_existing_page(
    self,
    page_id,
    title,
    body,
    type="page",
    representation="storage",
    minor_edit=False,
    version_comment=None,
    full_width=False,
):
    """Duplicate update_page. Left for the people who used it before. Use update_page instead"""
    return self.update_page(
        page_id=page_id,
        title=title,
        body=body,
        type=type,
        representation=representation,
        minor_edit=minor_edit,
        version_comment=version_comment,
        full_width=full_width,
    )

update_or_create(parent_id, title, body, representation='storage', minor_edit=False, version_comment=None, editor=None, full_width=False)

Update page or create a page if it is not exists :param parent_id: :param title: :param body: :param representation: OPTIONAL: either Confluence 'storage' or 'wiki' markup format :param minor_edit: Update page without notification :param version_comment: Version comment :param editor: OPTIONAL: v2 to be created in the new editor :param full_width: OPTIONAL: Default is False :return:

Source code in server/vendor/atlassian/confluence.py
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
def update_or_create(
    self,
    parent_id,
    title,
    body,
    representation="storage",
    minor_edit=False,
    version_comment=None,
    editor=None,
    full_width=False,
):
    """
    Update page or create a page if it is not exists
    :param parent_id:
    :param title:
    :param body:
    :param representation: OPTIONAL: either Confluence 'storage' or 'wiki' markup format
    :param minor_edit: Update page without notification
    :param version_comment: Version comment
    :param editor: OPTIONAL: v2 to be created in the new editor
    :param full_width: OPTIONAL: Default is False
    :return:
    """
    space = self.get_page_space(parent_id)

    if self.page_exists(space, title):
        page_id = self.get_page_id(space, title)
        parent_id = parent_id if parent_id is not None else self.get_parent_content_id(page_id)
        result = self.update_page(
            parent_id=parent_id,
            page_id=page_id,
            title=title,
            body=body,
            representation=representation,
            minor_edit=minor_edit,
            version_comment=version_comment,
            full_width=full_width,
        )
    else:
        result = self.create_page(
            space=space,
            parent_id=parent_id,
            title=title,
            body=body,
            representation=representation,
            editor=editor,
            full_width=full_width,
        )

    log.info(
        "You may access your page at: %s%s",
        self.url,
        ((result or {}).get("_links") or {}).get("tinyui"),
    )
    return result

update_page(page_id, title, body=None, parent_id=None, type='page', representation='storage', minor_edit=False, version_comment=None, always_update=False, full_width=False)

Update page if already exist :param page_id: :param title: :param body: :param parent_id: :param type: :param representation: OPTIONAL: either Confluence 'storage' or 'wiki' markup format :param minor_edit: Indicates whether to notify watchers about changes. If False then notifications will be sent. :param version_comment: Version comment :param always_update: Whether always to update (suppress content check) :param full_width: OPTIONAL: Default False :return:

Source code in server/vendor/atlassian/confluence.py
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
def update_page(
    self,
    page_id,
    title,
    body=None,
    parent_id=None,
    type="page",
    representation="storage",
    minor_edit=False,
    version_comment=None,
    always_update=False,
    full_width=False,
):
    """
    Update page if already exist
    :param page_id:
    :param title:
    :param body:
    :param parent_id:
    :param type:
    :param representation: OPTIONAL: either Confluence 'storage' or 'wiki' markup format
    :param minor_edit: Indicates whether to notify watchers about changes.
        If False then notifications will be sent.
    :param version_comment: Version comment
    :param always_update: Whether always to update (suppress content check)
    :param full_width: OPTIONAL: Default False
    :return:
    """
    # update current page
    params = {"status": "current"}
    log.info('Updating %s "%s" with %s', type, title, parent_id)

    if not always_update and body is not None and self.is_page_content_is_already_updated(page_id, body, title):
        return self.get_page_by_id(page_id)

    try:
        if self.advanced_mode:
            version = self.history(page_id).json()["lastUpdated"]["number"] + 1
        else:
            version = self.history(page_id)["lastUpdated"]["number"] + 1
    except (IndexError, TypeError) as e:
        log.error("Can't find '%s' %s!", title, type)
        log.debug(e)
        return None

    data = {
        "id": page_id,
        "type": type,
        "title": title,
        "version": {"number": version, "minorEdit": minor_edit},
        "metadata": {"properties": {}},
    }
    if body is not None:
        data["body"] = self._create_body(body, representation)

    if parent_id:
        data["ancestors"] = [{"type": "page", "id": parent_id}]
    if version_comment:
        data["version"]["message"] = version_comment

    if full_width is True:
        data["metadata"]["properties"]["content-appearance-draft"] = {"value": "full-width"}
        data["metadata"]["properties"]["content-appearance-published"] = {"value": "full-width"}
    else:
        data["metadata"]["properties"]["content-appearance-draft"] = {"value": "fixed-width"}
        data["metadata"]["properties"]["content-appearance-published"] = {"value": "fixed-width"}
    try:
        response = self.put(
            "rest/api/content/{0}".format(page_id),
            data=data,
            params=params,
        )
    except HTTPError as e:
        if e.response.status_code == 400:
            raise ApiValueError(
                "No space or no content type, or setup a wrong version "
                "type set to content, or status param is not draft and "
                "status content is current",
                reason=e,
            )
        if e.response.status_code == 404:
            raise ApiNotFoundError("Can not find draft with current content", reason=e)

        raise

    return response

update_page_property(page_id, data)

Update the page (content) property. Use json data or independent keys :param data: :param page_id: content_id format :data: property data in json format :return:

Source code in server/vendor/atlassian/confluence.py
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
def update_page_property(self, page_id, data):
    """
    Update the page (content) property.
    Use json data or independent keys
    :param data:
    :param page_id: content_id format
    :data: property data in json format
    :return:
    """
    url = "rest/api/content/{page_id}/property/{key}".format(page_id=page_id, key=data.get("key"))
    try:
        response = self.put(path=url, data=data)
    except HTTPError as e:
        if e.response.status_code == 400:
            raise ApiValueError(
                "The given property has a different content id to the one in the "
                "path, or the content already has a value with the given key, or "
                "the value is missing, or the value is too long",
                reason=e,
            )
        if e.response.status_code == 403:
            raise ApiPermissionError(
                "The user does not have permission to " "edit the content with the given id",
                reason=e,
            )
        if e.response.status_code == 404:
            raise ApiNotFoundError(
                "There is no content with the given id, or no property with the given key, "
                "or if the calling user does not have permission to view the content.",
                reason=e,
            )
        if e.response.status_code == 409:
            raise ApiConflictError(
                "The given version is does not match the expected " "target version of the updated property",
                reason=e,
            )
        if e.response.status_code == 413:
            raise ApiValueError("The value is too long", reason=e)
        raise
    return response

update_plugin_license(plugin_key, raw_license)

Update license for plugin :param plugin_key: :param raw_license: :return:

Source code in server/vendor/atlassian/confluence.py
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
def update_plugin_license(self, plugin_key, raw_license):
    """
    Update license for plugin
    :param plugin_key:
    :param raw_license:
    :return:
    """
    app_headers = {
        "X-Atlassian-Token": "nocheck",
        "Content-Type": "application/vnd.atl.plugins+json",
    }
    url = "/plugins/1.0/{plugin_key}/license".format(plugin_key=plugin_key)
    data = {"rawLicense": raw_license}
    return self.put(url, data=data, headers=app_headers)

upload_plugin(plugin_path)

Provide plugin path for upload into Jira e.g. useful for auto deploy :param plugin_path: :return:

Source code in server/vendor/atlassian/confluence.py
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
def upload_plugin(self, plugin_path):
    """
    Provide plugin path for upload into Jira e.g. useful for auto deploy
    :param plugin_path:
    :return:
    """
    files = {"plugin": open(plugin_path, "rb")}
    upm_token = self.request(
        method="GET",
        path="rest/plugins/1.0/",
        headers=self.no_check_headers,
        trailing=True,
    ).headers["upm-token"]
    url = "rest/plugins/1.0/?token={upm_token}".format(upm_token=upm_token)
    return self.post(url, files=files, headers=self.no_check_headers)