sylvia-iot-broker 0.1.6

The message broker module of the Sylvia-IoT platform.
Documentation
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
API - Broker
============

## Contents

- [Notes]#notes
- [Common error codes]#errcode
- [Roles]#roles
- [Service APIs]#service
    - [`GET /version` Get service version]#get_version
- [Unit APIs]#unit
    - [`POST /broker/api/v1/unit` Create unit]#post_unit
    - [`GET /broker/api/v1/unit/count` Unit count]#get_unit_count
    - [`GET /broker/api/v1/unit/list` Unit list]#get_unit_list
    - [`GET /broker/api/v1/unit/{unitId}` Get unit information]#get_unit
    - [`PATCH /broker/api/v1/unit/{unitId}` Update unit information]#patch_unit
    - [`DELETE /broker/api/v1/unit/{unitId}` Delete unit]#delete_unit
    - [`DELETE /broker/api/v1/unit/user/{userId}` Delete user units]#delete_unit_user
- [Application APIs]#application
    - [`POST /broker/api/v1/application` Create application]#post_application
    - [`GET /broker/api/v1/application/count` Application count]#get_application_count
    - [`GET /broker/api/v1/application/list` Application list]#get_application_list
    - [`GET /broker/api/v1/application/{applicationId}` Get application information]#get_application
    - [`PATCH /broker/api/v1/application/{applicationId}` Update application information]#patch_application
    - [`DELETE /broker/api/v1/application/{applicationId}` Delete application]#delete_application
- [Network APIs]#network
    - [`POST /broker/api/v1/network` Create network]#post_network
    - [`GET /broker/api/v1/network/count` Network count]#get_network_count
    - [`GET /broker/api/v1/network/list` Network list]#get_network_list
    - [`GET /broker/api/v1/network/{networkId}` Get network information]#get_network
    - [`PATCH /broker/api/v1/network/{networkId}` Update network information]#patch_network
    - [`DELETE /broker/api/v1/network/{networkId}` Delete network]#delete_network
- [Device APIs]#device
    - [`POST /broker/api/v1/device` Create device]#post_device
    - [`POST /broker/api/v1/device/bulk` Bulk creating devices]#post_device_bulk
    - [`POST /broker/api/v1/device/bulk-delete` Bulk deleting devices]#post_device_bulk_del
    - [`POST /broker/api/v1/device/range` Bulk creating devices with address range]#post_device_range
    - [`POST /broker/api/v1/device/range-delete` Bulk deleting devices with address range]#post_device_range_del
    - [`GET /broker/api/v1/device/count` Device count]#get_device_count
    - [`GET /broker/api/v1/device/list` Device list]#get_device_list
    - [`GET /broker/api/v1/device/{deviceId}` Get device information]#get_device
    - [`PATCH /broker/api/v1/device/{deviceId}` Update device information]#patch_device
    - [`DELETE /broker/api/v1/device/{deviceId}` Delete device]#delete_device
- [Device route APIs]#device_route
    - [`POST /broker/api/v1/device-route` Create device route]#post_device_route
    - [`POST /broker/api/v1/device-route/bulk` Bulk creating device routes]#post_device_route_bulk
    - [`POST /broker/api/v1/device-route/bulk-delete` Bulk deleting device routes]#post_device_route_bulk_del
    - [`POST /broker/api/v1/device-route/range` Bulk creating device routes with address range]#post_device_route_range
    - [`POST /broker/api/v1/device-route/range-delete` Bulk deleting device routes with address range]#post_device_route_range_del
    - [`GET /broker/api/v1/device-route/count` Device route count]#get_device_route_count
    - [`GET /broker/api/v1/device-route/list` Device route list]#get_device_route_list
    - [`DELETE /broker/api/v1/device-route/{routeId}` Delete device route]#delete_device_route
- [Network route APIs]#network_route
    - [`POST /broker/api/v1/network-route` Create network route]#post_network_route
    - [`GET /broker/api/v1/network-route/count` Network route count]#get_network_route_count
    - [`GET /broker/api/v1/network-route/list` Network route list]#get_network_route_list
    - [`DELETE /broker/api/v1/network-route/{routeId}` Delete network route]#delete_network_route
- [Downlink data buffer APIs]#dldata_buffer
    - [`GET /broker/api/v1/dldata-buffer/count` Downlink data buffer count]#get_dldata_buffer_count
    - [`GET /broker/api/v1/dldata-buffer/list` Downlink data buffer list]#get_dldata_buffer_list
    - [`DELETE /broker/api/v1/dldata-buffer/{dataId}` Delete downlink data buffer]#delete_dldata_buffer

## <a name="notes"></a>Notes

All API requests (except `GET /version`) must have a **Authorization** header with a **Bearer** token.

- **Example**

    ```http
    GET /broker/api/v1/unit/list HTTP/1.1
    Host: localhost
    Authorization: Bearer 766f29fa8691c81b749c0f316a7af4b7d303e45bf4000fe5829365d37caec2a4
    ```

All APIs may respond one of the following status codes:

- **200 OK**: The request is success with body.
- **204 No Content**: The request is success without body.
- **400 Bad Request**: The API request has something wrong.
- **401 Unauthorized**: The access token is invalid or expired.
- **403 Forbidden**: The user does not have the permission to operate APIs.
- **404 Not Found**: The resource (in path) does not exist.
- **500 Internal Server Error**: The server is crash or get an unknown error. You should respond to the system administrators to solve the problem.
- **503 Service Unavailable**: The server has something wrong. Please try again later.

All error responses have the following parameters in JSON format string:

- *string* `code`: The error code.
- *string* `message`: (**optional**) The error message.

- **Example**

    ```http
    HTTP/1.1 401 Unauthorized
    Access-Control-Allow-Origin: *
    Content-Type: application/json
    Content-Length: 70
    ETag: W/"43-Npr+dy47IJFtraEIw6D8mYLw7Ws"
    Date: Thu, 13 Jan 2022 07:46:09 GMT
    Connection: keep-alive

    {"code":"err_auth","message":"Invalid token: access token is invalid"}
    ```

