1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
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
|
`szurubooru` uses REST API for all operations.
# Table of contents
1. [General rules](#general-rules)
- [Authentication](#authentication)
- [User token authentication](#user-token-authentication)
- [Basic requests](#basic-requests)
- [File uploads](#file-uploads)
- [Error handling](#error-handling)
- [Field selecting](#field-selecting)
- [Versioning](#versioning)
2. [API reference](#api-reference)
- Tag categories
- [Listing tag categories](#listing-tag-categories)
- [Creating tag category](#creating-tag-category)
- [Updating tag category](#updating-tag-category)
- [Getting tag category](#getting-tag-category)
- [Deleting tag category](#deleting-tag-category)
- [Setting default tag category](#setting-default-tag-category)
- Tags
- [Listing tags](#listing-tags)
- [Creating tag](#creating-tag)
- [Updating tag](#updating-tag)
- [Getting tag](#getting-tag)
- [Deleting tag](#deleting-tag)
- [Merging tags](#merging-tags)
- [Listing tag siblings](#listing-tag-siblings)
- Posts
- [Listing posts](#listing-posts)
- [Creating post](#creating-post)
- [Updating post](#updating-post)
- [Getting post](#getting-post)
- [Deleting post](#deleting-post)
- [Merging posts](#merging-posts)
- [Rating post](#rating-post)
- [Adding post to favorites](#adding-post-to-favorites)
- [Removing post from favorites](#removing-post-from-favorites)
- [Getting featured post](#getting-featured-post)
- [Featuring post](#featuring-post)
- [Reverse image search](#reverse-image-search)
- Comments
- [Listing comments](#listing-comments)
- [Creating comment](#creating-comment)
- [Updating comment](#updating-comment)
- [Getting comment](#getting-comment)
- [Deleting comment](#deleting-comment)
- [Rating comment](#rating-comment)
- Users
- [Listing users](#listing-users)
- [Creating user](#creating-user)
- [Updating user](#updating-user)
- [Getting user](#getting-user)
- [Deleting user](#deleting-user)
- User Tokens
- [Listing user tokens](#listing-user-tokens)
- [Creating user token](#creating-user-token)
- [Updating user token](#updating-user-token)
- [Deleting user token](#deleting-user-token)
- Password reset
- [Password reset - step 1: mail request](#password-reset---step-2-confirmation)
- [Password reset - step 2: confirmation](#password-reset---step-2-confirmation)
- Snapshots
- [Listing snapshots](#listing-snapshots)
- Global info
- [Getting global info](#getting-global-info)
- File uploads
- [Uploading temporary file](#uploading-temporary-file)
3. [Resources](#resources)
- [User](#user)
- [Micro user](#micro-user)
- [User token](#user-token)
- [Tag category](#tag-category)
- [Tag](#tag)
- [Micro tag](#micro-tag)
- [Post](#post)
- [Micro post](#micro-post)
- [Note](#note)
- [Comment](#comment)
- [Snapshot](#snapshot)
- [Unpaged search result](#unpaged-search-result)
- [Paged search result](#paged-search-result)
- [Image search result](#image-search-result)
4. [Search](#search)
# General rules
## Authentication
Authentication is achieved by means of [basic HTTP
auth](https://en.wikipedia.org/wiki/Basic_access_authentication) or through the
use of [user token authentication](#user-token-authentication). For this
reason, it is recommended to connect through HTTPS. There are no sessions, so
every privileged request must be authenticated. Available privileges depend on
the user's rank. The way how rank translates to privileges is defined in the
server's configuration.
It is recommended to add `?bump-login` GET parameter to the first request in a
client "session" (where the definition of a session is up to the client), so
that the user's last login time is kept up to date.
## User token authentication
User token authentication works similarly to [basic HTTP
auth](https://en.wikipedia.org/wiki/Basic_access_authentication). Because it
operates similarly to ***basic HTTP auth*** it is still recommended to connect
through HTTPS. The authorization header uses the type of `Token` and the
username and token are encoded as Base64 and sent as the second parameter.
Example header for user1:token-is-more-secure
```
Authorization: Token dXNlcjE6dG9rZW4taXMtbW9yZS1zZWN1cmU=
```
The benefit of token authentication is that beyond the initial login to acquire
the first token, there is no need to transmit the user password in plaintext
via basic auth. Additionally tokens can be revoked at anytime allowing a
cleaner interface for isolating clients from user credentials.
## Basic requests
Every request must use `Content-Type: application/json` and `Accept:
application/json`. An exception to this rule are requests that upload files.
## File uploads
Requests that upload files must use `multipart/form-data` encoding. Any request
that bundles user files, must send the request data (which is JSON) as an
additional file with the special name of `metadata` (whereas the actual files
must have names specific to the API that is being used.)
Alternatively, the server can download the files from the Internet on client's
behalf. In that case, the request doesn't need to be specially encoded in any
way. The files, however, should be passed as regular fields appended with a
`Url` suffix. For example, to use `http://example.com/file.jpg` in an API that
accepts a file named `content`, the client should pass
`{"contentUrl":"http://example.com/file.jpg"}` as a part of the JSON message
body.
Finally, in some cases the user might want to reuse one file between the
requests to save the bandwidth (for example, reverse search + consecutive
upload). In this case one should use [temporary file
uploads](#uploading-temporary-file), and pass the tokens returned by the API as
regular fields appended with a `Token` suffix. For example, to use previously
uploaded data, which was given token `deadbeef`, in an API that accepts a file
named `content`, the client should pass `{"contentToken":"deadbeef"}` as part
of the JSON message body. If the file with the particular token doesn't exist
or it has expired, the server will show an error.
## Error handling
All errors (except for unhandled fatal server errors) send relevant HTTP status
code together with JSON of following structure:
```json5
{
"name": "Name of the error, e.g. 'PostNotFoundError'",
"title": "Generic title of error message, e.g. 'Not found'",
"description": "Detailed description of what went wrong, e.g. 'User `rr-` not found."
}
```
List of possible error names:
- `MissingRequiredFileError`
- `MissingRequiredParameterError`
- `InvalidParameterError` (when trying to pass text when integer is expected etc.)
- `IntegrityError` (race conditions when editing the same resource)
- `SearchError`
- `AuthError`
- `PostNotFoundError`
- `PostAlreadyFeaturedError`
- `PostAlreadyUploadedError`
- `InvalidPostIdError`
- `InvalidPostSafetyError`
- `InvalidPostSourceError`
- `InvalidPostContentError`
- `InvalidPostRelationError`
- `InvalidPostNoteError`
- `InvalidPostFlagError`
- `InvalidFavoriteTargetError`
- `InvalidCommentIdError`
- `CommentNotFoundError`
- `EmptyCommentTextError`
- `InvalidScoreTargetError`
- `InvalidScoreValueError`
- `TagCategoryNotFoundError`
- `TagCategoryAlreadyExistsError`
- `TagCategoryIsInUseError`
- `InvalidTagCategoryNameError`
- `InvalidTagCategoryColorError`
- `TagNotFoundError`
- `TagAlreadyExistsError`
- `TagIsInUseError`
- `InvalidTagNameError`
- `InvalidTagRelationError`
- `InvalidTagCategoryError`
- `InvalidTagDescriptionError`
- `UserNotFoundError`
- `UserAlreadyExistsError`
- `InvalidUserNameError`
- `InvalidEmailError`
- `InvalidPasswordError`
- `InvalidRankError`
- `InvalidAvatarError`
- `ProcessingError` (failed to generate thumbnail or download remote file)
- `ValidationError` (catch all for odd validation errors)
## Field selecting
For performance considerations, sometimes the client might want to choose the
fields the server sends to it in order to improve the query speed. This
customization is available for top-level fields of most of the
[resources](#resources). To choose the fields, the client should pass
`?fields=field1,field2,...` suffix to the query. This works regardless of the
request type (`GET`, `PUT` etc.).
For example, to list posts while getting only their IDs and tags, the client
should send a `GET` query like this:
```
GET /posts/?fields=id,tags
```
## Versioning
To prevent problems with concurrent resource modification, szurubooru
implements optimistic locks using resource versions. Each modifiable resource
has its `version` returned to the client with `GET` requests. At the same time,
each `PUT` and `DELETE` request sent by the client must present the same
`version` field to the server with value as it was given in `GET`.
For example, given `GET /post/1`, the server responds like this:
```
{
...,
"version": 2
}
```
This means the client must then send `{"version": 2}` back too. If the client
fails to do so, the server will reject the request notifying about missing
parameter. If someone has edited the post in the mean time, the server will
reject the request as well, in which case the client is encouraged to notify
the user about the situation.
# API reference
Depending on the deployment, the URLs might be relative to some base path such
as `/api/`. Values denoted with diamond braces (`<like this>`) signify variable
data.
## Listing tag categories
- **Request**
`GET /tag-categories`
- **Output**
An [unpaged search result](#unpaged-search-result), for which `<resource>`
is a [tag category resource](#tag-category).
- **Errors**
- privileges are too low
- **Description**
Lists all tag categories. Doesn't use paging.
## Creating tag category
- **Request**
`POST /tag-categories`
- **Input**
```json5
{
"name": <name>,
"color": <color>
}
```
- **Output**
A [tag category resource](#tag-category).
- **Errors**
- the name is used by an existing tag category (names are case insensitive)
- the name is invalid or missing
- the color is invalid or missing
- privileges are too low
- **Description**
Creates a new tag category using specified parameters. Name must match
`tag_category_name_regex` from server's configuration. First category
created becomes the default category.
## Updating tag category
- **Request**
`PUT /tag-category/<name>`
- **Input**
```json5
{
"version": <version>,
"name": <name>, // optional
"color": <color>, // optional
}
```
- **Output**
A [tag category resource](#tag-category).
- **Errors**
- the version is outdated
- the tag category does not exist
- the name is used by an existing tag category (names are case insensitive)
- the name is invalid
- the color is invalid
- privileges are too low
- **Description**
Updates an existing tag category using specified parameters. Name must
match `tag_category_name_regex` from server's configuration. All fields
except the [`version`](#versioning) are optional - update concerns only
provided fields.
## Getting tag category
- **Request**
`GET /tag-category/<name>`
- **Output**
A [tag category resource](#tag-category).
- **Errors**
- the tag category does not exist
- privileges are too low
- **Description**
Retrieves information about an existing tag category.
## Deleting tag category
- **Request**
`DELETE /tag-category/<name>`
- **Input**
```json5
{
"version": <version>
}
```
- **Output**
```json5
{}
```
- **Errors**
- the version is outdated
- the tag category does not exist
- the tag category is used by some tags
- the tag category is the last tag category available
- privileges are too low
- **Description**
Deletes existing tag category. The tag category to be deleted must have no
usages.
## Setting default tag category
- **Request**
`PUT /tag-category/<name>/default`
- **Input**
```json5
{}
```
- **Output**
A [tag category resource](#tag-category).
- **Errors**
- the tag category does not exist
- privileges are too low
- **Description**
Sets given tag category as default. All new tags created manually or
automatically will have this category.
## Listing tags
- **Request**
`GET /tags/?offset=<initial-pos>&limit=<page-size>&query=<query>`
- **Output**
A [paged search result resource](#paged-search-result), for which
`<resource>` is a [tag resource](#tag).
- **Errors**
- privileges are too low
- **Description**
Searches for tags.
**Anonymous tokens**
Same as `name` token.
**Named tokens**
| `<key>` | Description |
| ------------------- | ----------------------------------------- |
| `name` | having given name (accepts wildcards) |
| `category` | having given category (accepts wildcards) |
| `creation-date` | created at given date |
| `creation-time` | alias of `creation-date` |
| `last-edit-date` | edited at given date |
| `last-edit-time` | alias of `last-edit-date` |
| `edit-date` | alias of `last-edit-date` |
| `edit-time` | alias of `last-edit-date` |
| `usages` | used in given number of posts |
| `usage-count` | alias of `usages` |
| `post-count` | alias of `usages` |
| `suggestion-count` | with given number of suggestions |
| `implication-count` | with given number of implications |
**Sort style tokens**
| `<value>` | Description |
| ------------------- | ---------------------------- |
| `random` | as random as it can get |
| `name` | A to Z |
| `category` | category (A to Z) |
| `creation-date` | recently created first |
| `creation-time` | alias of `creation-date` |
| `last-edit-date` | recently edited first |
| `last-edit-time` | alias of `creation-time` |
| `edit-date` | alias of `creation-time` |
| `edit-time` | alias of `creation-time` |
| `usages` | used in most posts first |
| `usage-count` | alias of `usages` |
| `post-count` | alias of `usages` |
| `suggestion-count` | with most suggestions first |
| `implication-count` | with most implications first |
**Special tokens**
None.
## Creating tag
- **Request**
`POST /tags`
- **Input**
```json5
{
"names": [<name1>, <name2>, ...],
"category": <category>,
"description": <description>, // optional
"implications": [<name1>, <name2>, ...], // optional
"suggestions": [<name1>, <name2>, ...] // optional
}
```
- **Output**
A [tag resource](#tag).
- **Errors**
- any name is used by an existing tag (names are case insensitive)
- any name, implication or is invalid
- category is invalid
- no name was specified
- implications or suggestions contain any item from names (e.g. there's a
shallow cyclic dependency)
- privileges are too low
- **Description**
Creates a new tag using specified parameters. Names, suggestions and
implications must match `tag_name_regex` from server's configuration.
Category must exist and is the same as `name` field within
[`<tag-category>` resource](#tag-category). Suggestions and implications
are optional. If specified implied tags or suggested tags do not exist yet,
they will be automatically created. Tags created automatically have no
implications, no suggestions, one name and their category is set to the
first tag category found. If there are no tag categories established yet,
an error will be thrown.
## Updating tag
- **Request**
`PUT /tag/<name>`
- **Input**
```json5
{
"version": <version>,
"names": [<name1>, <name2>, ...], // optional
"category": <category>, // optional
"description": <description>, // optional
"implications": [<name1>, <name2>, ...], // optional
"suggestions": [<name1>, <name2>, ...] // optional
}
```
- **Output**
A [tag resource](#tag).
- **Errors**
- the version is outdated
- the tag does not exist
- any name is used by an existing tag (names are case insensitive)
- any name, implication or suggestion name is invalid
- category is invalid
- implications or suggestions contain any item from names (e.g. there's a
shallow cyclic dependency)
- privileges are too low
- **Description**
Updates an existing tag using specified parameters. Names, suggestions and
implications must match `tag_name_regex` from server's configuration.
Category must exist and is the same as `name` field within
[`<tag-category>` resource](#tag-category). If specified implied tags or
suggested tags do not exist yet, they will be automatically created. Tags
created automatically have no implications, no suggestions, one name and
their category is set to the first tag category found. All fields except
the [`version`](#versioning) are optional - update concerns only provided
fields.
## Getting tag
- **Request**
`GET /tag/<name>`
- **Output**
A [tag resource](#tag).
- **Errors**
- the tag does not exist
- privileges are too low
- **Description**
Retrieves information about an existing tag.
## Deleting tag
- **Request**
`DELETE /tag/<name>`
- **Input**
```json5
{
"version": <version>
}
```
- **Output**
```json5
{}
```
- **Errors**
- the version is outdated
- the tag does not exist
- privileges are too low
- **Description**
Deletes existing tag. The tag to be deleted must have no usages.
## Merging tags
- **Request**
`POST /tag-merge/`
- **Input**
```json5
{
"removeVersion": <source-tag-version>,
"remove": <source-tag-name>,
"mergeToVersion": <target-tag-version>,
"mergeTo": <target-tag-name>
}
```
- **Output**
A [tag resource](#tag) containing the merged tag.
- **Errors**
- the version of either tag is outdated
- the source or target tag does not exist
- the source tag is the same as the target tag
- privileges are too low
- **Description**
Removes source tag and merges all of its usages, suggestions and
implications to the target tag. Other tag properties such as category and
aliases do not get transferred and are discarded.
## Listing tag siblings
- **Request**
`GET /tag-siblings/<name>`
- **Output**
```json5
{
"results": [
{
"tag": <tag>,
"occurrences": <occurrence-count>
},
{
"tag": <tag>,
"occurrences": <occurrence-count>
}
]
}
```
...where `<tag>` is a [tag resource](#tag).
- **Errors**
- privileges are too low
- **Description**
Lists siblings of given tag, e.g. tags that were used in the same posts as
the given tag. `occurrences` field signifies how many times a given sibling
appears with given tag. Results are sorted by occurrences count and the
list is truncated to the first 50 elements. Doesn't use paging.
## Listing posts
- **Request**
`GET /posts/?offset=<initial-pos>&limit=<page-size>&query=<query>`
- **Output**
A [paged search result resource](#paged-search-result), for which
`<resource>` is a [post resource](#post).
- **Errors**
- privileges are too low
- **Description**
Searches for posts.
**Anonymous tokens**
Same as `tag` token.
**Named tokens**
| `<key>` | Description |
| -------------------- | ---------------------------------------------------------- |
| `id` | having given post number |
| `tag` | having given tag (accepts wildcards) |
| `score` | having given score |
| `uploader` | uploaded by given user (accepts wildcards) |
| `upload` | alias of upload |
| `submit` | alias of upload |
| `comment` | commented by given user (accepts wildcards) |
| `fav` | favorited by given user (accepts wildcards) |
| `tag-count` | having given number of tags |
| `comment-count` | having given number of comments |
| `fav-count` | favorited by given number of users |
| `note-count` | having given number of annotations |
| `note-text` | having given note text (accepts wildcards) |
| `relation-count` | having given number of relations |
| `feature-count` | having been featured given number of times |
| `type` | given type of posts. `<value>` can be either `image`, `animation` (or `animated` or `anim`), `flash` (or `swf`) or `video` (or `webm`). |
| `content-checksum` | having given SHA1 checksum |
| `file-size` | having given file size (in bytes) |
| `image-width` | having given image width (where applicable) |
| `image-height` | having given image height (where applicable) |
| `image-area` | having given number of pixels (image width * image height) |
| `image-aspect-ratio` | having given aspect ratio (image width / image height) |
| `image-ar` | alias of `image-aspect-ratio` |
| `width` | alias of `image-width` |
| `height` | alias of `image-height` |
| `area` | alias of `image-area` |
| `ar` | alias of `image-aspect-ratio` |
| `aspect-ratio` | alias of `image-aspect-ratio` |
| `creation-date` | posted at given date |
| `creation-time` | alias of `creation-date` |
| `date` | alias of `creation-date` |
| `time` | alias of `creation-date` |
| `last-edit-date` | edited at given date |
| `last-edit-time` | alias of `last-edit-date` |
| `edit-date` | alias of `last-edit-date` |
| `edit-time` | alias of `last-edit-date` |
| `comment-date` | commented at given date |
| `comment-time` | alias of `comment-date` |
| `fav-date` | last favorited at given date |
| `fav-time` | alias of `fav-date` |
| `feature-date` | featured at given date |
| `feature-time` | alias of `feature-time` |
| `safety` | having given safety. `<value>` can be either `safe`, `sketchy` (or `questionable`) or `unsafe`. |
| `rating` | alias of `safety` |
**Sort style tokens**
| `<value>` | Description |
| ---------------- | ------------------------------------------------ |
| `random` | as random as it can get |
| `id` | highest to lowest post number |
| `score` | highest scored |
| `tag-count` | with most tags |
| `comment-count` | most commented first |
| `fav-count` | loved by most |
| `note-count` | with most annotations |
| `relation-count` | with most relations |
| `feature-count` | most often featured |
| `file-size` | largest files first |
| `image-width` | widest images first |
| `image-height` | tallest images first |
| `image-area` | largest images first |
| `width` | alias of `image-width` |
| `height` | alias of `image-height` |
| `area` | alias of `image-area` |
| `creation-date` | newest to oldest (pretty much same as id) |
| `creation-time` | alias of `creation-date` |
| `date` | alias of `creation-date` |
| `time` | alias of `creation-date` |
| `last-edit-date` | like creation-date, only looks at last edit time |
| `last-edit-time` | alias of `last-edit-date` |
| `edit-date` | alias of `last-edit-date` |
| `edit-time` | alias of `last-edit-date` |
| `comment-date` | recently commented by anyone |
| `comment-time` | alias of `comment-date` |
| `fav-date` | recently added to favorites by anyone |
| `fav-time` | alias of `fav-date` |
| `feature-date` | recently featured |
| `feature-time` | alias of `feature-time` |
**Special tokens**
| `<value>` | Description |
| ------------ | ------------------------------------------------------------- |
| `liked` | posts liked by currently logged in user |
| `disliked` | posts disliked by currently logged in user |
| `fav` | posts added to favorites by currently logged in user |
| `tumbleweed` | posts with score of 0, without comments and without favorites |
## Creating post
- **Request**
`POST /posts/`
- **Input**
```json5
{
"tags": [<tag1>, <tag2>, <tag3>],
"safety": <safety>,
"source": <source>, // optional
"relations": [<post1>, <post2>, <post3>], // optional
"notes": [<note1>, <note2>, <note3>], // optional
"flags": [<flag1>, <flag2>], // optional
"anonymous": <anonymous> // optional
}
```
- **Files**
- `content` - the content of the post.
- `thumbnail` - the content of custom thumbnail (optional).
- **Output**
A [post resource](#post).
- **Errors**
- tags have invalid names
- safety, notes or flags are invalid
- relations refer to non-existing posts
- privileges are too low
- **Description**
Creates a new post. If specified tags do not exist yet, they will be
automatically created. Tags created automatically have no implications, no
suggestions, one name and their category is set to the first tag category
found. Safety must be any of `"safe"`, `"sketchy"` or `"unsafe"`. Relations
must contain valid post IDs. `<flag>` currently can be only `"loop"` to
enable looping for video posts. Sending empty `thumbnail` will cause the
post to use default thumbnail. If `anonymous` is set to truthy value, the
uploader name won't be recorded (privilege verification still applies; it's
possible to disallow anonymous uploads completely from config.) For details
how to pass `content` and `thumbnail`, see [file uploads](#file-uploads).
## Updating post
- **Request**
`PUT /post/<id>`
- **Input**
```json5
{
"version": <version>,
"tags": [<tag1>, <tag2>, <tag3>], // optional
"safety": <safety>, // optional
"source": <source>, // optional
"relations": [<post1>, <post2>, <post3>], // optional
"notes": [<note1>, <note2>, <note3>], // optional
"flags": [<flag1>, <flag2>] // optional
}
```
- **Files**
- `content` - the content of the post (optional).
- `thumbnail` - the content of custom thumbnail (optional).
- **Output**
A [post resource](#post).
- **Errors**
- the version is outdated
- tags have invalid names
- safety, notes or flags are invalid
- relations refer to non-existing posts
- privileges are too low
- **Description**
Updates existing post. If specified tags do not exist yet, they will be
automatically created. Tags created automatically have no implications, no
suggestions, one name and their category is set to the first tag category
found. Safety must be any of `"safe"`, `"sketchy"` or `"unsafe"`. Relations
must contain valid post IDs. `<flag>` currently can be only `"loop"` to
enable looping for video posts. Sending empty `thumbnail` will reset the
post thumbnail to default. For details how to pass `content` and
`thumbnail`, see [file uploads](#file-uploads). All fields except the
[`version`](#versioning) are optional - update concerns only provided
fields.
## Getting post
- **Request**
`GET /post/<id>`
- **Output**
A [post resource](#post).
- **Errors**
- the post does not exist
- privileges are too low
- **Description**
Retrieves information about an existing post.
## Deleting post
- **Request**
`DELETE /post/<id>`
- **Input**
```json5
{
"version": <version>
}
```
- **Output**
```json5
{}
```
- **Errors**
- the version is outdated
- the post does not exist
- privileges are too low
- **Description**
Deletes existing post. Related posts and tags are kept.
## Merging posts
- **Request**
`POST /post-merge/`
- **Input**
```json5
{
"removeVersion": <source-post-version>,
"remove": <source-post-id>,
"mergeToVersion": <target-post-version>,
"mergeTo": <target-post-id>,
"replaceContent": <true-or-false>
}
```
- **Output**
A [post resource](#post) containing the merged post.
- **Errors**
- the version of either post is outdated
- the source or target post does not exist
- the source post is the same as the target post
- privileges are too low
- **Description**
Removes source post and merges all of its tags, relations, scores,
favorites and comments to the target post. If `replaceContent` is set to
true, content of the target post is replaced using the content of the
source post; otherwise it remains unchanged. Source post properties such as
its safety, source, whether to loop the video and other scalar values do
not get transferred and are discarded.
## Rating post
- **Request**
`PUT /post/<id>/score`
- **Input**
```json5
{
"score": <score>
}
```
- **Output**
A [post resource](#post).
- **Errors**
- post does not exist
- score is invalid
- privileges are too low
- **Description**
Updates score of authenticated user for given post. Valid scores are -1, 0
and 1.
## Adding post to favorites
- **Request**
`POST /post/<id>/favorite`
- **Output**
A [post resource](#post).
- **Errors**
- post does not exist
- privileges are too low
- **Description**
Marks the post as favorite for authenticated user.
## Removing post from favorites
- **Request**
`DELETE /post/<id>/favorite`
- **Output**
A [post resource](#post).
- **Errors**
- post does not exist
- privileges are too low
- **Description**
Unmarks the post as favorite for authenticated user.
## Getting featured post
- **Request**
`GET /featured-post`
- **Output**
A [post resource](#post).
- **Errors**
- privileges are too low
- **Description**
Retrieves the post that is currently featured on the main page in web
client. If no post is featured, `<post>` is null. Note that this method
exists mostly for compatibility with setting featured post - most of times,
you'd want to use query global info which contains more information.
## Featuring post
- **Request**
`POST /featured-post`
- **Input**
```json5
{
"id": <post-id>
}
```
- **Output**
A [post resource](#post).
- **Errors**
- privileges are too low
- trying to feature a post that is currently featured
- **Description**
Features a post on the main page in web client.
## Reverse image search
- **Request**
`POST /posts/reverse-search`
- **Files**
- `content` - the image to search for.
- **Output**
An [image search result](#image-search-result).
- **Errors**
- privileges are too low
- **Description**
Retrieves posts that look like the input image.
## Listing comments
- **Request**
`GET /comments/?offset=<initial-pos>&limit=<page-size>&query=<query>`
- **Output**
A [paged search result resource](#paged-search-result), for which
`<resource>` is a [comment resource](#comment).
- **Errors**
- privileges are too low
- **Description**
Searches for comments.
**Anonymous tokens**
Same as `text` token.
**Named tokens**
| `<key>` | Description |
| ---------------- | ---------------------------------------------- |
| `id` | specific comment ID |
| `post` | specific post ID |
| `user` | created by given user (accepts wildcards) |
| `author` | alias of `user` |
| `text` | containing given text (accepts wildcards) |
| `creation-date` | created at given date |
| `creation-time` | alias of `creation-date` |
| `last-edit-date` | whose most recent edit date matches given date |
| `last-edit-time` | alias of `last-edit-date` |
| `edit-date` | alias of `last-edit-date` |
| `edit-time` | alias of `last-edit-date` |
**Sort style tokens**
| `<value>` | Description |
| ---------------- | ------------------------- |
| `random` | as random as it can get |
| `user` | author name, A to Z |
| `author` | alias of `user` |
| `post` | post ID, newest to oldest |
| `creation-date` | newest to oldest |
| `creation-time` | alias of `creation-date` |
| `last-edit-date` | recently edited first |
| `last-edit-time` | alias of `last-edit-date` |
| `edit-date` | alias of `last-edit-date` |
| `edit-time` | alias of `last-edit-date` |
**Special tokens**
None.
## Creating comment
- **Request**
`POST /comments/`
- **Input**
```json5
{
"text": <text>,
"postId": <post-id>
}
```
- **Output**
A [comment resource](#comment).
- **Errors**
- the post does not exist
- comment text is empty
- privileges are too low
- **Description**
Creates a new comment under given post.
## Updating comment
- **Request**
`PUT /comment/<id>`
- **Input**
```json5
{
"version": <version>,
"text": <new-text> // mandatory
}
```
- **Output**
A [comment resource](#comment).
- **Errors**
- the version is outdated
- the comment does not exist
- new comment text is empty
- privileges are too low
- **Description**
Updates an existing comment text.
## Getting comment
- **Request**
`GET /comment/<id>`
- **Output**
A [comment resource](#comment).
- **Errors**
- the comment does not exist
- privileges are too low
- **Description**
Retrieves information about an existing comment.
## Deleting comment
- **Request**
`DELETE /comment/<id>`
- **Input**
```json5
{
"version": <version>
}
```
- **Output**
```json5
{}
```
- **Errors**
- the version is outdated
- the comment does not exist
- privileges are too low
- **Description**
Deletes existing comment.
## Rating comment
- **Request**
`PUT /comment/<id>/score`
- **Input**
```json5
{
"score": <score>
}
```
- **Output**
A [comment resource](#comment).
- **Errors**
- comment does not exist
- score is invalid
- privileges are too low
- **Description**
Updates score of authenticated user for given comment. Valid scores are -1,
0 and 1.
## Listing users
- **Request**
`GET /users/?offset=<initial-pos>&limit=<page-size>&query=<query>`
- **Output**
A [paged search result resource](#paged-search-result), for which
`<resource>` is a [user resource](#user).
- **Errors**
- privileges are too low
- **Description**
Searches for users.
**Anonymous tokens**
Same as `name` token.
**Named tokens**
| `<key>` | Description |
| ----------------- | ----------------------------------------------- |
| `name` | having given name (accepts wildcards) |
| `creation-date` | registered at given date |
| `creation-time` | alias of `creation-date` |
| `last-login-date` | whose most recent login date matches given date |
| `last-login-time` | alias of `last-login-date` |
| `login-date` | alias of `last-login-date` |
| `login-time` | alias of `last-login-date` |
**Sort style tokens**
| `<value>` | Description |
| ----------------- | -------------------------- |
| `random` | as random as it can get |
| `name` | A to Z |
| `creation-date` | newest to oldest |
| `creation-time` | alias of `creation-date` |
| `last-login-date` | recently active first |
| `last-login-time` | alias of `last-login-date` |
| `login-date` | alias of `last-login-date` |
| `login-time` | alias of `last-login-date` |
**Special tokens**
None.
## Creating user
- **Request**
`POST /users`
- **Input**
```json5
{
"name": <user-name>,
"password": <user-password>,
"email": <email>, // optional
"rank": <rank>, // optional
"avatarStyle": <avatar-style> // optional
}
```
- **Files**
- `avatar` - the content of the new avatar (optional).
- **Output**
A [user resource](#user).
- **Errors**
- a user with such name already exists (names are case insensitive)
- either user name, password, email or rank are invalid
- the user is trying to update their or someone else's rank to higher than
their own
- avatar is missing for manual avatar style
- privileges are too low
- **Description**
Creates a new user using specified parameters. Names and passwords must
match `user_name_regex` and `password_regex` from server's configuration,
respectively. Email address, rank and avatar fields are optional. Avatar
style can be either `gravatar` or `manual`. `manual` avatar style requires
client to pass also `avatar` file - see [file uploads](#file-uploads) for
details. If the rank is empty and the user happens to be the first user
ever created, become an administrator, whereas subsequent users will be
given the rank indicated by `default_rank` in the server's configuration.
## Updating user
- **Request**
`PUT /user/<name>`
- **Input**
```json5
{
"version": <version>,
"name": <user-name>, // optional
"password": <user-password>, // optional
"email": <email>, // optional
"rank": <rank>, // optional
"avatarStyle": <avatar-style> // optional
}
```
- **Files**
- `avatar` - the content of the new avatar (optional).
- **Output**
A [user resource](#user).
- **Errors**
- the version is outdated
- the user does not exist
- a user with new name already exists (names are case insensitive)
- either user name, password, email or rank are invalid
- the user is trying to update their or someone else's rank to higher than
their own
- avatar is missing for manual avatar style
- privileges are too low
- **Description**
Updates an existing user using specified parameters. Names and passwords
must match `user_name_regex` and `password_regex` from server's
configuration, respectively. All fields are optional - update concerns only
provided fields. To update last login time, see
[authentication](#authentication). Avatar style can be either `gravatar` or
`manual`. `manual` avatar style requires client to pass also `avatar`
file - see [file uploads](#file-uploads) for details. All fields except the
[`version`](#versioning) are optional - update concerns only provided
fields.
## Getting user
- **Request**
`GET /user/<name>`
- **Output**
A [user resource](#user).
- **Errors**
- the user does not exist
- privileges are too low
- **Description**
Retrieves information about an existing user.
## Deleting user
- **Request**
`DELETE /user/<name>`
- **Input**
```json5
{
"version": <version>
}
```
- **Output**
```json5
{}
```
- **Errors**
- the version is outdated
- the user does not exist
- privileges are too low
- **Description**
Deletes existing user.
## Listing user tokens
- **Request**
`GET /user-tokens/<user_name>`
- **Output**
An [unpaged search result resource](#unpaged-search-result), for which
`<resource>` is a [user token resource](#user-token).
- **Errors**
- privileges are too low
- **Description**
Searches for user tokens for the given user.
## Creating user token
- **Request**
`POST /user-token/<user_name>`
- **Input**
```json5
{
"enabled": <enabled>, // optional
"note": <note>, // optional
"expirationTime": <expiration-time> // optional
}
```
- **Output**
A [user token resource](#user-token).
- **Errors**
- privileges are too low
- **Description**
Creates a new user token that can be used for authentication of API
endpoints instead of a password.
## Updating user token
- **Request**
`PUT /user-token/<user_name>/<token>`
- **Input**
```json5
{
"version": <version>,
"enabled": <enabled>, // optional
"note": <note>, // optional
"expirationTime": <expiration-time> // optional
}
```
- **Output**
A [user token resource](#user-token).
- **Errors**
- the version is outdated
- the user token does not exist
- privileges are too low
- **Description**
Updates an existing user token using specified parameters. All fields
except the [`version`](#versioning) are optional - update concerns only
provided fields.
## Deleting user token
- **Request**
`DELETE /user-token/<user_name>/<token>`
- **Input**
```json5
{
"version": <version>
}
```
- **Output**
```json5
{}
```
- **Errors**
- the token does not exist
- privileges are too low
- **Description**
Deletes existing user token.
## Password reset - step 1: mail request
- **Request**
`GET /password-reset/<email-or-name>`
- **Output**
```
{}
```
- **Errors**
- the user does not exist
- the user hasn't provided an email address
- **Description**
Sends a confirmation email to given user. The email contains link
containing a token. The token cannot be guessed, thus using such link
proves that the person who requested to reset the password also owns the
mailbox, which is a strong indication they are the rightful owner of the
account.
## Password reset - step 2: confirmation
- **Request**
`POST /password-reset/<email-or-name>`
- **Input**
```json5
{
"token": <token-from-email>
}
```
- **Output**
```json5
{
"password": <new-password>
}
```
- **Errors**
- the token is missing
- the token is invalid
- the user does not exist
- **Description**
Generates a new password for given user. Password is sent as plain-text, so
it is recommended to connect through HTTPS.
## Listing snapshots
- **Request**
`GET /snapshots/?offset=<initial-pos>&limit=<page-size>&query=<query>`
- **Output**
A [paged search result resource](#paged-search-result), for which
`<resource>` is a [snapshot resource](#snapshot).
- **Errors**
- privileges are too low
- **Description**
Lists recent resource snapshots.
**Anonymous tokens**
Not supported.
**Named tokens**
| `<key>` | Description |
| ----------------- | ---------------------------------------------------------------- |
| `type` | involving given resource type |
| `id` | involving given resource id |
| `date` | created at given date |
| `time` | alias of `date` |
| `operation` | `modified`, `created`, `deleted` or `merged` |
| `user` | name of the user that created given snapshot (accepts wildcards) |
**Sort style tokens**
None. The snapshots are always sorted by creation time.
**Special tokens**
None.
## Getting global info
- **Request**
`GET /info`
- **Output**
```json5
{
"postCount": <post-count>,
"diskUsage": <disk-usage>, // in bytes
"featuredPost": <featured-post>,
"featuringTime": <time>,
"featuringUser": <user>,
"serverTime": <server-time>,
"config": {
"userNameRegex": <user-name-regex>,
"passwordRegex": <password-regex>,
"tagNameRegex": <tag-name-regex>,
"tagCategoryNameRegex": <tag-category-name-regex>,
"defaultUserRank": <default-rank>,
"privileges": <privileges>
}
}
```
- **Description**
Retrieves simple statistics. `<featured-post>` is null if there is no
featured post yet. `<server-time>` is pretty much the same as the `Date`
HTTP field, only formatted in a manner consistent with other dates. Values
in `config` key are taken directly from the server config, with the
exception of privilege array keys being converted to lower camel case to
match the API convention.
## Uploading temporary file
- **Request**
`POST /uploads`
- **Files**
- `content` - the content of the file to upload. Note that in this
particular API, one can't use token-based uploads.
- **Output**
```json5
{
"token": <token>
}
```
- **Errors**
- privileges are too low
- **Description**
Puts a file in temporary storage and assigns it a token that can be used in
other requests. The files uploaded that way are deleted after a short while
so clients shouldn't use it as a free upload service.
# Resources
## User
**Description**
A single user.
**Structure**
```json5
{
"version": <version>,
"name": <name>,
"email": <email>,
"rank": <rank>,
"lastLoginTime": <last-login-time>,
"creationTime": <creation-time>,
"avatarStyle": <avatar-style>,
"avatarUrl": <avatar-url>,
"commentCount": <comment-count>,
"uploadedPostCount": <uploaded-post-count>,
"likedPostCount": <liked-post-count>,
"dislikedPostCount": <disliked-post-count>,
"favoritePostCount": <favorite-post-count>
}
```
**Field meaning**
- `<version>`: resource version. See [versioning](#versioning).
- `<name>`: the user name.
- `<email>`: the user email. It is available only if the request is
authenticated by the same user, or the authenticated user can change the
email. If it's unavailable, the server returns `false`. If the user hasn't
specified an email, the server returns `null`.
- `<rank>`: the user rank, which effectively affects their privileges.
Possible values:
- `"restricted"`: restricted user
- `"regular"`: regular user
- `"power"`: power user
- `"moderator"`: moderator
- `"administrator"`: administrator
- `<last-login-time>`: the last login time, formatted as per RFC 3339.
- `<creation-time>`: the user registration time, formatted as per RFC 3339.
- `<avatarStyle>`: how to render the user avatar.
Possible values:
- `"gravatar"`: the user uses Gravatar.
- `"manual"`: the user has uploaded a picture manually.
- `<avatarUrl>`: the URL to the avatar.
- `<comment-count>`: number of comments.
- `<uploaded-post-count>`: number of uploaded posts.
- `<liked-post-count>`: nubmer of liked posts. It is available only if the
request is authenticated by the same user. If it's unavailable, the server
returns `false`.
- `<disliked-post-count>`: number of disliked posts. It is available only if
the request is authenticated by the same user. If it's unavailable, the
server returns `false`.
- `<favorite-post-count>`: number of favorited posts.
## Micro user
**Description**
A [user resource](#user) stripped down to `name` and `avatarUrl` fields.
## User token
**Description**
A single user token.
**Structure**
```json5
{
"user": <user>,
"token": <token>,
"note": <token>,
"enabled": <enabled>,
"expirationTime": <expiration-time>,
"version": <version>,
"creationTime": <creation-time>,
"lastEditTime": <last-edit-time>,
"lastUsageTime": <last-usage-time>
}
```
**Field meaning**
- `<user>`: micro user. See [micro user](#micro-user).
- `<token>`: the token that can be used to authenticate the user.
- `<note>`: a note that describes the token.
- `<enabled>`: whether the token is still valid for authentication.
- `<expiration-time>`: time when the token expires. It must include the timezone as per RFC 3339.
- `<version>`: resource version. See [versioning](#versioning).
- `<creation-time>`: time the user token was created, formatted as per RFC 3339.
- `<last-edit-time>`: time the user token was edited, formatted as per RFC 3339.
- `<last-usage-time>`: the last time this token was used during a login involving `?bump-login`, formatted as per RFC 3339.
## Tag category
**Description**
A single tag category. The primary purpose of tag categories is to distinguish
certain tag types (such as characters, media type etc.), which improves user
experience.
**Structure**
```json5
{
"version": <version>,
"name": <name>,
"color": <color>,
"usages": <usages>
"default": <is-default>
}
```
**Field meaning**
- `<version>`: resource version. See [versioning](#versioning).
- `<name>`: the category name.
- `<color>`: the category color.
- `<usages>`: how many tags is the given category used with.
- `<is-default>`: whether the tag category is the default one.
## Tag
**Description**
A single tag. Tags are used to let users search for posts.
**Structure**
```json5
{
"version": <version>,
"names": <names>,
"category": <category>,
"implications": <implications>,
"suggestions": <suggestions>,
"creationTime": <creation-time>,
"lastEditTime": <last-edit-time>,
"usages": <usage-count>,
"description": <description>
}
```
**Field meaning**
- `<version>`: resource version. See [versioning](#versioning).
- `<names>`: a list of tag names (aliases). Tagging a post with any name will
automatically assign the first name from this list.
- `<category>`: the name of the category the given tag belongs to.
- `<implications>`: a list of implied tags, serialized as [micro
tag resource](#micro-tag). Implied tags are automatically appended by the web
client on usage.
- `<suggestions>`: a list of suggested tags, serialized as [micro
tag resource](#micro-tag). Suggested tags are shown to the user by the web
client on usage.
- `<creation-time>`: time the tag was created, formatted as per RFC 3339.
- `<last-edit-time>`: time the tag was edited, formatted as per RFC 3339.
- `<usage-count>`: the number of posts the tag was used in.
- `<description>`: the tag description (instructions how to use, history etc.)
The client should render is as Markdown.
## Micro tag
**Description**
A [tag resource](#tag) stripped down to `names`, `category` and `usages` fields.
## Post
**Description**
One file together with its metadata posted to the site.
**Structure**
```json5
{
"version": <version>,
"id": <id>,
"creationTime": <creation-time>,
"lastEditTime": <last-edit-time>,
"safety": <safety>,
"source": <source>,
"type": <type>,
"checksum": <checksum>,
"canvasWidth": <canvas-width>,
"canvasHeight": <canvas-height>,
"contentUrl": <content-url>,
"thumbnailUrl": <thumbnail-url>,
"flags": <flags>,
"tags": <tags>,
"relations": <relations>,
"notes": <notes>,
"user": <user>,
"score": <score>,
"ownScore": <own-score>,
"ownFavorite": <own-favorite>,
"tagCount": <tag-count>,
"favoriteCount": <favorite-count>,
"commentCount": <comment-count>,
"noteCount": <note-count>,
"featureCount": <feature-count>,
"relationCount": <relation-count>,
"lastFeatureTime": <last-feature-time>,
"favoritedBy": <favorited-by>,
"hasCustomThumbnail": <has-custom-thumbnail>,
"mimeType": <mime-type>,
"comments": [
<comment>,
<comment>,
<comment>
]
}
```
**Field meaning**
- `<version>`: resource version. See [versioning](#versioning).
- `<id>`: the post identifier.
- `<creation-time>`: time the tag was created, formatted as per RFC 3339.
- `<last-edit-time>`: time the tag was edited, formatted as per RFC 3339.
- `<safety>`: whether the post is safe for work.
Available values:
- `"safe"`
- `"sketchy"`
- `"unsafe"`
- `<source>`: where the post was grabbed form, supplied by the user.
- `<type>`: the type of the post.
Available values:
- `"image"` - plain image.
- `"animation"` - animated image (GIF).
- `"video"` - WEBM video.
- `"flash"` - Flash animation / game.
- `"youtube"` - Youtube embed.
- `<checksum>`: the file checksum. Used in snapshots to signify changes of the
post content.
- `<canvas-width>` and `<canvas-height>`: the original width and height of the
post content.
- `<content-url>`: where the post content is located.
- `<thumbnail-url>`: where the post thumbnail is located.
- `<flags>`: various flags such as whether the post is looped, represented as
array of plain strings.
- `<tags>`: list of tags the post is tagged with, serialized as [micro
tag resource](#micro-tag).
- `<relations>`: a list of related posts, serialized as [micro post
resources](#micro-post). Links to related posts are shown
to the user by the web client.
- `<notes>`: a list of post annotations, serialized as list of [note
resources](#note).
- `<user>`: who created the post, serialized as [micro user resource](#micro-user).
- `<score>`: the collective score (+1/-1 rating) of the given post.
- `<own-score>`: the score (+1/-1 rating) of the given post by the
authenticated user.
- `<own-favorite>`: whether the authenticated user has given post in their
favorites.
- `<tag-count>`: how many tags the post is tagged with
- `<favorite-count>`: how many users have the post in their favorites
- `<comment-count>`: how many comments are filed under that post
- `<note-count>`: how many notes the post has
- `<feature-count>`: how many times has the post been featured.
- `<relation-count>`: how many posts are related to this post.
- `<last-feature-time>`: the last time the post was featured, formatted as per
RFC 3339.
- `<favorited-by>`: list of users, serialized as [micro user resources](#micro-user).
- `<has-custom-thumbnail>`: whether the post uses custom thumbnail.
- `<mime-type>`: subsidiary to `<type>`, used to tell exact content format;
useful for `<video>` tags for instance.
- `<comment>`: a [comment resource](#comment) for given post.
## Micro post
**Description**
A [post resource](#post) stripped down to `name` and `thumbnailUrl` fields.
## Note
**Description**
A text annotation rendered on top of the post.
**Structure**
```json5
{
"polygon": <list-of-points>,
"text": <text>,
}
```
**Field meaning**
- `<list-of-points>`: where to draw the annotation. Each point must have
coordinates within 0 to 1. For example, `[[0,0],[0,1],[1,1],[1,0]]` will draw
the annotation on the whole post, whereas `[[0,0],[0,0.5],[0.5,0.5],[0.5,0]]`
will draw it inside the post's upper left quarter.
- `<text>`: the annotation text. The client should render is as Markdown.
## Comment
**Description**
A comment under a post.
**Structure**
```json5
{
"version": <version>,
"id": <id>,
"postId": <post-id>,
"user": <author>
"text": <text>,
"creationTime": <creation-time>,
"lastEditTime": <last-edit-time>,
"score": <score>,
"ownScore": <own-score>
}
```
**Field meaning**
- `<version>`: resource version. See [versioning](#versioning).
- `<id>`: the comment identifier.
- `<post-id>`: an id of the post the comment is for.
- `<text>`: the comment content. The client should render is as Markdown.
- `<author>`: a [micro user resource](#micro-user) the comment is created by.
- `<creation-time>`: time the comment was created, formatted as per RFC 3339.
- `<last-edit-time>`: time the comment was edited, formatted as per RFC 3339.
- `<score>`: the collective score (+1/-1 rating) of the given comment.
- `<own-score>`: the score (+1/-1 rating) of the given comment by the
authenticated user.
## Snapshot
**Description**
A snapshot is a version of a database resource.
**Structure**
```json5
{
"operation": <operation>,
"type": <resource-type>,
"id": <resource-id>,
"user": <issuer>,
"data": <data>,
"time": <time>
}
```
**Field meaning**
- `<operation>`: what happened to the resource.
The value can be either of values below:
- `"created"` - the resource has been created
- `"modified"` - the resource has been modified
- `"deleted"` - the resource has been deleted
- `"merged"` - the resource has been merged to another resource
- `<resource-type>` and `<resource-id>`: the resource that was changed.
The values are correlated as per table below:
| `<resource-type>` | `<resource-id>` |
| ----------------- | ------------------------------- |
| `"tag"` | first tag name at given time |
| `"tag_category"` | tag category name at given time |
| `"post"` | post ID |
- `<issuer>`: a [micro user resource](#micro-user) representing the user who
has made the change.
- `<data>`: the snapshot data, of which content depends on the `<operation>`.
More explained later.
- `<time>`: when the snapshot was created (i.e. when the resource was changed),
formatted as per RFC 3339.
**`<data>` field for creation snapshots**
The value can be either of structures below, depending on
`<resource-type>`:
- Tag category snapshot data (`<resource-type> = "tag_category"`)
*Example*
```json5
{
"name": "character",
"color": "#FF0000",
"default": false
}
```
- Tag snapshot data (`<resource-type> = "tag"`)
*Example*
```json5
{
"names": ["tag1", "tag2", "tag3"],
"category": "plain",
"implications": ["imp1", "imp2", "imp3"],
"suggestions": ["sug1", "sug2", "sug3"]
}
```
- Post snapshot data (`<resource-type> = "post"`)
*Example*
```json5
{
"source": "http://example.com/",
"safety": "safe",
"checksum": "deadbeef",
"tags": ["tag1", "tag2"],
"relations": [1, 2],
"notes": [<note1>, <note2>, <note3>],
"flags": ["loop"],
"featured": false
}
```
`<note>`s are serialized the same way as [note resources](#note).
**`<data>` field for modification snapshots**
The value is a property-wise recursive diff between previous version of the
resource and its current version. Its structure is a `<dictionary-diff>` of
dictionaries as created by creation snapshots, which is described below.
`<primitive>`: any primitive (number or a string)
`<anything>`: any dictionary, list or primitive
`<dictionary-diff>`:
```json5
{
"type": "object change",
"value":
{
"property-of-any-type-1":
{
"type": "deleted property",
"value": <anything>
},
"property-of-any-type-2":
{
"type": "added property",
"value": <anything>
},
"primitive-property":
{
"type": "primitive change":
"old-value": "<primitive>",
"new-value": "<primitive>"
},
"list-property": <list-diff>,
"dictionary-property": <dictionary-diff>
}
}
```
`<list-diff>`:
```json5
{
"type": "list change",
"removed": [<anything>, <anything>],
"added": [<anything>, <anything>]
}
```
Example - a diff for a post that has changed source and has one note added.
Note the similarities with the structure of post creation snapshots.
```json5
{
"type": "object change",
"value":
{
"source":
{
"type": "primitive change",
"old-value": None,
"new-value": "new source"
},
"notes":
{
"type": "list change",
"removed": [],
"added":
[
{"polygon": [[0, 0], [0, 1], [1, 1]], "text": "new note"}
]
}
}
}
```
Since the snapshot dictionaries structure is pretty immutable, you probably
won't see `added property` or `deleted property` around. This observation holds
true even if the way the snapshots are generated changes - szurubooru stores
just the diffs rather than original snapshots, so it wouldn't be able to
generate a diff against an old version.
**`<data>` field for deletion snapshots**
Same as creation snapshot. In emergencies, it can be used to reconstruct
deleted entities. Please note that this does not constitute as means against
vandalism (it's still possible to cause chaos by mass editing - this should be
dealt with by configuring role privileges in the config) or replace database
backups.
**`<data>` field for merge snapshots**
A tuple containing 2 elements:
- resource type equivalent to `<resource-type>` of the target entity.
- resource ID euivalen to `<resource-id>` of the target entity.
## Unpaged search result
**Description**
A result of search operation that doesn't involve paging.
**Structure**
```json5
{
"results": [
<resource>,
<resource>,
<resource>
]
}
```
**Field meaning**
- `<resource>`: any resource - which exactly depends on the API call. For
details on this field, check the documentation for given API call.
## Paged search result
**Description**
A result of search operation that involves paging.
**Structure**
```json5
{
"query": <query>, // same as in input
"offset": <offset>, // same as in input
"limit": <page-size>,
"total": <total-count>,
"results": [
<resource>,
<resource>,
<resource>
]
}
```
**Field meaning**
- `<query>`: the query passed in the original request that contains standard
[search query](#search).
- `<offset>`: the record starting offset, passed in the original request.
- `<page-size>`: number of records on one page.
- `<total-count>`: how many resources were found. To get the page count, divide
this number by `<page-size>`.
- `<resource>`: any resource - which exactly depends on the API call. For
details on this field, check the documentation for given API call.
## Image search result
**Description**
A result of reverse image search operation.
**Structure**
```json5
{
"exactPost": <exact-post>,
"similarPosts": [
{
"distance": <distance>,
"post": <similar-post>
},
{
"distance": <distance>,
"post": <similar-post>
},
...
]
}
```
**Field meaning**
- `exact-post`: a [post resource](#post) that is exact byte-to-byte duplicate
of the input file. May be `null`.
- `<similar-post>`: a [post resource](#post) that isn't exact duplicate, but
visually resembles the input file. Works only on images and animations, i.e.
does not work for videos and Flash movies. For non-images and corrupted
images, this list is empty.
- `<distance>`: distance from the original image (0..1). The lower this value
is, the more similar the post is.
# Search
Search queries are built of tokens that are separated by spaces. Each token can
be of following form:
| Syntax | Token type | Description |
| ----------------- | ----------------- | ------------------------------------------ |
| `<value>` | anonymous tokens | basic filters |
| `<key>:<value>` | named tokens | advanced filters |
| `sort:<style>` | sort style tokens | sort the results |
| `special:<value>` | special tokens | filters usually tied to the logged in user |
Most of anonymous and named tokens support ranged and composite values that
take following form:
| `<value>` | Description |
| --------- | ----------------------------------------------------- |
| `a,b,c` | will show things that satisfy either `a`, `b` or `c`. |
| `1..` | will show things that are equal to or greater than 1. |
| `..4` | will show things that are equal to at most 4. |
| `1..4` | will show things that are equal to 1, 2, 3 or 4. |
Ranged values can be also supplied by appending `-min` or `-max` to the key,
for example like this: `score-min:1`.
Date/time values can be of following form:
- `today`
- `yesterday`
- `<year>`
- `<year>-<month>`
- `<year>-<month>-<day>`
Some fields, such as user names, can take wildcards (`*`).
You can escape special characters such as `:` and `-` by prepending them with a
backslash: `\\`.
**Example**
Searching for posts with following query:
sea -fav-count:8.. type:swf uploader:Pirate
will show flash files tagged as sea, that were liked by seven people at most,
uploaded by user Pirate.
Searching for posts with `re:zero` will show an error message about unknown
named token.
Searching for posts with `re\:zero` will show posts tagged with `re:zero`.
|