All APIs except [Create unit](#post_unit) can be used by unit owners.
- Only `GET` APIs are available for unit members.
- System administrators and managers (role with **admin** and **manager**) can manage all unit resources.
- Unit owners and members can only manage their unit resources.

## <a name="errcode"></a>Common error codes

The following are common error codes. The API specific error codes are listed in each API response documents.

- **401** `err_auth`: Authorization code error. Please refresh a new token.
- **503** `err_db`: Database operation error. Please try again later.
- **503** `err_intmsg`: Inter-service communication error. Please try again later.
- **404** `err_not_found`: The request resource (normally in path) not found.
- **400** `err_param`: Request input format error. Please check request parameters.
- **403** `err_perm`: Permission fail. This usually means that API requests with an invalid user role.
- **503** `err_rsc`: Resource allocation error. Please try again later.
- **500** `err_unknown`: Unknown error. This usually means that the server causes bugs or unexpected errors.

## <a name="roles"></a>Roles

This system supports the following roles:

- `admin`: The system administrator.
- `manager`: The system manager who acts as admin to view/edit all units' data.
- `service`: The web service.

**Normal user** means users without any roles.

# <a name="service"></a>Service APIs

## <a name="get_version"></a>Get service version

Get service name and version information.

    GET /version?
        q={query}

- *string* `q`: (**optional**) To query the specific information **in plain text**. You can use:
    - `name`: To query the service name.
    - `version`: To query current version.

#### Response

- **200 OK**: Version information. Parameters are:

    - *object* `data`:
        - *string* `name`: The service name.
        - *string* `version`: Current version.

    - **Example**

        ```json
        {
            "data": {
                "name": "sylvia-iot-broker",
                "version": "1.0.0"
            }
        }
        ```

    - **Example** when `q=name`:

        ```
        sylvia-iot-broker
        ```

    - **Example** when `q=version`:

        ```
        1.0.0
        ```

# <a name="unit"></a>Unit APIs

The following API can be only used by system administrators or managers:
- `DELETE /broker/api/v1/unit/user/{userId}`

## <a name="post_unit"></a>Create unit

Create a unit. The user who use this API will be the owner of the unit.

    POST /broker/api/v1/unit

#### Additional HTTP Headers

    Content-Type: application/json

#### Parameters

- *object* `data`:
    - *string* `code`: Unit code. The pattern is `[A-Za-z0-9]{1}[A-Za-z0-9-_]*`. This code will be transformed to lowercase.
    - *string* `ownerId`: (**optional for admin and manager**) The specified user ID for this unit.
    - *string* `name`: (**optional**) Display name.
    - *object* `info`: (**optional**) Other information.

- **Example**

    ```json
    {
        "data": {
            "code": "sylvia",
            "name": "Sylvia unit",
            "info": {
                "address": "Mt. Sylvia"
            }
        }
    }
    ```

#### Response

- **200 OK**: The unit ID. Parameters are:

    - *object* `data`:
        - *string* `unitId`: The ID of the created unit.

    - **Example**

        ```json
        {
            "data": {
                "unitId": "1640923958516-qvdFNpOV"
            }
        }
        ```

- **400 Bad Request**: the special error codes are:
    - `err_broker_owner_not_exist`: The specified owner does not exist.
    - `err_broker_unit_exist`: The unit code has been used.
- **401, 403, 500, 503**: See [Notes]#notes.

## <a name="get_unit_count"></a>Unit count

Get unit list count.

    GET /broker/api/v1/unit/count?
        owner={specifiedOwnerId}&
        member={specifiedMemberId}&
        contains={word}

- *string* `owner`: (**optional for admin and manager**) To search units of the specified owner user ID.
- *string* `member`: (**optional for admin and manager**) To search units of the specified member user ID.
- *string* `contains`: (**optional**) To search codes which contain the specified word. This is case insensitive.

#### Response

- **200 OK**: Unit list count. Parameters are:

    - *object* `data`:
        - *number* `count`: Unit list count.

    - **Example**

        ```json
        {
            "data": {
                "count": 1
            }
        }
        ```

- **400, 401, 403, 500, 503**: See [Notes]#notes.

## <a name="get_unit_list"></a>Unit list

Get unit list.

    GET /broker/api/v1/unit/list?
        owner={specifiedOwnerId}&
        member={specifiedMemberId}&
        contains={word}&
        offset={offset}&
        limit={limit}&
        sort={sortKeysAndOrders}&
        format={responseFormat}

- *string* `owner`: (**optional for admin and manager**) To search units of the specified owner user ID.
- *string* `member`: (**optional for admin and manager**) To search units of the specified member user ID.
- *string* `contains`: (**optional**) To search codes which contain the specified word. This is case insensitive.
- *number* `offset`: (**optional**) Data offset. Default is **0**.
- *number* `limit`: (**optional**) Number of items to list. **0** to list all data. Default is **100**.
- *string* `sort`: (**optional**) To sort the result. Format is `key:[asc|desc]`. The key can be **code**, **created**, **modified**, **name**. Default is **code:asc**.
- *string* `format`: (**optional**) Response body format. Default is array in the **data** field.
    - **array**: The response body is JSON array, not an object.

#### Response

- **200 OK**: An array that contains all units' information. Parameters are:

    - *object[]* `data`:
        - *string* `unitId`: Unit ID.
        - *string* `code`: Unit code.
        - *string* `createdAt`: Creation time in RFC 3339 format.
        - *string* `modifiedAt`: Modification time in RFC 3339 format.
        - *string* `ownerId`: User ID that is the owner of the unit.
        - *string[]* `memberIds`: User IDs who can view the unit's resources (application, network, ...).
        - *string* `name`: Display name.
        - *object* `info`: Other information.

    - **Example**

        ```json
        {
            "data": [
                {
                    "unitId": "1640923958516-qvdFNpOV",
                    "code": "sylvia",
                    "createdAt": "2021-12-31T04:12:38.516Z",
                    "modifiedAt": "2021-12-31T04:12:38.516Z",
                    "ownerId": "1640921188987-x51FTVPD",
                    "memberIds": [
                        "1640921188987-x51FTVPD",
                        "1641003827053-c2e84RJO"
                    ],
                    "name": "Sylvia unit",
                    "info": {
                        "address": "Mt. Sylvia"
                    }
                }
            ]
        }
        ```

    - **Example (format=`array`)**

        ```json
        [
            {
                "unitId": "1640923958516-qvdFNpOV",
                "code": "sylvia",
                "createdAt": "2021-12-31T04:12:38.516Z",
                "modifiedAt": "2021-12-31T04:12:38.516Z",
                "ownerId": "1640921188987-x51FTVPD",
                "memberIds": [
                    "1640921188987-x51FTVPD",
                    "1641003827053-c2e84RJO"
                ],
                "name": "Sylvia unit",
                "info": {
                    "address": "Mt. Sylvia"
                }
            }
        ]
        ```

- **400, 401, 403, 500, 503**: See [Notes]#notes.

## <a name="get_unit"></a>Get unit information

Get the specified unit information.

    GET /broker/api/v1/unit/{unitId}

- *string* `unitId`: The specified unit ID to get unit information.

#### Response

- **200 OK**:

    - *object* `data`: An object that contains the unit information. See [Unit APIs - Unit list]#get_unit_list.

- **400, 401, 403, 500, 503**: See [Notes]#notes.
- **404 Not Found**: The specified unit does not exist.

## <a name="patch_unit"></a>Update unit information

Update the specified unit information.

    PATCH /broker/api/v1/unit/{unitId}

- *string* `unitId`: The specified unit ID to update unit information.

#### Additional HTTP Headers

    Content-Type: application/json

#### Parameters

- *object* `data`:
    - *string* `ownerId`: (**optional for admin and manager**) The user ID of the new owner.
    - *string[]* `memberIds`: (**optional for admin and manager**) The user IDs who can view the unit's resources.
    - *string* `name`: (**optional**) The display name.
    - *object* `info`: (**optional**) Other information. You must provide full of fields, or all fields will be replaced with the new value.

- **Note**: You must give at least one parameter.

- **Example**

    ```json
    {
        "data": {
            "name": "Sylvia depart",
            "info": {
                "contact": "Sylvia depart's contact",
                "address": "Mt. Sylvia"
            }
        }
    }
    ```

#### Response

- **204 No Content**
- **400 Bad Request**: the special error codes are:
    - `err_broker_owner_not_exist`: The specified owner does not exist.
    - `err_broker_member_not_exist`: The specified member(s) does not exist.
- **401, 403, 500, 503**: See [Notes]#notes.
- **404 Not Found**: The specified unit does not exist.

## <a name="delete_unit"></a>Delete unit

Delete a unit and its own resources.

    DELETE /broker/api/v1/unit/{unitId}

- *string* `unitId`: The specified unit ID to delete.

#### Response

- **204 No Content**
- **401, 403, 500, 503**: See [Notes]#notes.
- **404 Not Found**: The specified unit does not exist.

## <a name="delete_unit_user"></a>Delete user units

Delete all units and their resources of the specified owner.

    DELETE /auth/api/v1/unit/user/{userId}

- *string* `userId`: The specified user ID of units' owner.

#### Response

- **204 No Content**
- **400, 401, 403, 500, 503**: See [Notes]#notes.
- **404 Not Found**: The specified user does not exist.

# <a name="application"></a>Application APIs

## <a name="post_application"></a>Create application

Create an application.

    POST /broker/api/v1/application

#### Additional HTTP Headers

    Content-Type: application/json

#### Parameters

- *object* `data`:
    - *string* `code`: Application code for queues. The pattern is `[A-Za-z0-9]{1}[A-Za-z0-9-_]*`. This code will be transformed to lowercase.
    - *string* `unitId`: The associated unit ID.
    - *string* `hostUri`: The application queue URI.
    - *string* `name`: (**optional**) Display name.
    - *object* `info`: (**optional**) Other information.

- **Example**

    ```json
    {
        "data": {
            "code": "tracker",
            "unitId": "1640923958516-qvdFNpOV",
            "hostUri": "amqp://localhost/sylvia",
            "name": "Position tracker application",
            "info": {
                "description": "This is the position tracker application with maps"
            }
        }
    }
    ```

#### Response

- **200 OK**: The application ID. Parameters are:

    - *object* `data`:
        - *string* `applicationId`: The ID of the created application.

    - **Example**

        ```json
        {
            "data": {
                "applicationId": "1640924063709-rmJIxW0s"
            }
        }
        ```

- **400 Bad Request**: the special error codes are:
    - `err_broker_unit_not_exist`: The unit does not exist.
    - `err_broker_application_exist`: The application code has been used.
- **401, 403, 500, 503**: See [Notes]#notes.

## <a name="get_application_count"></a>Application count

Get application list count.

    GET /broker/api/v1/application/count?
        unit={specifiedUnitId}&
        code={specifiedCode}&
        contains={word}

- *string* `unit`: (**required for normal user**) To search applications of the specified unit ID.
- *string* `code`: (**optional**) To search the specified code. This is case insensitive and excludes **contains**.
- *string* `contains`: (**optional**) To search codes which contain the specified word. This is case insensitive.

#### Response

- **200 OK**: Application list count. Parameters are:

    - *object* `data`:
        - *number* `count`: Application list count.

    - **Example**

        ```json
        {
            "data": {
                "count": 2
            }
        }
        ```

- **400 Bad Request**: the special error codes are:
    - `err_broker_unit_not_exist`: The unit does not exist.
- **401, 403, 500, 503**: See [Notes]#notes.

## <a name="get_application_list"></a>Application list

Get application list.

    GET /broker/api/v1/application/list?
        unit={specifiedUnitId}&
        code={specifiedCode}&
        contains={word}&
        offset={offset}&
        limit={limit}&
        sort={sortKeysAndOrders}&
        format={responseFormat}

- *string* `unit`: (**required for normal user**) To search applications of the specified unit ID.
- *string* `code`: (**optional**) To search the specified code. This is case insensitive and excludes **contains**.
- *string* `contains`: (**optional**) To search codes which contain the specified word. This is case insensitive.
- *number* `offset`: (**optional**) Data offset. Default is **0**.
- *number* `limit`: (**optional**) Number of items to list. **0** to list all data. Default is **100**.
- *string* `sort`: (**optional**) To sort the result. Format is `key:[asc|desc]`. The key can be **code**, **created**, **modified**, **name**. Default is **code:asc**.
- *string* `format`: (**optional**) Response body format. Default is array in the **data** field.
    - **array**: The response body is JSON array, not an object.

#### Response

- **200 OK**: An array that contains all applications' information. Parameters are:

    - *object[]* `data`:
        - *string* `applicationId`: Application ID.
        - *string* `code`: Application code for queues.
        - *string* `unitId`: The associated unit ID.
        - *string* `unitCode`: The associated unit code.
        - *string* `createdAt`: Creation time in RFC 3339 format.
        - *string* `modifiedAt`: Modification time in RFC 3339 format.
        - *string* `hostUri`: The application queue URI.
        - *string* `name`: Display name.
        - *object* `info`: Other information.

    - **Example**

        ```json
        {
            "data": [
                {
                    "applicationId": "1640924152438-eVJe8UhY",
                    "code": "meter",
                    "unitId": "1640923958516-qvdFNpOV",
                    "unitCode": "sylvia",
                    "createdAt": "2021-12-31T04:15:52.438Z",
                    "modifiedAt": "2021-12-31T04:15:52.438Z",
                    "hostUri": "amqp://localhost/sylvia",
                    "name": "Meter application",
                    "info": {
                        "description": "This is the meter program"
                    }
                },
                {
                    "applicationId": "1640924063709-rmJIxW0s",
                    "code": "tracker",
                    "unitId": "1640923958516-qvdFNpOV",
                    "unitCode": "sylvia",
                    "createdAt": "2021-12-31T04:14:23.709Z",
                    "modifiedAt": "2021-12-31T04:14:23.709Z",
                    "hostUri": "amqp://localhost/sylvia",
                    "name": "Position tracker application",
                    "info": {
                        "description": "This is the position tracker application with maps"
                    }
                }
            ]
        }
        ```

    - **Example (format=`array`)**

        ```json
        [
            {
                "applicationId": "1640924152438-eVJe8UhY",
                "code": "meter",
                "unitId": "1640923958516-qvdFNpOV",
                "unitCode": "sylvia",
                "createdAt": "2021-12-31T04:15:52.438Z",
                "modifiedAt": "2021-12-31T04:15:52.438Z",
                "hostUri": "amqp://localhost/sylvia",
                "name": "Meter application",
                "info": {
                    "description": "This is the meter program"
                }
            },
            {
                "applicationId": "1640924063709-rmJIxW0s",
                "code": "tracker",
                "unitId": "1640923958516-qvdFNpOV",
                "unitCode": "sylvia",
                "createdAt": "2021-12-31T04:14:23.709Z",
                "modifiedAt": "2021-12-31T04:14:23.709Z",
                "hostUri": "amqp://localhost/sylvia",
                "name": "Position tracker application",
                "info": {
                    "description": "This is the position tracker application with maps"
                }
            }
        ]
        ```

- **400 Bad Request**: the special error codes are:
    - `err_broker_unit_not_exist`: The unit does not exist.
- **401, 403, 500, 503**: See [Notes]#notes.

## <a name="get_application"></a>Get application information

Get the specified application information.

    GET /broker/api/v1/application/{applicationId}

- *string* `applicationId`: The specified application ID to get application information.

#### Response

- **200 OK**:

    - *object* `data`: An object that contains the application information. See [Application APIs - Application list]#get_application_list.

- **400, 401, 403, 500, 503**: See [Notes]#notes.
- **404 Not Found**: The specified application does not exist.

## <a name="patch_application"></a>Update application information

Update the specified application information.

    PATCH /broker/api/v1/application/{applicationId}

- *string* `applicationId`: The specified application ID to update application information.

#### Additional HTTP Headers

    Content-Type: application/json

#### Parameters

- *object* `data`:
    - *string* `hostUri`: (**optional**) The application queue URI. Changing this value will reconnect to the new message queue.
    - *string* `name`: (**optional**) The display name.
    - *object* `info`: (**optional**) Other information. You must provide full of fields, or all fields will be replaced with the new value.

- **Note**: You must give at least one parameter.

- **Example**

    ```json
    {
        "data": {
            "hostUri": "amqp://192.168.1.1/sylvia",
            "name": "The tracker v2 application",
            "info": {
                "description": "The version 2 tracker application",
                "changelog": "add altitude"
            }
        }
    }
    ```

#### Response

- **204 No Content**
- **400, 401, 403, 500, 503**: See [Notes]#notes.
- **404 Not Found**: The specified application does not exist.

## <a name="delete_application"></a>Delete application

Delete an application and its own resources.

    DELETE /broker/api/v1/application/{applicationId}

- *string* `applicationId`: The specified application ID to delete.

#### Response

- **204 No Content**
- **401, 403, 500, 503**: See [Notes]#notes.

# <a name="network"></a>Network APIs

## <a name="post_network"></a>Create network

Create a network.

    POST /broker/api/v1/network

#### Additional HTTP Headers

    Content-Type: application/json

#### Parameters

- *object* `data`:
    - *string* `code`: Network code for queues. The pattern is `[A-Za-z0-9]{1}[A-Za-z0-9-_]*`. This code will be transformed to lowercase.
    - *string | null* `unitId`: The associated unit ID for private network.
        - **null**: (**for admin or manager only**) the public network.
    - *string* `hostUri`: The network queue URI.
    - *string* `name`: (**optional**) Display name.
    - *object* `info`: (**optional**) Other information.

- **Example**

    ```json
    {
        "data": {
            "code": "lora",
            "unitId": "1640923958516-qvdFNpOV",
            "hostUri": "amqp://localhost/sylvia",
            "name": "Sylvia unit's private LoRa network",
            "info": {
                "description": "This is the private LoRa network"
            }
        }
    }
    ```

#### Response

- **200 OK**: The network ID. Parameters are:

    - *object* `data`:
        - *string* `networkId`: The ID of the created network.

    - **Example**

        ```json
        {
            "data": {
                "networkId": "1640924173420-BNg2lwo3"
            }
        }
        ```

- **400 Bad Request**: the special error codes are:
    - `err_broker_unit_not_exist`: The unit does not exist.
    - `err_broker_network_exist`: The network code has been used.
- **401, 403, 500, 503**: See [Notes]#notes.

## <a name="get_network_count"></a>Network count

Get network list count.

    GET /broker/api/v1/network/count?
        unit={specifiedUnitId}&
        code={specifiedCode}&
        contains={word}

- *string* `unit`: (**required for normal user**) To search networks of the specified unit ID.
    - (**for admin or manager only**) Empty string for get public network only.
- *string* `code`: (**optional**) To search the specified code. This is case insensitive and excludes **contains**.
- *string* `contains`: (**optional**) To search codes which contain the specified word. This is case insensitive.

#### Response

- **200 OK**: Network list count. Parameters are:

    - *object* `data`:
        - *number* `count`: Network list count.

    - **Example**

        ```json
        {
            "data": {
                "count": 2
            }
        }
        ```

- **400, 401, 403, 500, 503**: See [Notes]#notes.

## <a name="get_network_list"></a>Network list

Get network list.

    GET /broker/api/v1/network/list?
        unit={specifiedUnitId}&
        code={specifiedCode}&
        contains={word}&
        offset={offset}&
        limit={limit}&
        sort={sortKeysAndOrders}&
        format={responseFormat}

- *string* `unit`: (**required for normal user**) To search networks of the specified unit ID.
    - (**for admin or manager only**) Empty string for get public network only.
- *string* `code`: (**optional**) To search the specified code. This is case insensitive and excludes **contains**.
- *string* `contains`: (**optional**) To search codes which contain the specified word. This is case insensitive.
- *number* `offset`: (**optional**) Data offset. Default is **0**.
- *number* `limit`: (**optional**) Number of items to list. **0** to list all data. Default is **100**.
- *string* `sort`: (**optional**) To sort the result. Format is `key:[asc|desc]`. The key can be **code**, **created**, **modified**, **name**. Default is **code:asc**.
- *string* `format`: (**optional**) Response body format. Default is array in the **data** field.
    - **array**: The response body is JSON array, not an object.

#### Response

- **200 OK**: An array that contains all networks' information. Parameters are:

    - *object[]* `data`:
        - *string* `networkId`: Network ID.
        - *string* `code`: Network code for queues.
        - *string | null* `unitId`: The associated unit ID for private network or **null** means public network.
        - *string | null* `unitCode`: The associated unit code.
        - *string* `createdAt`: Creation time in RFC 3339 format.
        - *string* `modifiedAt`: Modification time in RFC 3339 format.
        - *string* `hostUri`: The network queue URI.
        - *string* `name`: Display name.
        - *object* `info`: Other information.

    - **Example**

        ```json
        {
            "data": [
                {
                    "networkId": "1640924173420-BNg2lwo3",
                    "code": "lora",
                    "unitId": "1640923958516-qvdFNpOV",
                    "unitCode": "sylvia",
                    "createdAt": "2021-12-31T04:16:13.420Z",
                    "modifiedAt": "2021-12-31T04:16:13.420Z",
                    "hostUri": "amqp://localhost/sylvia",
                    "name": "Sylvia unit's private LoRa network",
                    "info": {
                        "description": "This is the private LoRa network"
                    }
                },
                {
                    "networkId": "1640924213217-oDwwyNK3",
                    "code": "zigbee",
                    "unitId": null,
                    "unitCode": null,
                    "createdAt": "2021-12-31T04:16:53.217Z",
                    "modifiedAt": "2021-12-31T04:16:53.217Z",
                    "hostUri": "amqp://localhost/sylvia",
                    "name": "Public Zigbee network",
                    "info": {
                        "description": "This is the public Zigbee network"
                    }
                }
            ]
        }
        ```

    - **Example (format=`array`)**

        ```json
        [
            {
                "networkId": "1640924173420-BNg2lwo3",
                "code": "lora",
                "unitId": "1640923958516-qvdFNpOV",
                "unitCode": "sylvia",
                "createdAt": "2021-12-31T04:16:13.420Z",
                "modifiedAt": "2021-12-31T04:16:13.420Z",
                "hostUri": "amqp://localhost/sylvia",
                "name": "Sylvia unit's private LoRa network",
                "info": {
                    "description": "This is the private LoRa network"
                }
            },
            {
                "networkId": "1640924213217-oDwwyNK3",
                "code": "zigbee",
                "unitId": null,
                "unitCode": null,
                "createdAt": "2021-12-31T04:16:53.217Z",
                "modifiedAt": "2021-12-31T04:16:53.217Z",
                "hostUri": "amqp://localhost/sylvia",
                "name": "Public Zigbee network",
                "info": {
                    "description": "This is the public Zigbee network"
                }
            }
        ]
        ```

- **400 Bad Request**: the special error codes are:
    - `err_broker_unit_not_exist`: The unit does not exist.
- **401, 403, 500, 503**: See [Notes]#notes.

## <a name="get_network"></a>Get network information

Get the specified network information.

    GET /broker/api/v1/network/{networkId}

- *string* `networkId`: The specified network ID to get network information.

#### Response

- **200 OK**:

    - *object* `data`: An object that contains the network information. See [Network APIs - Network list]#get_network_list.

- **400, 401, 403, 500, 503**: See [Notes]#notes.
- **404 Not Found**: The specified network does not exist.

## <a name="patch_network"></a>Update network information

Update the specified network information.

    PATCH /broker/api/v1/network/{networkId}

- *string* `networkId`: The specified network ID to update network information.

#### Additional HTTP Headers

    Content-Type: application/json

#### Parameters

- *object* `data`:
    - *string* `hostUri`: (**optional**) The network queue URI. Changing this value will reconnect to the new message queue.
    - *string* `name`: (**optional**) The display name.
    - *object* `info`: (**optional**) Other information. You must provide full of fields, or all fields will be replaced with the new value.

- **Note**: You must give at least one parameter.

- **Example**

    ```json
    {
        "data": {
            "hostUri": "amqp://192.168.1.1/sylvia",
            "name": "The OpenLoRa network server",
            "info": {
                "changelog": "upgrade LoRa network server"
            }
        }
    }
    ```

#### Response

- **204 No Content**
- **400, 401, 403, 500, 503**: See [Notes]#notes.
- **404 Not Found**: The specified network does not exist.

## <a name="delete_network"></a>Delete network

Delete a network and its own resources.

    DELETE /broker/api/v1/network/{networkId}

- *string* `networkId`: The specified network ID to delete.

#### Response

- **204 No Content**
- **401, 403, 500, 503**: See [Notes]#notes.

# <a name="device"></a>Device APIs

## <a name="post_device"></a>Create device

Create a device.

    POST /broker/api/v1/device

#### Additional HTTP Headers

    Content-Type: application/json

#### Parameters

- *object* `data`:
    - *string* `unitId`: The associated unit ID.
    - *string* `networkId`: The associated network ID. The public network can be assigned by **admin** or **manager**.
    - *string* `networkAddr`: The network address of the specified network. This will be transformed to lowercase.
    - *string* `profile`: (**optional**) Device profile that is used for application servers to identify data content. The pattern is empty or `[A-Za-z0-9]{1}[A-Za-z0-9-_]*`. This will be transformed to lowercase.
    - *string* `name`: (**optional**) Display name.
    - *object* `info`: (**optional**) Other information.

- **Example**

    ```json
    {
        "data": {
            "unitId": "1640923958516-qvdFNpOV",
            "networkId": "1640924173420-BNg2lwo3",
            "networkAddr": "800012ae",
            "profile": "tracker",
            "name": "Mt. Sylvia tracker",
            "info": {
                "latitude": "24.38349800818775",
                "longitude": "121.22999674970842"
            }
        }
    }
    ```

#### Response

- **200 OK**: The device ID. Parameters are:

    - *object* `data`:
        - *string* `deviceId`: The ID of the created device.

    - **Example**

        ```json
        {
            "data": {
                "deviceId": "1640924274329-yESwHhKO"
            }
        }
        ```

- **400 Bad Request**: the special error codes are:
    - `err_broker_unit_not_exist`: The unit does not exist.
    - `err_broker_network_not_exist`: The network does not exist.
    - `err_broker_network_addr_exist`: The network address has been used.
- **401, 403, 500, 503**: See [Notes]#notes.

## <a name="post_device_bulk"></a>Bulk creating devices

Create devices in bulk.

    POST /broker/api/v1/device/bulk

Notes:
- Devices created earlier will be skipped.
- **name** will be the network address.
- Maximum 1024 devices.

#### Additional HTTP Headers

    Content-Type: application/json

#### Parameters

- *object* `data`:
    - *string* `unitId`: The associated unit ID.
    - *string* `networkId`: The associated network ID. The public network can be assigned by **admin** or **manager**.
    - *string[]* `networkAddrs`: The network addresses of the specified network. This will be transformed to lowercase.
    - *string* `profile`: (**optional**) Device profile that is used for application servers to identify data content. The pattern is empty or `[A-Za-z0-9]{1}[A-Za-z0-9-_]*`. This will be transformed to lowercase.

- **Example**

    ```json
    {
        "data": {
            "unitId": "1640923958516-qvdFNpOV",
            "networkId": "1640924173420-BNg2lwo3",
            "networkAddrs": [
                "800012ae",
                "8000257f",
                "800022f3"
            ],
            "profile": ""
        }
    }
    ```

#### Response

- **204 No Content**
- **400 Bad Request**: the special error codes are:
    - `err_broker_unit_not_exist`: The unit does not exist.
    - `err_broker_network_not_exist`: The network does not exist.
- **401, 403, 500, 503**: See [Notes]#notes.

## <a name="post_device_bulk_del"></a>Bulk deleting devices

Delete devices in bulk.

    POST /broker/api/v1/device/bulk-delete

Notes:
- Maximum 1024 devices.

#### Additional HTTP Headers

    Content-Type: application/json

#### Parameters

- *object* `data`:
    - *string* `unitId`: The associated unit ID.
    - *string* `networkId`: The associated network ID. The public network can be assigned by **admin** or **manager**.
    - *string[]* `networkAddrs`: The network addresses of the specified network. This will be transformed to lowercase.

- **Example**

    ```json
    {
        "data": {
            "unitId": "1640923958516-qvdFNpOV",
            "networkId": "1640924173420-BNg2lwo3",
            "networkAddrs": [
                "800012ae",
                "8000257f",
                "800022f3"
            ]
        }
    }
    ```

#### Response

- **204 No Content**
- **400 Bad Request**: the special error codes are:
    - `err_broker_unit_not_exist`: The unit does not exist.
    - `err_broker_network_not_exist`: The network does not exist.
- **401, 403, 500, 503**: See [Notes]#notes.

## <a name="post_device_range"></a>Bulk creating devices with address range

Create devices in bulk with address range.

    POST /broker/api/v1/device/range

Notes:
- Devices created earlier will be skipped.
- **name** will be the network address.
- Maximum 1024 devices (0x400).
- `startAddrs` and `endAddrs` must be hexadecimal string with the same (even) length.
- Strings up to 32 bytes (128 bits) are supported.

#### Additional HTTP Headers

    Content-Type: application/json

#### Parameters

- *object* `data`:
    - *string* `unitId`: The associated unit ID.
    - *string* `networkId`: The associated network ID. The public network can be assigned by **admin** or **manager**.
    - *string* `startAddr`: The start network address of the specified network.
    - *string* `endAddr`: The end network address of the specified network.
    - *string* `profile`: (**optional**) The device profile that is used for application servers to identify data content. The pattern is empty or `[A-Za-z0-9]{1}[A-Za-z0-9-_]*`. This will be transformed to lowercase.

- **Example**

    ```json
    {
        "data": {
            "unitId": "1640923958516-qvdFNpOV",
            "networkId": "1640924173420-BNg2lwo3",
            "startAddr": "80001000",
            "endAddr": "800013ff",
            "profile": "tracker"
        }
    }
    ```

#### Response

- **204 No Content**
- **400 Bad Request**: the special error codes are:
    - `err_broker_unit_not_exist`: The unit does not exist.
    - `err_broker_network_not_exist`: The network does not exist.
- **401, 403, 500, 503**: See [Notes]#notes.

## <a name="post_device_range_del"></a>Bulk deleting devices with address range

Delete devices in bulk with address range.

    POST /broker/api/v1/device/range-delete

Notes:
- Maximum 1024 devices (0x400).
- `startAddrs` and `endAddrs` must be hexadecimal string with the same (even) length.
- Strings up to 32 bytes (128 bits) are supported.

#### Additional HTTP Headers

    Content-Type: application/json

#### Parameters

- *object* `data`:
    - *string* `unitId`: The associated unit ID.
    - *string* `networkId`: The associated network ID. The public network can be assigned by **admin** or **manager**.
    - *string* `startAddr`: The start network address of the specified network.
    - *string* `endAddr`: The end network address of the specified network.

- **Example**

    ```json
    {
        "data": {
            "unitId": "1640923958516-qvdFNpOV",
            "networkId": "1640924173420-BNg2lwo3",
            "startAddr": "80001000",
            "endAddr": "800013ff"
        }
    }
    ```

#### Response

- **204 No Content**
- **400 Bad Request**: the special error codes are:
    - `err_broker_unit_not_exist`: The unit does not exist.
    - `err_broker_network_not_exist`: The network does not exist.
- **401, 403, 500, 503**: See [Notes]#notes.

## <a name="get_device_count"></a>Device count

Get device list count.

    GET /broker/api/v1/device/count?
        unit={specifiedUnitId}&
        network={specifiedNetworkId}&
        addr={specifiedNetworkAddr}&
        profile={specifiedProfile}&
        contains={word}

- *string* `unit`: (**required for normal user**) To search devices of the specified unit ID.
- *string* `network`: (**optional**) To search devices of the specified network ID.
- *string* `addr`: (**optional**) To search devices of the specified network address. This is case insensitive.
- *string* `profile`: (**optional**) To search devices of the specified profile. This is case insensitive.
- *string* `contains`: (**optional**) To search names which contain the specified word. This is case insensitive.

#### Response

- **200 OK**: Device list count. Parameters are:

    - *object* `data`:
        - *number* `count`: Device list count.

    - **Example**

        ```json
        {
            "data": {
                "count": 2
            }
        }
        ```

- **400 Bad Request**: the special error codes are:
    - `err_broker_unit_not_exist`: The unit does not exist.
- **401, 403, 500, 503**: See [Notes]#notes.

## <a name="get_device_list"></a>Device list

Get device list.

    GET /broker/api/v1/device/list?
        unit={specifiedUnitId}&
        network={specifiedNetworkId}&
        addr={specifiedNetworkAddr}&
        profile={specifiedProfile}&
        contains={word}&
        offset={offset}&
        limit={limit}&
        sort={sortKeysAndOrders}&
        format={responseFormat}

- *string* `unit`: (**required for normal user**) To search devices of the specified unit ID.
- *string* `network`: (**optional**) To search devices of the specified network ID.
- *string* `addr`: (**optional**) To search devices of the specified network address. This is case insensitive.
- *string* `profile`: (**optional**) To search devices of the specified profile. This is case insensitive.
- *string* `contains`: (**optional**) To search names which contain the specified word. This is case insensitive.
- *number* `offset`: (**optional**) Data offset. Default is **0**.
- *number* `limit`: (**optional**) Number of items to list. **0** to list all data. Default is **100**.
- *string* `sort`: (**optional**) To sort the result. Format is `key:[asc|desc]`. The key can be **network**, **addr**, **created**, **modified**, **profile**, **name**. Default is **network:asc,addr:asc**.
- *string* `format`: (**optional**) Response body format. Default is array in the **data** field.
    - **array**: The response body is JSON array, not an object.

#### Response

- **200 OK**: An array that contains all devices' information. Parameters are:

    - *object[]* `data`:
        - *string* `deviceId`: Device ID.
        - *string* `unitId`: The associated unit ID.
        - *string | null* `unitCode`: The associated unit code for private network or **null** means public network.
        - *string* `networkId`: The associated network ID.
        - *string* `networkCode`: The associated network code.
        - *string* `networkAddr`: The associated network address.
        - *string* `createdAt`: Creation time in RFC 3339 format.
        - *string* `modifiedAt`: Modification time in RFC 3339 format.
        - *string* `profile`: The device profile that is used for application servers to identify data content.
        - *string* `name`: Display name.
        - *object* `info`: Other information.

    - **Example**

        ```json
        {
            "data": [
                {
                    "deviceId": "1640924274329-yESwHhKO",
                    "unitId": "1640923958516-qvdFNpOV",
                    "unitCode": "sylvia",
                    "networkId": "1640924173420-BNg2lwo3",
                    "networkCode": "lora",
                    "networkAddr": "800012ae",
                    "createdAt": "2021-12-31T04:17:54.329Z",
                    "modifiedAt": "2021-12-31T04:17:54.329Z",
                    "profile": "tracker",
                    "name": "Mt. Sylvia tracker",
                    "info": {
                        "latitude": "24.38349800818775",
                        "longitude": "121.22999674970842"
                    }
                },
                {
                    "unitId": "1640924263290-Pyc1T5fT",
                    "unitCode": null,
                    "networkId": "1640924213217-oDwwyNK3",
                    "networkCode": "zigbee",
                    "networkAddr": "13a2",
                    "createdAt": "2021-12-31T04:17:43.290Z",
                    "modifiedAt": "2021-12-31T04:17:43.290Z",
                    "profile": "",
                    "name": "Mt. Sylvia meter",
                    "info": {
                        "latitude": "24.38349800818775",
                        "longitude": "121.22999674970842"
                    }
                }
            ]
        }
        ```

    - **Example (format=`array`)**

        ```json
        [
            {
                "deviceId": "1640924274329-yESwHhKO",
                "unitId": "1640923958516-qvdFNpOV",
                "unitCode": "sylvia",
                "networkId": "1640924173420-BNg2lwo3",
                "networkCode": "lora",
                "networkAddr": "800012ae",
                "createdAt": "2021-12-31T04:17:54.329Z",
                "modifiedAt": "2021-12-31T04:17:54.329Z",
                "profile": "tracker",
                "name": "Mt. Sylvia tracker",
                "info": {
                    "latitude": "24.38349800818775",
                    "longitude": "121.22999674970842"
                }
            },
            {
                "deviceId": "1640924263290-Pyc1T5fT",
                "unitId": "1640923958516-qvdFNpOV",
                "unitCode": null,
                "networkId": "1640924213217-oDwwyNK3",
                "networkCode": "zigbee",
                "networkAddr": "13a2",
                "createdAt": "2021-12-31T04:17:43.290Z",
                "modifiedAt": "2021-12-31T04:17:43.290Z",
                "profile": "",
                "name": "Mt. Sylvia meter",
                "info": {
                    "latitude": "24.38349800818775",
                    "longitude": "121.22999674970842"
                }
            }
        ]
        ```

- **400 Bad Request**: the special error codes are:
    - `err_broker_unit_not_exist`: The unit does not exist.
- **401, 403, 500, 503**: See [Notes]#notes.

## <a name="get_device"></a>Get device information

Get the specified device information.

    GET /broker/api/v1/device/{deviceId}

- *string* `deviceId`: The specified device ID to get device information.

#### Response

- **200 OK**:

    - *object* `data`: An object that contains the device information. See [Device APIs - Device list]#get_device_list.

- **400, 401, 403, 500, 503**: See [Notes]#notes.
- **404 Not Found**: The specified device does not exist.

## <a name="patch_device"></a>Update device information

Update the specified device information.

    PATCH /broker/api/v1/device/{deviceId}

- *string* `deviceId`: The specified device ID to update device information.

#### Additional HTTP Headers

    Content-Type: application/json

#### Parameters

- *object* `data`:
    - *string* `networkId`: (**optional**) The associated network ID. The public network can be assigned by **admin** or **manager**.
    - *string* `networkAddr`: (**optional**) The network address of the specified network. This will be transformed to lowercase.
    - *string* `profile`: (**optional**) The device profile. The pattern is empty or `[A-Za-z0-9]{1}[A-Za-z0-9-_]*`. This will be transformed to lowercase.
    - *string* `name`: (**optional**) The display name.
    - *object* `info`: (**optional**) Other information. You must provide full of fields, or all fields will be replaced with the new value.

- **Note**: You must give at least one parameter.

- **Example**

    ```json
    {
        "data": {
            "networkId": "1640924213217-oDwwyNK3",
            "networkAddr": "13a2",
            "profile": "e-meter",
            "name": "Mt. Sylvia e-meter",
            "info": {
                "latitude": "24.38349800818775",
                "longitude": "121.22999674970842",
                "changelog": "upgrade meter Dec 31st"
            }
        }
    }
    ```

#### Response

- **204 No Content**
- **400 Bad Request**: the special error codes are:
    - `err_broker_network_not_exist`: The network does not exist.
    - `err_broker_network_addr_exist`: The network address has been used.
- **401, 403, 500, 503**: See [Notes]#notes.
- **404 Not Found**: The specified device does not exist.

## <a name="delete_device"></a>Delete device

Delete a device and its own resources.

    DELETE /broker/api/v1/device/{deviceId}

- *string* `deviceId`: The specified device ID to delete.

#### Response

- **204 No Content**
- **401, 403, 500, 503**: See [Notes]#notes.

# <a name="device_route"></a>Device route APIs

## <a name="post_device_route"></a>Create device route

Create an device route.

    POST /broker/api/v1/device-route

#### Additional HTTP Headers

    Content-Type: application/json

#### Parameters

- *object* `data`:
    - *string* `deviceId`: The device ID.
    - *string* `applicationId`: The target application ID.

- **Example**

    ```json
    {
        "data": {
            "deviceId": "1640924274329-yESwHhKO",
            "applicationId": "1640924063709-rmJIxW0s"
        }
    }
    ```

#### Response

- **200 OK**: The device ID. Parameters are:

    - *object* `data`:
        - *string* `routeId`: The route ID of the created device route.

    - **Example**

        ```json
        {
            "data": {
                "routeId": "1640924308457-D455ZtkDW033"
            }
        }
        ```

- **400 Bad Request**: the special error codes are:
    - `err_broker_application_not_exist`: The application does not exist.
    - `err_broker_device_not_exist`: The device does not exist.
    - `err_broker_route_exist`: The device route has been created.
    - `err_broker_unit_not_match`: The unit of the device and application is not the same.
- **401, 403, 500, 503**: See [Notes]#notes.

## <a name="post_device_route_bulk"></a>Bulk creating device routes

Create device routes in bulk.

    POST /broker/api/v1/device-route/bulk

Notes:
- Devices routes created earlier will be skipped.
- Maximum 1024 devices.

#### Additional HTTP Headers

    Content-Type: application/json

#### Parameters

- *object* `data`:
    - *string* `applicationId`: The target application ID.
    - *string* `networkId`: The associated network ID. The public network can be assigned by **admin** or **manager**.
    - *string[]* `networkAddrs`: The network addresses of the specified network. This will be transformed to lowercase.

- **Example**

    ```json
    {
        "data": {
            "applicationId": "1640924063709-rmJIxW0s",
            "networkId": "1640924173420-BNg2lwo3",
            "networkAddrs": [
                "800012ae",
                "8000257f",
                "800022f3"
            ]
        }
    }
    ```

#### Response

- **204 No Content**
- **400 Bad Request**: the special error codes are:
    - `err_broker_application_not_exist`: The application does not exist.
    - `err_broker_network_not_exist`: The network does not exist.
    - `err_broker_device_not_exist`: The device does not exist.
- **401, 403, 500, 503**: See [Notes]#notes.

## <a name="post_device_route_bulk_del"></a>Bulk deleting device routes

Delete device routes in bulk.

    POST /broker/api/v1/device-route/bulk-delete

Notes:
- Maximum 1024 devices.

#### Additional HTTP Headers

    Content-Type: application/json

#### Parameters

- *object* `data`:
    - *string* `applicationId`: The target application ID.
    - *string* `networkId`: The associated network ID. The public network can be assigned by **admin** or **manager**.
    - *string[]* `networkAddrs`: The network addresses of the specified network. This will be transformed to lowercase.

- **Example**

    ```json
    {
        "data": {
            "applicationId": "1640924063709-rmJIxW0s",
            "networkId": "1640924173420-BNg2lwo3",
            "networkAddrs": [
                "800012ae",
                "8000257f",
                "800022f3"
            ]
        }
    }
    ```

#### Response

- **204 No Content**
- **400 Bad Request**: the special error codes are:
    - `err_broker_application_not_exist`: The application does not exist.
    - `err_broker_network_not_exist`: The network does not exist.
- **401, 403, 500, 503**: See [Notes]#notes.

## <a name="post_device_route_range"></a>Bulk creating device routes with address range

Create device routes in bulk with address range.

    POST /broker/api/v1/device-route/range

Notes:
- Devices routes created earlier will be skipped.
- Maximum 1024 devices (0x400).
- `startAddrs` and `endAddrs` must be hexadecimal string with the same (even) length.
- Strings up to 32 bytes (128 bits) are supported.

#### Additional HTTP Headers

    Content-Type: application/json

#### Parameters

- *object* `data`:
    - *string* `applicationId`: The target application ID.
    - *string* `networkId`: The associated network ID. The public network can be assigned by **admin** or **manager**.
    - *string* `startAddr`: The start network address of the specified network.
    - *string* `endAddr`: The end network address of the specified network.

- **Example**

    ```json
    {
        "data": {
            "applicationId": "1640924063709-rmJIxW0s",
            "networkId": "1640924173420-BNg2lwo3",
            "startAddr": "80001000",
            "endAddr": "800013ff"
        }
    }
    ```

#### Response

- **204 No Content**
- **400 Bad Request**: the special error codes are:
    - `err_broker_application_not_exist`: The application does not exist.
    - `err_broker_network_not_exist`: The network does not exist.
    - `err_broker_device_not_exist`: The device does not exist.
- **401, 403, 500, 503**: See [Notes]#notes.

## <a name="post_device_route_range_del"></a>Bulk deleting device routes with address range

Delete device routes in bulk with address range.

    POST /broker/api/v1/device-route/range-delete

Notes:
- Maximum 1024 devices (0x400).
- `startAddrs` and `endAddrs` must be hexadecimal string with the same (even) length.
- Strings up to 32 bytes (128 bits) are supported.

#### Additional HTTP Headers

    Content-Type: application/json

#### Parameters

- *object* `data`:
    - *string* `applicationId`: The target application ID.
    - *string* `networkId`: The associated network ID. The public network can be assigned by **admin** or **manager**.
    - *string* `startAddr`: The start network address of the specified network.
    - *string* `endAddr`: The end network address of the specified network.

- **Example**

    ```json
    {
        "data": {
            "applicationId": "1640924063709-rmJIxW0s",
            "networkId": "1640924173420-BNg2lwo3",
            "startAddr": "80001000",
            "endAddr": "800013ff"
        }
    }
    ```

#### Response

- **204 No Content**
- **400 Bad Request**: the special error codes are:
    - `err_broker_application_not_exist`: The application does not exist.
    - `err_broker_network_not_exist`: The network does not exist.
- **401, 403, 500, 503**: See [Notes]#notes.

## <a name="get_device_route_count"></a>Device route count

Get device route list count.

    GET /broker/api/v1/device-route/count?
        unit={specifiedUnitId}&
        application={specifiedApplicationId}&
        network={specifiedNetworkId}&
        device={specifiedDeviceId}

- *string* `unit`: (**required for normal user**) To search device routes of the specified unit ID.
- *string* `application`: (**optional**) To search device routes of the specified application ID.
- *string* `network`: (**optional**) To search device routes of the specified network ID.
- *string* `device`: (**optional**) To search device routes of the specified device ID.

#### Response

- **200 OK**: Device route list count. Parameters are:

    - *object* `data`:
        - *number* `count`: Device route list count.

    - **Example**

        ```json
        {
            "data": {
                "count": 1
            }
        }
        ```

- **400 Bad Request**: the special error codes are:
    - `err_broker_unit_not_exist`: The unit does not exist.
- **401, 403, 500, 503**: See [Notes]#notes.

## <a name="get_device_route_list"></a>Device route list

Get device route list.

    GET /broker/api/v1/device-route/list?
        unit={specifiedUnitId}&
        application={specifiedApplicationId}&
        network={specifiedNetworkId}&
        device={specifiedDeviceId}&
        offset={offset}&
        limit={limit}&
        sort={sortKeysAndOrders}&
        format={responseFormat}

- *string* `unit`: (**required for normal user**) To search device routes of the specified unit ID.
- *string* `application`: (**optional**) To search device routes of the specified application ID.
- *string* `network`: (**optional**) To search device routes of the specified network ID.
- *string* `device`: (**optional**) To search device routes of the specified device ID.
- *number* `offset`: (**optional**) Data offset. Default is **0**.
- *number* `limit`: (**optional**) Number of items to list. **0** to list all data. Default is **100**.
- *string* `sort`: (**optional**) To sort the result. Format is `key:[asc|desc]`. The key can be **application**, **network**, **addr**, **created**, **modified**. Default is **network:asc,addr:asc,created:desc**.
- *string* `format`: (**optional**) Response body format. Default is array in the **data** field.
    - **array**: The response body is JSON array, not an object.

#### Response

- **200 OK**: An array that contains all device routes' information. Parameters are:

    - *object[]* `data`:
        - *string* `routeId`: Route ID.
        - *string* `unitId`: The associated unit ID.
        - *string* `applicationId`: The target application ID.
        - *string* `applicationCode`: The target application code.
        - *string* `deviceId`: The device ID.
        - *string* `networkId`: The network ID of the device.
        - *string* `networkCode`: The network code of the device.
        - *string* `networkAddr`: The network address of the device.
        - *string* `profile`: The device profile.
        - *string* `createdAt`: Creation time in RFC 3339 format.
        - *string* `modifiedAt`: Modification time in RFC 3339 format.

    - **Example**

        ```json
        {
            "data": [
                {
                    "routeId": "1640924308457-D455ZtkDW033",
                    "unitId": "1640923958516-qvdFNpOV",
                    "applicationId": "1640924063709-rmJIxW0s",
                    "applicationCode": "tracker",
                    "deviceId": "1640924274329-yESwHhKO",
                    "networkId": "1640924173420-BNg2lwo3",
                    "networkCode": "lora",
                    "networkAddr": "800012ae",
                    "profile": "tracker",
                    "createdAt": "2021-12-31T04:18:28.457Z",
                    "modifiedAt": "2021-12-31T04:18:28.457Z"
                }
            ]
        }
        ```

    - **Example (format=`array`)**

        ```json
        [
            {
                "routeId": "1640924308457-D455ZtkDW033",
                "unitId": "1640923958516-qvdFNpOV",
                "applicationId": "1640924063709-rmJIxW0s",
                "applicationCode": "tracker",
                "deviceId": "1640924274329-yESwHhKO",
                "networkId": "1640924173420-BNg2lwo3",
                "networkCode": "lora",
                "networkAddr": "800012ae",
                "profile": "tracker",
                "createdAt": "2021-12-31T04:18:28.457Z",
                "modifiedAt": "2021-12-31T04:18:28.457Z"
            }
        ]
        ```

- **400 Bad Request**: the special error codes are:
    - `err_broker_unit_not_exist`: The unit does not exist.
- **401, 403, 500, 503**: See [Notes]#notes.

## <a name="delete_device_route"></a>Delete device route

Delete a device route.

    DELETE /broker/api/v1/device-route/{routeId}

- *string* `routeId`: The specified route ID to delete.

#### Response

- **204 No Content**
- **401, 403, 500, 503**: See [Notes]#notes.

# <a name="network_route"></a>Network route APIs

## <a name="post_network_route"></a>Create network route

Create an network route.

    POST /broker/api/v1/network-route

#### Additional HTTP Headers

    Content-Type: application/json

#### Parameters

- *object* `data`:
    - *string* `networkId`: The network ID.
    - *string* `applicationId`: The target application ID.

- **Example**

    ```json
    {
        "data": {
            "networkId": "1640924173420-BNg2lwo3",
            "applicationId": "1640924063709-rmJIxW0s"
        }
    }
    ```

#### Response

- **200 OK**: The network ID. Parameters are:

    - *object* `data`:
        - *string* `routeId`: The route ID of the created network route.

    - **Example**

        ```json
        {
            "data": {
                "routeId": "1640924311420-po5HWJAyIZPY"
            }
        }
        ```

- **400 Bad Request**: the special error codes are:
    - `err_broker_application_not_exist`: The application does not exist.
    - `err_broker_network_not_exist`: The network does not exist.
    - `err_broker_route_exist`: The network route has been created.
- **401, 403, 500, 503**: See [Notes]#notes.

## <a name="get_network_route_count"></a>Network route count

Get network route list count.

    GET /broker/api/v1/network-route/count?
        unit={specifiedUnitId}&
        application={specifiedApplicationId}&
        network={specifiedNetworkId}

- *string* `unit`: (**required for normal user**) To search network routes of the specified unit ID.
- *string* `application`: (**optional**) To search network routes of the specified application ID.
- *string* `network`: (**optional**) To search network routes of the specified network ID.

#### Response

- **200 OK**: Network route list count. Parameters are:

    - *object* `data`:
        - *number* `count`: Network route list count.

    - **Example**

        ```json
        {
            "data": {
                "count": 1
            }
        }
        ```

- **400 Bad Request**: the special error codes are:
    - `err_broker_unit_not_exist`: The unit does not exist.
- **401, 403, 500, 503**: See [Notes]#notes.

## <a name="get_network_route_list"></a>Network route list

Get network route list.

    GET /broker/api/v1/network-route/list?
        unit={specifiedUnitId}&
        application={specifiedApplicationId}&
        network={specifiedNetworkId}&
        offset={offset}&
        limit={limit}&
        sort={sortKeysAndOrders}&
        format={responseFormat}

- *string* `unit`: (**required for normal user**) To search network routes of the specified unit ID.
- *string* `application`: (**optional**) To search network routes of the specified application ID.
- *string* `network`: (**optional**) To search network routes of the specified network ID.
- *number* `offset`: (**optional**) Data offset. Default is **0**.
- *number* `limit`: (**optional**) Number of items to list. **0** to list all data. Default is **100**.
- *string* `sort`: (**optional**) To sort the result. Format is `key:[asc|desc]`. The key can be **application**, **network**, **created**. Default is **network:asc,created:false**.
- *string* `format`: (**optional**) Response body format. Default is array in the **data** field.
    - **array**: The response body is JSON array, not an object.

#### Response

- **200 OK**: An array that contains all network routes' information. Parameters are:

    - *object[]* `data`:
        - *string* `routeId`: Route ID.
        - *string* `unitId`: The associated unit ID.
        - *string* `applicationId`: The target application ID.
        - *string* `applicationCode`: The target application code.
        - *string* `networkId`: The network ID.
        - *string* `networkCode`: The code of the network.
        - *string* `createdAt`: Creation time in RFC 3339 format.

    - **Example**

        ```json
        {
            "data": [
                {
                    "routeId": "1640924311420-po5HWJAyIZPY",
                    "unitId": "1640923958516-qvdFNpOV",
                    "applicationId": "1640924063709-rmJIxW0s",
                    "applicationCode": "tracker",
                    "networkId": "1640924173420-BNg2lwo3",
                    "networkCode": "lora",
                    "createdAt": "2021-12-31T04:18:31.420Z"
                }
            ]
        }
        ```

    - **Example (format=`array`)**

        ```json
        [
            {
                "routeId": "1640924311420-po5HWJAyIZPY",
                "unitId": "1640923958516-qvdFNpOV",
                "applicationId": "1640924063709-rmJIxW0s",
                "applicationCode": "tracker",
                "networkId": "1640924173420-BNg2lwo3",
                "networkCode": "lora",
                "createdAt": "2021-12-31T04:18:31.420Z"
            }
        ]
        ```

- **400 Bad Request**: the special error codes are:
    - `err_broker_unit_not_exist`: The unit does not exist.
- **401, 403, 500, 503**: See [Notes]#notes.

## <a name="delete_network_route"></a>Delete network route

Delete a network route.

    DELETE /broker/api/v1/network-route/{routeId}

- *string* `routeId`: The specified route ID to delete.

#### Response

- **204 No Content**
- **401, 403, 500, 503**: See [Notes]#notes.

# <a name="dldata_buffer"></a>Downlink data buffer APIs

## <a name="get_dldata_buffer_count"></a>Downlink data buffer count

Get downlink data buffer list count.

    GET /broker/api/v1/dldata-buffer/count?
        unit={specifiedUnitId}&
        application={specifiedApplicationId}&
        network={specifiedNetworkId}&
        device={specifiedDeviceId}

- *string* `unit`: (**required for normal user**) To search downlink data buffers of the specified unit ID.
- *string* `application`: (**optional**) To search downlink data buffers of the specified source application ID.
- *string* `network`: (**optional**) To search downlink data buffers of the specified destination network ID.
- *string* `device`: (**optional**) To search downlink data buffers of the specified destination device ID.

#### Response

- **200 OK**: Downlink data buffer list count. Parameters are:

    - *object* `data`:
        - *number* `count`: Downlink data buffer list count.

    - **Example**

        ```json
        {
            "data": {
                "count": 1
            }
        }
        ```

- **400 Bad Request**: the special error codes are:
    - `err_broker_unit_not_exist`: The unit does not exist.
- **401, 403, 500, 503**: See [Notes]#notes.

## <a name="get_dldata_buffer_list"></a>Downlink data buffer list

Get downlink data buffer list.

    GET /broker/api/v1/dldata-buffer/list?
        unit={specifiedUnitId}&
        application={specifiedApplicationId}&
        network={specifiedNetworkId}&
        device={specifiedDeviceId}&
        offset={offset}&
        limit={limit}&
        sort={sortKeysAndOrders}&
        format={responseFormat}

- *string* `unit`: (**required for normal user**) To search downlink data buffers of the specified unit ID.
- *string* `application`: (**optional**) To search downlink data buffers of the specified source application ID.
- *string* `network`: (**optional**) To search downlink data buffers of the specified destination network ID.
- *string* `device`: (**optional**) To search downlink data buffers of the specified destination device ID.
- *number* `offset`: (**optional**) Data offset. Default is **0**.
- *number* `limit`: (**optional**) Number of items to list. **0** to list all data. Default is **100**.
- *string* `sort`: (**optional**) To sort the result. Format is `key:[asc|desc]`. The key can be **application**, **created**, **expired**. Default is **application:asc,created:false**.
- *string* `format`: (**optional**) Response body format. Default is array in the **data** field.
    - **array**: The response body is JSON array, not an object.

#### Response

- **200 OK**: An array that contains all downlink data buffers' information. Parameters are:

    - *object[]* `data`:
        - *string* `dataId`: Data ID.
        - *string* `unitId`: The associated unit ID.
        - *string* `applicationId`: The source application ID.
        - *string* `applicationCode`: The source application code.
        - *string* `deviceId`: The destination device ID.
        - *string* `networkId`: The network ID of the device.
        - *string* `networkAddr`: The network address of the device.
        - *string* `createdAt`: Creation time in RFC 3339 format.
        - *string* `expiredAt`: Expiration time in RFC 3339 format.

    - **Example**

        ```json
        {
            "data": [
                {
                    "dataId": "1640924391768-DyyneusWeveV",
                    "unitId": "1640923958516-qvdFNpOV",
                    "applicationId": "1640924063709-rmJIxW0s",
                    "applicationCode": "tracker",
                    "deviceId": "1640924274329-yESwHhKO",
                    "networkId": "1640924173420-BNg2lwo3",
                    "networkAddr": "800012ae",
                    "createdAt": "2021-12-31T04:19:51.768Z",
                    "expiredAt": "2021-12-31T04:29:51.768Z"
                }
            ]
        }
        ```

    - **Example (format=`array`)**

        ```json
        [
            {
                "dataId": "1640924391768-DyyneusWeveV",
                "unitId": "1640923958516-qvdFNpOV",
                "applicationId": "1640924063709-rmJIxW0s",
                "applicationCode": "tracker",
                "deviceId": "1640924274329-yESwHhKO",
                "networkId": "1640924173420-BNg2lwo3",
                "networkAddr": "800012ae",
                "createdAt": "2021-12-31T04:19:51.768Z",
                "expiredAt": "2021-12-31T04:29:51.768Z"
            }
        ]
        ```

- **400 Bad Request**: the special error codes are:
    - `err_broker_unit_not_exist`: The unit does not exist.
- **401, 403, 500, 503**: See [Notes]#notes.

## <a name="delete_dldata_buffer"></a>Delete downlink data buffer

Delete a downlink data buffer.

    DELETE /broker/api/v1/dldata-buffer/{dataId}

- *string* `dataId`: The specified data ID to delete.

#### Response

- **204 No Content**
- **401, 403, 500, 503**: See [Notes]#notes.