summaryrefslogtreecommitdiffhomepage
path: root/api.md
blob: 7fe05624bf1ba562a884cd70498ff7739ebc7033 (plain)
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
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
# Tailscale API

The Tailscale API is a (mostly) RESTful API. Typically, both `POST` bodies and responses are JSON-encoded.

## Base URL

The base URL for the Tailscale API is `https://api.tailscale.com/api/v2/`.

Examples in this document may abbreviate this to `/api/v2/`.

## Authentication

Requests to the Tailscale API are authenticated with an API access token (sometimes called an API key).
Access tokens can be supplied as the username portion of HTTP Basic authentication (leave the password blank) or as an OAuth Bearer token:

```sh
# passing token with basic auth
curl -u "tskey-api-xxxxx:" https://api.tailscale.com/api/v2/...

# passing token as bearer token
curl -H "Authorization: Bearer tskey-api-xxxxx" https://api.tailscale.com/api/v2/...
```

Access tokens for individual users can be created and managed from the [**Keys**](https://login.tailscale.com/admin/settings/keys) page of the admin console.
These tokens will have the same permissions as the owning user, and can be set to expire in 1 to 90 days.
Access tokens are identifiable by the prefix `tskey-api-`.

Alternatively, an OAuth client can be used to create short-lived access tokens with scoped permission.
OAuth clients don't expire, and can therefore be used to provide ongoing access to the API, creating access tokens as needed.
OAuth clients and the access tokens they create are not tied to an individual Tailscale user.
OAuth client secrets are identifiable by the prefix `tskey-client-`.
Learn more about [OAuth clients](https://tailscale.com/kb/1215/).

## Errors

The Tailscale API returns status codes consistent with [standard HTTP conventions](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status).
In addition to the status code, errors may include additional information in the response body:

```jsonc
{
  "message": "additional error information"
}
```

## Pagination

The Tailscale API does not currently support pagination. All results are returned at once.

# APIs

**[Device](#device)**

- Get a device: [`GET /api/v2/device/{deviceid}`](#get-device)
- Delete a device: [`DELETE /api/v2/device/{deviceID}`](#delete-device)
- Expire device key: [`POST /api/v2/device/{deviceID}/expire`](#expire-device-key)
- **Routes**
  - Get device routes: [`GET /api/v2/device/{deviceID}/routes`](#get-device-routes)
  - Set device routes: [`POST /api/v2/device/{deviceID}/routes`](#set-device-routes)
- **Authorize**
  - Authorize a device: [`POST /api/v2/device/{deviceID}/authorized`](#authorize-device)
- **Tags**
  - Update tags: [`POST /api/v2/device/{deviceID}/tags`](#update-device-tags)
- **Key**
  - Update device key: [`POST /api/v2/device/{deviceID}/key`](#update-device-key)
- **IP Address**
  - Set device IPv4 address: [`POST /api/v2/device/{deviceID}/ip`](#set-device-ipv4-address)
- **Device posture attributes**
  - Get device posture attributes: [`GET /api/v2/device/{deviceID}/attributes`](#get-device-posture-attributes)
  - Set custom device posture attributes: [`POST /api/v2/device/{deviceID}/attributes/{attributeKey}`](#set-device-posture-attributes)
  - Delete custom device posture attributes: [`DELETE /api/v2/device/{deviceID}/attributes/{attributeKey}`](#delete-custom-device-posture-attributes)
- [**Device invites**](#invites-to-a-device)
  - List device invites: [`GET /api/v2/device/{deviceID}/device-invites`](#list-device-invites)
  - Create device invites: [`POST /api/v2/device/{deviceID}/device-invites`](#create-device-invites)

**[Tailnet](#tailnet)**

- [**Policy File**](#policy-file)
  - Get policy file: [`GET /api/v2/tailnet/{tailnet}/acl`](#get-policy-file)
  - Update policy file: [`POST /api/v2/tailnet/{tailnet}/acl`](#update-policy-file)
  - Preview rule matches: [`POST /api/v2/tailnet/{tailnet}/acl/preview`](#preview-policy-file-rule-matches)
  - Validate and test policy file: [`POST /api/v2/tailnet/{tailnet}/acl/validate`](#validate-and-test-policy-file)
- Devices
  - List tailnet devices: [`GET /api/v2/tailnet/{tailnet}/devices`](#list-tailnet-devices)
- [**Keys**](#tailnet-keys)
  - List tailnet keys: [`GET /api/v2/tailnet/{tailnet}/keys`](#list-tailnet-keys)
  - Create an auth key: [`POST /api/v2/tailnet/{tailnet}/keys`](#create-auth-key)
  - Get a key: [`GET /api/v2/tailnet/{tailnet}/keys/{keyid}`](#get-key)
  - Delete a key: [`DELETE /api/v2/tailnet/{tailnet}/keys/{keyid}`](#delete-key)
- [**DNS**](#dns)
  - **Nameservers**
    - Get nameservers: [`GET /api/v2/tailnet/{tailnet}/dns/nameservers`](#get-nameservers)
    - Set nameservers: [`POST /api/v2/tailnet/{tailnet}/dns/nameservers`](#set-nameservers)
  - **Preferences**
    - Get DNS preferences: [`GET /api/v2/tailnet/{tailnet}/dns/preferences`](#get-dns-preferences)
    - Set DNS preferences: [`POST /api/v2/tailnet/{tailnet}/dns/preferences`](#set-dns-preferences)
  - **Search paths**
    - Get search paths: [`GET /api/v2/tailnet/{tailnet}/dns/searchpaths`](#get-search-paths)
    - Set search paths: [`POST /api/v2/tailnet/{tailnet}/dns/searchpaths`](#set-search-paths)
  - **Split DNS**
    - Get split DNS: [`GET /api/v2/tailnet/{tailnet}/dns/split-dns`](#get-split-dns)
    - Update split DNS: [`PATCH /api/v2/tailnet/{tailnet}/dns/split-dns`](#update-split-dns)
    - Set split DNS: [`PUT /api/v2/tailnet/{tailnet}/dns/split-dns`](#set-split-dns)
- [**User invites**](#tailnet-user-invites)
  - List user invites: [`GET /api/v2/tailnet/{tailnet}/user-invites`](#list-user-invites)
  - Create user invites: [`POST /api/v2/tailnet/{tailnet}/user-invites`](#create-user-invites)

**[User invites](#user-invites)**

- Get user invite: [`GET /api/v2/user-invites/{userInviteId}`](#get-user-invite)
- Delete user invite: [`DELETE /api/v2/user-invites/{userInviteId}`](#delete-user-invite)
- Resend user invite (by email): [`POST /api/v2/user-invites/{userInviteId}/resend`](#resend-user-invite)

**[Device invites](#device-invites)**

- Get device invite: [`GET /api/v2/device-invites/{deviceInviteId}`](#get-device-invite)
- Delete device invite: [`DELETE /api/v2/device-invites/{deviceInviteId}`](#delete-device-invite)
- Resend device invite (by email): [`POST /api/v2/device-invites/{deviceInviteId}/resend`](#resend-device-invite)
- Accept device invite [`POST /api/v2/device-invites/-/accept`](#accept-device-invite)

# Device

A Tailscale device (sometimes referred to as _node_ or _machine_), is any computer or mobile device that joins a tailnet.

Each device has a unique ID (`nodeId` in the JSON below) that is used to identify the device in API calls.
This ID can be found by going to the [**Machines**](https://login.tailscale.com/admin/machines) page in the admin console,
selecting the relevant device, then finding the ID in the Machine Details section.
You can also [list all devices in the tailnet](#list-tailnet-devices) to get their `nodeId` values.

(A device's numeric `id` value can also be used in API calls, but `nodeId` is preferred.)

### Attributes

```jsonc
{
  // addresses (array of strings) is a list of Tailscale IP
  // addresses for the device, including both IPv4 (formatted as 100.x.y.z)
  // and IPv6 (formatted as fd7a:115c:a1e0:a:b:c:d:e) addresses.
  "addresses": ["100.87.74.78", "fd7a:115c:a1e0:ac82:4843:ca90:697d:c36e"],

  // id (string) is the legacy identifier for a device; you
  // can supply this value wherever {deviceId} is indicated in the
  // endpoint. Note that although "id" is still accepted, "nodeId" is
  // preferred.
  "id": "393735751060",

  // nodeID (string) is the preferred identifier for a device;
  // supply this value wherever {deviceId} is indicated in the endpoint.
  "nodeId": "n5SUKe8CNTRL",

  // user (string) is the user who registered the node. For untagged nodes,
  // this user is the device owner.
  "user": "amelie@example.com",

  // name (string) is the MagicDNS name of the device.
  // Learn more about MagicDNS at https://tailscale.com/kb/1081/.
  "name": "pangolin.tailfe8c.ts.net",

  // hostname (string) is the machine name in the admin console
  // Learn more about machine names at https://tailscale.com/kb/1098/.
  "hostname": "pangolin",

  // clientVersion (string) is the version of the Tailscale client
  // software; this is empty for external devices.
  "clientVersion": "",

  // updateAvailable (boolean) is 'true' if a Tailscale client version
  // upgrade is available. This value is empty for external devices.
  "updateAvailable": false,

  // os (string) is the operating system that the device is running.
  "os": "linux",

  // created (string) is the date on which the device was added
  // to the tailnet; this is empty for external devices.
  "created": "2022-12-01T05:23:30Z",

  // lastSeen (string) is when device was last active on the tailnet.
  "lastSeen": "2022-12-01T05:23:30Z",

  // keyExpiryDisabled (boolean) is 'true' if the keys for the device
  // will not expire. Learn more at https://tailscale.com/kb/1028/.
  "keyExpiryDisabled": true,

  // expires (string) is the expiration date of the device's auth key.
  // Learn more about key expiry at https://tailscale.com/kb/1028/.
  "expires": "2023-05-30T04:44:05Z",

  // authorized (boolean) is 'true' if the device has been
  // authorized to join the tailnet; otherwise, 'false'. Learn
  // more about device authorization at https://tailscale.com/kb/1099/.
  "authorized": true,

  // isExternal (boolean) if 'true', indicates that a device is not
  // a member of the tailnet, but is shared in to the tailnet;
  // if 'false', the device is a member of the tailnet.
  // Learn more about node sharing at https://tailscale.com/kb/1084/.
  "isExternal": true,

  // machineKey (string) is for internal use and is not required for
  // any API operations. This value is empty for external devices.
  "machineKey": "",

  // nodeKey (string) is mostly for internal use, required for select
  // operations, such as adding a node to a locked tailnet.
  // Learn about tailnet locks at https://tailscale.com/kb/1226/.
  "nodeKey": "nodekey:01234567890abcdef",

  // blocksIncomingConnections (boolean) is 'true' if the device is not
  // allowed to accept any connections over Tailscale, including pings.
  // Learn more in the "Allow incoming connections"
  // section of https://tailscale.com/kb/1072/.
  "blocksIncomingConnections": false,

  // enabledRoutes (array of strings) are the subnet routes for this
  // device that have been approved by the tailnet admin.
  // Learn more about subnet routes at https://tailscale.com/kb/1019/.
  "enabledRoutes": ["10.0.0.0/16", "192.168.1.0/24"],

  // advertisedRoutes (array of strings) are the subnets this device
  // intends to expose.
  // Learn more about subnet routes at https://tailscale.com/kb/1019/.
  "advertisedRoutes": ["10.0.0.0/16", "192.168.1.0/24"],

  // clientConnectivity provides a report on the device's current physical
  // network conditions.
  "clientConnectivity": {
    // endpoints (array of strings) Client's magicsock UDP IP:port
    // endpoints (IPv4 or IPv6)
    "endpoints": ["199.9.14.201:59128", "192.68.0.21:59128"],

    // mappingVariesByDestIP (boolean) is 'true' if the host's NAT mappings
    // vary based on the destination IP.
    "mappingVariesByDestIP": false,

    // latency (JSON object) lists DERP server locations and their current
    // latency; "preferred" is 'true' for the node's preferred DERP
    // server for incoming traffic.
    "latency": {
      "Dallas": {
        "latencyMs": 60.463043
      },
      "New York City": {
        "preferred": true,
        "latencyMs": 31.323811
      }
    },

    // clientSupports (JSON object) identifies features supported by the client.
    "clientSupports": {
      // hairpinning (boolean) is 'true' if your router can route connections
      // from endpoints on your LAN back to your LAN using those endpoints’
      // globally-mapped IPv4 addresses/ports
      "hairPinning": false,

      // ipv6 (boolean) is 'true' if the device OS supports IPv6,
      // regardless of whether IPv6 internet connectivity is available.
      "ipv6": false,

      // pcp (boolean) is 'true' if PCP port-mapping service exists on
      // your router.
      "pcp": false,

      // pmp (boolean) is 'true' if NAT-PMP port-mapping service exists
      // on your router.
      "pmp": false,

      // udp (boolean) is 'true' if UDP traffic is enabled on the
      // current network; if 'false', Tailscale may be unable to make
      // direct connections, and will rely on our DERP servers.
      "udp": true,

      // upnp (boolean) is 'true' if UPnP port-mapping service exists
      // on your router.
      "upnp": false
    }
  },

  // tags (array of strings) let you assign an identity to a device that
  // is separate from human users, and use it as part of an ACL to restrict
  // access. Once a device is tagged, the tag is the owner of that device.
  // A single node can have multiple tags assigned. This value is empty for
  // external devices.
  // Learn more about tags at https://tailscale.com/kb/1068/.
  "tags": ["tag:golink"],

  // tailnetLockError (string) indicates an issue with the tailnet lock
  // node-key signature on this device.
  // This field is only populated when tailnet lock is enabled.
  "tailnetLockError": "",

  // tailnetLockKey (string) is the node's tailnet lock key. Every node
  // generates a tailnet lock key (so the value will be present) even if
  // tailnet lock is not enabled.
  // Learn more about tailnet lock at https://tailscale.com/kb/1226/.
  "tailnetLockKey": "",

  // postureIdentity contains extra identifiers from the device when the tailnet
  // it is connected to has device posture identification collection enabled.
  // If the device has not opted-in to posture identification collection, this
  // will contain {"disabled": true}.
  // Learn more about posture identity at https://tailscale.com/kb/1326/device-identity
  "postureIdentity": {
    "serialNumbers": ["CP74LFQJXM"]
  }
}
```

### Subnet routes

Devices within a tailnet can be set up as subnet routers.
A subnet router acts as a gateway, relaying traffic from your Tailscale network onto your physical subnet.
Setting up subnet routers exposes routes to other devices in the tailnet.
Learn more about [subnet routers](https://tailscale.com/kb/1019).

A device can act as a subnet router if its subnet routes are both advertised and enabled.
This is a two-step process, but the steps can occur in any order:

- The device that intends to act as a subnet router exposes its routes by **advertising** them.
  This is done in the Tailscale command-line interface.
- The tailnet admin must approve the routes by **enabling** them.
  This is done in the [**Machines**](https://login.tailscale.com/admin/machines) page of the Tailscale admin console
  or [via the API](#set-device-routes).

If a device has advertised routes, they are not exposed to traffic until they are enabled by the tailnet admin.
Conversely, if a tailnet admin pre-approves certain routes by enabling them, they are not available for routing until the device in question has advertised them.

The API exposes two methods for dealing with subnet routes:

- Get routes: [`GET /api/v2/device/{deviceID}/routes`](#get-device-routes) to fetch lists of advertised and enabled routes for a device
- Set routes: [`POST /api/v2/device/{deviceID}/routes`](#set-device-routes) to set enabled routes for a device

<a name="device-get"></a>

## Get device

```http
GET /api/v2/device/{deviceid}
```

Retrieve the details for the specified device.
This returns a JSON `device` object listing device attributes.

### Parameters

#### `deviceid` (required in URL path)

The ID of the device.

#### `fields` (optional in query string)

Controls whether the response returns **all** object fields or only a predefined subset of fields.
Currently, there are two supported options:

- **`all`:** return all object fields in the response
- **`default`:** return all object fields **except**:
  - `enabledRoutes`
  - `advertisedRoutes`
  - `clientConnectivity` (which contains the following fields: `mappingVariesByDestIP`, `derp`, `endpoints`, `latency`, and `clientSupports`)
  - `postureIdentity`

### Request example

```sh
curl "https://api.tailscale.com/api/v2/device/12345?fields=all" \
  -u "tskey-api-xxxxx:"
```

### Response

```jsonc
{
  "addresses":[
    "100.71.74.78",
    "fd7a:115c:a1e0:ac82:4843:ca90:697d:c36e"
  ],
  "id":"12345",

  // Additional fields as documented in device "Attributes" section above
}
{
  "addresses":[
    "100.74.66.78",
    "fd7a:115c:a1e0:ac82:4843:ca90:697d:c36f"
  ],
  "id":"67890",

  // Additional fields as documented in device "Attributes" section above
}
```

<a href="device-delete"></a>

## Delete device

```http
DELETE /api/v2/device/{deviceID}
```

Deletes the supplied device from its tailnet.
The device must belong to the user's tailnet.
Deleting shared/external devices is not supported.

### Parameters

#### `deviceid` (required in URL path)

The ID of the device.

### Request example

```sh
curl -X DELETE 'https://api.tailscale.com/api/v2/device/12345' \
  -u "tskey-api-xxxxx:"
```

### Response

If successful, the response should be empty:

```http
HTTP/1.1 200 OK
```

If the device is not owned by your tailnet:

```http
HTTP/1.1 501 Not Implemented
...
{"message":"cannot delete devices outside of your tailnet"}
```

<a href="expire-device-key"></a>

## Expire a device's key

```http
POST /api/v2/device/{deviceID}/expire
```

Mark a device's node key as expired.
This will require the device to re-authenticate in order to connect to the tailnet.
The device must belong to the requesting user's tailnet.

### Parameters

#### `deviceid` (required in URL path)

The ID of the device.

### Request example

```sh
curl -X POST 'https://api.tailscale.com/api/v2/device/12345/expire' \
  -u "tskey-api-xxxxx:" \
  -H "Content-Type: application/json"
```

### Response

If successful, the response should be empty:

```http
HTTP/1.1 200 OK
```

<a href="device-routes-get">

## Get device routes

```http
GET /api/v2/device/{deviceID}/routes
```

Retrieve the list of [subnet routes](#subnet-routes) that a device is advertising, as well as those that are enabled for it:

- **Enabled routes:** The subnet routes for this device that have been approved by the tailnet admin.
- **Advertised routes:** The subnets this device intends to expose.

### Parameters

#### `deviceid` (required in URL path)

The ID of the device.

### Request example

```sh
curl "https://api.tailscale.com/api/v2/device/11055/routes" \
-u "tskey-api-xxxxx:"
```

### Response

Returns the enabled and advertised subnet routes for a device.

```jsonc
{
  "advertisedRoutes": ["10.0.0.0/16", "192.168.1.0/24"],
  "enabledRoutes": []
}
```

<a href="device-routes-post"></a>

## Set device routes

```http
POST /api/v2/device/{deviceID}/routes
```

Sets a device's enabled [subnet routes](#subnet-routes) by replacing the existing list of subnet routes with the supplied parameters.
Advertised routes cannot be set through the API, since they must be set directly on the device.

### Parameters

#### `deviceid` (required in URL path)

The ID of the device.

#### `routes` (required in `POST` body)

The new list of enabled subnet routes.

```jsonc
{
  "routes": ["10.0.0.0/16", "192.168.1.0/24"]
}
```

### Request example

```sh
curl "https://api.tailscale.com/api/v2/device/11055/routes" \
-u "tskey-api-xxxxx:" \
-H "Content-Type: application/json" \
--data-binary '{"routes": ["10.0.0.0/16", "192.168.1.0/24"]}'
```

### Response

Returns the enabled and advertised subnet routes for a device.

```jsonc
{
  "advertisedRoutes": ["10.0.0.0/16", "192.168.1.0/24"],
  "enabledRoutes": ["10.0.0.0/16", "192.168.1.0/24"]
}
```

<a href="#device-authorized-post"></a>

## Authorize device

```http
POST /api/v2/device/{deviceID}/authorized
```

Authorize a device.
This call marks a device as authorized or revokes its authorization for tailnets where device authorization is required, according to the `authorized` field in the payload.

This returns a successful 2xx response with an empty JSON object in the response body.

### Parameters

#### `deviceid` (required in URL path)

The ID of the device.

#### `authorized` (required in `POST` body)

Specify whether the device is authorized. False to deauthorize an authorized device, and true to authorize a new device or to re-authorize a previously deauthorized device.

```jsonc
{
  "authorized": true
}
```

### Request example

```sh
curl "https://api.tailscale.com/api/v2/device/11055/authorized" \
-u "tskey-api-xxxxx:" \
-H "Content-Type: application/json" \
--data-binary '{"authorized": true}'
```

### Response

The response is 2xx on success. The response body is currently an empty JSON object.

<a href="device-tags-post"></a>

## Update device tags

```http
POST /api/v2/device/{deviceID}/tags
```

Update the tags set on a device.
Tags let you assign an identity to a device that is separate from human users, and use that identity as part of an ACL to restrict access.
Tags are similar to role accounts, but more flexible.

Tags are created in the tailnet policy file by defining the tag and an owner of the tag.
Once a device is tagged, the tag is the owner of that device.
A single node can have multiple tags assigned.

Consult the policy file for your tailnet in the [admin console](https://login.tailscale.com/admin/acls) for the list of tags that have been created for your tailnet.
Learn more about [tags](https://tailscale.com/kb/1068/).

This returns a 2xx code if successful, with an empty JSON object in the response body.

### Parameters

#### `deviceid` (required in URL path)

The ID of the device.

#### `tags` (required in `POST` body)

The new list of tags for the device.

```jsonc
{
  "tags": ["tag:foo", "tag:bar"]
}
```

### Request example

```sh
curl "https://api.tailscale.com/api/v2/device/11055/tags" \
-u "tskey-api-xxxxx:" \
-H "Content-Type: application/json" \
--data-binary '{"tags": ["tag:foo", "tag:bar"]}'
```

### Response

The response is 2xx on success. The response body is currently an empty JSON object.

If the tags supplied in the `POST` call do not exist in the tailnet policy file, the response is '400 Bad Request':

```jsonc
{
  "message": "requested tags [tag:madeup tag:wrongexample] are invalid or not permitted"
}
```

<a href="device-key-post"></a>

## Update device key

```http
POST /api/v2/device/{deviceID}/key
```

Update properties of the device key.

### Parameters

#### `deviceid` (required in URL path)

The ID of the device.

#### `keyExpiryDisabled` (optional in `POST` body)

Disable or enable the expiry of the device's node key.

When a device is added to a tailnet, its key expiry is set according to the tailnet's [key expiry](https://tailscale.com/kb/1028/) setting.
If the key is not refreshed and expires, the device can no longer communicate with other devices in the tailnet.

Set `"keyExpiryDisabled": true` to disable key expiry for the device and allow it to rejoin the tailnet (for example to access an accidentally expired device).
You can then call this method again with `"keyExpiryDisabled": false` to re-enable expiry.

```jsonc
{
  "keyExpiryDisabled": true
}
```

- If `true`, disable the device's key expiry.
  The original key expiry time is still maintained.
  Upon re-enabling, the key will expire at that original time.
- If `false`, enable the device's key expiry.
  Sets the key to expire at the original expiry time prior to disabling.
  The key may already have expired. In that case, the device must be re-authenticated.
- Empty value will not change the key expiry.

This returns a 2xx code on success, with an empty JSON object in the response body.

### Request example

```sh
curl "https://api.tailscale.com/api/v2/device/11055/key" \
-u "tskey-api-xxxxx:" \
-H "Content-Type: application/json" \
--data-binary '{"keyExpiryDisabled": true}'
```

### Response

The response is 2xx on success. The response body is currently an empty JSON object.

## Set device IPv4 address

```http
POST /api/v2/device/{deviceID}/ip
```

Set the Tailscale IPv4 address of the device.

### Parameters

#### `deviceid` (required in URL path)

The ID of the device.

#### `ipv4` (optional in `POST` body)

Provide a new IPv4 address for the device.

When a device is added to a tailnet, its Tailscale IPv4 address is set at random either from the CGNAT range, or a subset of the CGNAT range specified by an [ip pool](https://tailscale.com/kb/1304/ip-pool).
This endpoint can be used to replace the existing IPv4 address with a specific value.

```jsonc
{
  "ipv4": "100.80.0.1"
}
```

This action will break any existing connections to this machine.
You will need to reconnect to this machine using the new IP address.
You may also need to flush your DNS cache.

This returns a 2xx code on success, with an empty JSON object in the response body.

### Request example

```sh
curl "https://api.tailscale.com/api/v2/device/11055/ip" \
-u "tskey-api-xxxxx:" \
-H "Content-Type: application/json" \
--data-binary '{"ipv4": "100.80.0.1"}'
```

### Response

The response is 2xx on success. The response body is currently an empty JSON object.

## Get device posture attributes

The posture attributes API endpoints can be called with OAuth access tokens with
an `acl` or `devices` [scope](https://tailscale.com/kb/1215/oauth-clients#scopes), or personal access belonging to
[user roles](https://tailscale.com/kb/1138/user-roles) Owners, Admins, Network Admins, or IT Admins.

```
GET /api/v2/device/{deviceID}/attributes
```

Retrieve all posture attributes for the specified device. This returns a JSON object of all the key-value pairs of posture attributes for the device.

### Parameters

#### `deviceID` (required in URL path)

The ID of the device to fetch posture attributes for.

### Request example

```
curl "https://api.tailscale.com/api/v2/device/11055/attributes" \
-u "tskey-api-xxxxx:"
```

### Response

The response is 200 on success. The response body is a JSON object containing all the posture attributes assigned to the node. Attribute values can be strings, numbers or booleans.

```json
{
  "attributes": {
    "custom:myScore": 87,
    "custom:diskEncryption": true,
    "custom:myAttribute": "my_value",
    "node:os": "linux",
    "node:osVersion": "5.19.0-42-generic",
    "node:tsReleaseTrack": "stable",
    "node:tsVersion": "1.40.0",
    "node:tsAutoUpdate": false
  }
}
```

## Set custom device posture attributes

```
POST /api/v2/device/{deviceID}/attributes/{attributeKey}
```

Create or update a custom posture attribute on the specified device. User-managed attributes must be in the `custom` namespace, which is indicated by prefixing the attribute key with `custom:`.

Custom device posture attributes are available for the Personal and Enterprise plans.

### Parameters

#### `deviceID` (required in URL path)

The ID of the device on which to set the custom posture attribute.

#### `attributeKey` (required in URL path)

The name of the posture attribute to set. This must be prefixed with `custom:`.

Keys have a maximum length of 50 characters including the namespace, and can only contain letters, numbers, underscores, and colon.

Keys are case-sensitive. Keys must be unique, but are checked for uniqueness in a case-insensitive manner. For example, `custom:MyAttribute` and `custom:myattribute` cannot both be set within a single tailnet.

All values for a given key need to be of the same type, which is determined when the first value is written for a given key. For example, `custom:myattribute` cannot have a numeric value (`87`) for one node and a string value (`"78"`) for another node within the same tailnet.

### Posture attribute `value` (required in POST body)

```json
{
  "value": "foo"
}
```

A value can be either a string, number or boolean.

A string value can have a maximum length of 50 characters, and can only contain letters, numbers, underscores, and periods.

A number value is an integer and must be a JSON safe number (up to 2^53 - 1).

### Request example

```
curl "https://api.tailscale.com/api/v2/device/11055/attributes/custom:my_attribute" \
-u "tskey-api-xxxxx:" \
-H "Content-Type: application/json" \
--data-binary '{"value": "my_value"}'
```

### Response

The response is 2xx on success. The response body is currently an empty JSON object.

## Delete custom device posture attributes

```
DELETE /api/v2/device/{deviceID}/attributes/{attributeKey}
```

Delete a posture attribute from the specified device. This is only applicable to user-managed posture attributes in the `custom` namespace, which is indicated by prefixing the attribute key with `custom:`.

<PricingPlanNote feature="Custom device posture attributes" verb="are" plan="the Personal and Enterprise plans" />

### Parameters

#### `deviceID` (required in URL path)

The ID of the device from which to delete the posture attribute.

#### `attributeKey` (required in URL path)

The name of the posture attribute to delete. This must be prefixed with `custom:`.

Keys have a maximum length of 50 characters including the namespace, and can only contain letters, numbers, underscores, and a delimiting colon.

### Request example

```
curl -X DELETE "https://api.tailscale.com/api/v2/device/11055/attributes/custom:my_attribute" \
-u "tskey-api-xxxxx:"
```

### Response

The response is 2xx on success. The response body is currently an empty JSON object.

## Invites to a device

The device sharing invite methods let you create and list [invites to share a device](https://tailscale.com/kb/1084/sharing).

## List device invites

```http
GET /api/v2/device/{deviceID}/device-invites
```

List all share invites for a device.

### Parameters

#### `deviceID` (required in URL path)

The ID of the device.

### Request example

```sh
curl -X GET "https://api.tailscale.com/api/v2/device/11055/device-invites" \
-u "tskey-api-xxxxx:"
```

### Response

```jsonc
[
  {
    "id": "12345",
    "created": "2024-05-08T20:19:51.777861756Z",
    "tailnetId": 59954,
    "deviceId": 11055,
    "sharerId": 22011,
    "allowExitNode": true,
    "email": "user@example.com",
    "lastEmailSentAt": "2024-05-08T20:19:51.777861756Z",
    "inviteUrl": "https://login.tailscale.com/admin/invite/<code>",
    "accepted": false
  },
  {
    "id": "12346",
    "created": "2024-04-03T21:38:49.333829261Z",
    "tailnetId": 59954,
    "deviceId": 11055,
    "sharerId": 22012,
    "inviteUrl": "https://login.tailscale.com/admin/invite/<code>",
    "accepted": true,
    "acceptedBy": {
      "id": 33223,
      "loginName": "someone@example.com",
      "profilePicUrl": ""
    }
  }
]
```

## Create device invites

```http
POST /api/v2/device/{deviceID}/device-invites
```

Create new share invites for a device.

### Parameters

#### `deviceID` (required in URL path)

The ID of the device.

#### List of invite requests (required in `POST` body)

Each invite request is an object with the following optional fields:

- **`multiUse`:** (Optional) Specify whether the invite can be accepted more than once. When set to `true`, it results in an invite that can be accepted up to 1,000 times.
- **`allowExitNode`:** (Optional) Specify whether the invited user can use the device as an exit node when it advertises as one.
- **`email`:** (Optional) Specify the email to send the created invite. If not set, the endpoint generates and returns an invite URL (but doesn't send it out).

### Request example

```sh
curl -X POST "https://api.tailscale.com/api/v2/device/11055/device-invites" \
-u "tskey-api-xxxxx:" \
-H "Content-Type: application/json" \
--data-binary '[{"multiUse": true, "allowExitNode": true, "email":"user@example.com"}]'
```

### Response

```jsonc
[
  {
    "id": "12347",
    "created": "2024-05-08T20:29:45.842358533Z",
    "tailnetId": 59954,
    "deviceId": 11055,
    "sharerId": 22012,
    "multiUse": true,
    "allowExitNode": true,
    "email": "user@example.com",
    "lastEmailSentAt": "2024-05-08T20:29:45.842358533Z",
    "inviteUrl": "https://login.tailscale.com/admin/invite/<code>",
    "accepted": false
  }
]
```

# Tailnet

A tailnet is your private network, composed of all the devices on it and their configuration.
Learn more about [tailnets](https://tailscale.com/kb/1136/).

When specifying a tailnet in the API, you can:

- Provide a dash (`-`) to reference the default tailnet of the access token being used to make the API call.
  This is the best option for most users.
  Your API calls would start:

  ```sh
  curl "https://api.tailscale.com/api/v2/tailnet/-/..."
  ```

- Provide the **organization** name found on the **[General Settings](https://login.tailscale.com/admin/settings/general)**
  page of the Tailscale admin console (not to be confused with the "tailnet name" found in the DNS tab).

  For example, if your organization name is `alice@gmail.com`, your API calls would start:

  ```sh
  curl "https://api.tailscale.com/api/v2/tailnet/alice@gmail.com/..."
  ```

## Policy File

The tailnet policy file contains access control lists and related configuration.
The policy file is expressed using "[HuJSON](https://github.com/tailscale/hujson#readme)"
(human JSON, a superset of JSON that allows comments and trailing commas).
Most policy file API methods can also return regular JSON for compatibility with other tools.
Learn more about [network access controls](https://tailscale.com/kb/1018/).

<a href="tailnet-acl-get"></a>

## Get Policy File

```http
GET /api/v2/tailnet/{tailnet}/acl
```

Retrieves the current policy file for the given tailnet; this includes the ACL along with the rules and tests that have been defined.

This method can return the policy file as JSON or HuJSON, depending on the `Accept` header.
The response also includes an `ETag` header, which can be optionally included when [updating the policy file](#update-policy-file) to avoid missed updates.

### Parameters

#### `tailnet` (required in URL path)

The tailnet organization name.

#### `Accept` (optional in request header)

Response is encoded as JSON if `application/json` is requested, otherwise HuJSON will be returned.

#### `details` (optional in query string)

Request a detailed description of the tailnet policy file by providing `details=1` in the URL query string.
If using this, do not supply an `Accept` parameter in the header.

The response will contain a JSON object with the fields:

- **tailnet policy file:** a base64-encoded string representation of the huJSON format
- **warnings:** array of strings for syntactically valid but nonsensical entries
- **errors:** an array of strings for parsing failures

### Request example (response in HuJSON format)

```sh
curl "https://api.tailscale.com/api/v2/tailnet/example.com/acl" \
  -u "tskey-api-xxxxx:"
```

### Response in HuJSON format

On success, returns a 200 status code and the tailnet policy file in HuJSON format.
No errors or warnings are returned.

```jsonc
...
Content-Type: application/hujson
Etag: "e0b2816b418b3f266309d94426ac7668ab3c1fa87798785bf82f1085cc2f6d9c"
...

// Example/default ACLs for unrestricted connections.
{
  // Declare static groups of users beyond those in the identity service.
  "groups": {
    "group:example": ["user1@example.com", "user2@example.com"],
  },

  // Declare convenient hostname aliases to use in place of IP addresses.
  "hosts": {
    "example-host-1": "100.100.100.100",
  },

  // Access control lists.
  "acls": [
    // Match absolutely everything.
    // Comment this section out if you want to define specific restrictions.
    {"action": "accept", "src": ["*"], "dst": ["*:*"]},
  ],
}

```

### Request example (response in JSON format)

```sh
curl "https://api.tailscale.com/api/v2/tailnet/example.com/acl" \
  -u "tskey-api-xxxxx:"
  -H "Accept: application/json"
```

### Response in JSON format

On success, returns a 200 status code and the tailnet policy file in JSON format.
No errors or warnings are returned.

```jsonc
...
Content-Type: application/json
Etag: "e0b2816b418b3f266309d94426ac7668ab3c1fa87798785bf82f1085cc2f6d9c"
...
{
   "acls" : [
      {
         "action" : "accept",
         "ports" : [
            "*:*"
         ],
         "users" : [
            "*"
         ]
      }
   ],
   "groups" : {
      "group:example" : [
         "user1@example.com",
         "user2@example.com"
      ]
   },
   "hosts" : {
      "example-host-1" : "100.100.100.100"
   }
}
```

### Request example (with details)

```sh
curl "https://api.tailscale.com/api/v2/tailnet/example.com/acl?details=1" \
  -u "tskey-api-xxxxx:"
```

### Response (with details)

On success, returns a 200 status code and the tailnet policy file in a base64-encoded string representation of the huJSON format.
In addition, errors and warnings are returned.

```sh
{
  "acl": "Ly8gUG9raW5nIGFyb3VuZCBpbiB0aGUgQVBJIGRvY3MsIGhvcGluZyB5b3UnZCBmaW5kIHNvbWV0aGluZyBnb29kLCBlaD8KLy8gV2UgbGlrZSB5b3VyIHN0eWxlISAgR28gZ3JhYiB5b3Vyc2VsZiBhIFRhaWxzY2FsZSB0LXNoaXJ0IGlmIHRoZXJlIGFyZQovLyBzdGlsbCBzb21lIGF2YWlsYWJsZS4gQnV0IHNoaGguLi4gZG9uJ3QgdGVsbCBhbnlvbmUhCi8vCi8vICAgICAgICAgICAgIGh0dHBzOi8vc3dhZy5jb20vZ2lmdC82a29mNGs1Z3B1ZW95ZDB2NXd6MHJkYmMKewoJLy8gRGVjbGFyZSBzdGF0aWMgZ3JvdXBzIG9mIHVzZXJzIGJleW9uZCB0aG9zZSBpbiB0aGUgaWRlbnRpdHkgc2VydmljZS4KCSJncm91cHMiOiB7CgkJImdyb3VwOmV4YW1wbGUiOiBbInVzZXIxQGV4YW1wbGUuY29tIiwgInVzZXIyQGV4YW1wbGUuY29tIl0sCgl9LAoKCS8vIERlY2xhcmUgY29udmVuaWVudCBob3N0bmFtZSBhbGlhc2VzIHRvIHVzZSBpbiBwbGFjZSBvZiBJUCBhZGRyZXNzZXMuCgkiaG9zdHMiOiB7CgkJImV4YW1wbGUtaG9zdC0xIjogIjEwMC4xMDAuMTAwLjEwMCIsCgl9LAoKCS8vIEFjY2VzcyBjb250cm9sIGxpc3RzLgoJImFjbHMiOiBbCgkJLy8gTWF0Y2ggYWJzb2x1dGVseSBldmVyeXRoaW5nLgoJCS8vIENvbW1lbnQgdGhpcyBzZWN0aW9uIG91dCBpZiB5b3Ugd2FudCB0byBkZWZpbmUgc3BlY2lmaWMgcmVzdHJpY3Rpb25zLgoJCXsiYWN0aW9uIjogImFjY2VwdCIsICJ1c2VycyI6IFsiKiJdLCAicG9ydHMiOiBbIio6KiJdfSwKCV0sCn0K",
  "warnings": [
    "\"group:example\": user not found: \"user1@example.com\"",
    "\"group:example\": user not found: \"user2@example.com\""
  ],
  "errors": null
}
```

<a href="tailnet-acl-post"></a>

## Update policy file

```http
POST /api/v2/tailnet/{tailnet}/acl`
```

Sets the ACL for the given tailnet.
HuJSON and JSON are both accepted inputs.
An `If-Match` header can be set to avoid missed updates.

On success, returns the updated ACL in JSON or HuJSON according to the `Accept` header.
Otherwise, errors are returned for incorrectly defined ACLs, ACLs with failing tests on attempted updates, and mismatched `If-Match` header and ETag.

### Parameters

#### tailnet (required in URL path)

The tailnet organization name.

#### `If-Match` (optional in request header)

This is a safety mechanism to avoid overwriting other users' updates to the tailnet policy file.

- Set the `If-Match` value to that of the ETag header returned in a `GET` request to `/api/v2/tailnet/{tailnet}/acl`.
  Tailscale compares the ETag value in your request to that of the current tailnet file and only replaces the file if there's a match.
  (A mismatch indicates that another update has been made to the file.)
  For example: `-H "If-Match: \"e0b2816b418\""`
- Alternately, set the `If-Match` value to `ts-default` to ensure that the policy file is replaced
  _only if the current policy file is still the untouched default_ created automatically for each tailnet.
  For example: `-H "If-Match: \"ts-default\""`

#### `Accept` (optional in request header)

Sets the return type of the updated tailnet policy file.
Response is encoded as JSON if `application/json` is requested, otherwise HuJSON will be returned.

#### Tailnet policy file entries (required in `POST` body)

Define the policy file in the `POST` body.
Include the entire policy file.
Note that the supplied object fully replaces your existing tailnet policy file.

The `POST` body should be formatted as JSON or HuJSON.
Learn about the [ACL policy properties you can include in the request](https://tailscale.com/kb/1018/#tailscale-policy-syntax).

### Request example

```sh
POST /api/v2/tailnet/example.com/acl
curl "https://api.tailscale.com/api/v2/tailnet/example.com/acl" \
  -u "tskey-api-xxxxx:" \
  -H "Content-Type: application/json" \
  -H "If-Match: \"e0b2816b418b3f266309d94426ac7668ab3c1fa87798785bf82f1085cc2f6d9c\""
  --data-binary '// Example/default ACLs for unrestricted connections.
{
  // Declare tests to check functionality of ACL rules. User must be a valid user with registered machines.
  "tests": [
    // {"src": "user1@example.com", "accept": ["example-host-1:22"], "deny": ["example-host-2:100"]},
  ],
  // Declare static groups of users beyond those in the identity service.
  "groups": {
    "group:example": [ "user1@example.com", "user2@example.com" ],
  },
  // Declare convenient hostname aliases to use in place of IP addresses.
  "hosts": {
    "example-host-1": "100.100.100.100",
  },
  // Access control lists.
  "acls": [
    // Match absolutely everything. Comment out this section if you want
    // to define specific ACL restrictions.
    { "action": "accept", "users": ["*"], "ports": ["*:*"] },
  ]
}'
```

### Response

A successful response returns an HTTP status of '200' and the modified tailnet policy file in JSON or HuJSON format, depending on the request header.

```jsonc
// Example/default ACLs for unrestricted connections.
{
  // Declare tests to check functionality of ACL rules. User must be a valid user with registered machines.
  "tests": [
    // {"src": "user1@example.com", "accept": ["example-host-1:22"], "deny": ["example-host-2:100"]},
  ],
  // Declare static groups of users beyond those in the identity service.
  "groups": {
    "group:example": ["user1@example.com", "user2@example.com"]
  },
  // Declare convenient hostname aliases to use in place of IP addresses.
  "hosts": {
    "example-host-1": "100.100.100.100"
  },
  // Access control lists.
  "acls": [
    // Match absolutely everything. Comment out this section if you want
    // to define specific ACL restrictions.
    { "action": "accept", "users": ["*"], "ports": ["*:*"] }
  ]
}
```

### Response: failed test error

```
{
    "message": "test(s) failed",
    "data": [
        {
            "user": "user1@example.com",
            "errors": [
                "address \"user2@example.com:400\": want: Accept, got: Drop"
            ]
        }
    ]
}
```

<a href="tailnet-acl-preview-post"></a>

## Preview policy file rule matches

```http
POST /api/v2/tailnet/{tailnet}/acl/preview
```

When given a user or IP port to match against, returns the tailnet policy rules that
apply to that resource without saving the policy file to the server.

### Parameters

#### `tailnet` (required in URL path)

The tailnet organization name.

#### `type` (required in query string)

Specify for which type of resource (user or IP port) matching rules are to be fetched.
Read about [previewing changes in the admin console](https://tailscale.com/kb/1018/#previewing-changes).

- `user`: Specify `user` if the `previewFor` value is a user's email.
  Note that `user` remains in the API for compatibility purposes, but has been replaced by `src` in policy files.
- `ipport`: Specify `ipport` if the `previewFor` value is an IP address and port.
  Note that `ipport` remains in the API for compatibility purposes, but has been replaced by `dst` in policy files.

#### `previewFor` (required in query string)

- If `type=user`, provide the email of a valid user with registered machines.
- If `type=ipport`, provide an IP address + port: `10.0.0.1:80`.

The supplied policy file is queried with this parameter to determine which rules match.

#### Tailnet policy file (required in `POST` body)

Provide the tailnet policy file in the `POST` body in JSON or HuJSON format.
Learn about [tailnet policy file entries](https://tailscale.com/kb/1018).

### Request example

```sh
curl "https://api.tailscale.com/api/v2/tailnet/example.com/acl/preview?previewFor=user1@example.com&type=user" \
  -u "tskey-api-xxxxx:" \
  -H "Content-Type: application/json" \
  --data-binary '// Example/default ACLs for unrestricted connections.
{
  // Declare tests to check functionality of ACL rules. User must be a valid user with registered machines.
  "tests": [
    // {"src": "user1@example.com", "accept": ["example-host-1:22"], "deny": ["example-host-2:100"]},
  ],
  // Declare static groups of users beyond those in the identity service.
  "groups": {
    "group:example": [ "user1@example.com", "user2@example.com" ],
  },
  // Declare convenient hostname aliases to use in place of IP addresses.
  "hosts": {
    "example-host-1": "100.100.100.100",
  },
  // Access control lists.
  "acls": [
    // Match absolutely everything. Comment out this section if you want
    // to define specific ACL restrictions.
    { "action": "accept", "users": ["*"], "ports": ["*:*"] },
  ]
}'
```

### Response

A successful response returns an HTTP status of '200' and a list of rules that apply to the resource supplied as a list of matches as JSON objects.
Each match object includes:

- `users`: array of strings indicating source entities affected by the rule
- `ports`: array of strings representing destinations that can be accessed
- `lineNumber`: integer indicating the rule's location in the policy file

The response also echoes the `type` and `previewFor` values supplied in the request.

```jsonc
{
  "matches": [
    {
      "users": ["*"],
      "ports": ["*:*"],
      "lineNumber": 19
    }
  ],
  "type": "user",
  "previewFor: "user1@example.com"
}
```

<a href="tailnet-acl-validate-post"></a>

## Validate and test policy file

```http
POST /api/v2/tailnet/{tailnet}/acl/validate
```

This method works in one of two modes, neither of which modifies your current tailnet policy file:

- **Run ACL tests:** When the **request body contains ACL tests as a JSON array**,
  Tailscale runs ACL tests against the tailnet's current policy file.
  Learn more about [ACL tests](https://tailscale.com/kb/1018/#tests).
- **Validate a new policy file:** When the **request body is a JSON object**,
  Tailscale interprets the body as a hypothetical new tailnet policy file with new ACLs, including any new rules and tests.
  It validates that the policy file is parsable and runs tests to validate the existing rules.

In either case, this method does not modify the tailnet policy file in any way.

### Parameters for "Run ACL tests" mode

#### `tailnet` (required in URL path)

The tailnet organization name.

#### ACL tests (required in `POST` body)

The `POST` body should be a JSON formatted array of ACL Tests.
Learn more about [tailnet policy file tests](https://tailscale.com/kb/1018/#tests).

### Request example to run ACL tests

```sh
curl "https://api.tailscale.com/api/v2/tailnet/example.com/acl/validate" \
  -u "tskey-api-xxxxx:" \
  -H "Content-Type: application/json" \
  --data-binary '
  [
    {"src": "user1@example.com", "accept": ["example-host-1:22"], "deny": ["example-host-2:100"]}
  ]'
```

### Parameters for "Validate a new policy file" mode

#### `tailnet` (required in URL path)

The tailnet organization name.

#### Entire tailnet policy file (required in `POST` body)

The `POST` body should be a JSON object with a JSON or HuJSON representation of a tailnet policy file.

### Request example to validate a policy file

```sh
curl "https://api.tailscale.com/api/v2/tailnet/example.com/acl/validate" \
  -u "tskey-api-xxxxx:" \
  -H "Content-Type: application/json" \
  --data-binary '
  {
    "acls": [
     { "action": "accept", "src": ["100.105.106.107"], "dst": ["1.2.3.4:*"] },
    ],
    "tests", [
      {"src": "100.105.106.107", "allow": ["1.2.3.4:80"]}
    ],
  }'
```

### Response

The HTTP status code will be '200' if the request was well formed and there were no server errors, even in the case of failing tests or an invalid ACL.
Look at the response body to determine whether there was a problem within your ACL or tests:

- If the tests are valid, an empty body or a JSON object with no `message` is returned.
- If there's a problem, the response body will be a JSON object with a non-empty `message` property and optionally additional details in `data`:

  ```jsonc
  {
    "message": "test(s) failed",
    "data": [
      {
        "user": "user1@example.com",
        "errors": ["address \"2.2.2.2:22\": want: Drop, got: Accept"]
      }
    ]
  }
  ```

If your tailnet has [user and group provisioning](https://tailscale.com/kb/1180/sso-okta-scim/) turned on, we will also warn you about
any groups that are used in the policy file that are not being synced from SCIM. Explicitly defined groups will not trigger this warning.

```jsonc
{
  "message": "warning(s) found",
  "data": [
    {
      "user": "group:unknown@example.com",
      "warnings": [
        "group is not syncing from SCIM and will be ignored by rules in the policy file"
      ]
    }
  ]
}
```

<a href="tailnet-devices"></a>

## List tailnet devices

```http
GET /api/v2/tailnet/{tailnet}/devices
```

Lists the devices in a tailnet.
Optionally use the `fields` query parameter to explicitly indicate which fields are returned.

### Parameters

#### `tailnet` (required in URL path)

The tailnet organization name.

#### `fields` (optional in query string)

Controls whether the response returns **all** fields or only a predefined subset of fields.
Currently, there are two supported options:

- **`all`:** return all fields in the response
- **`default`:** return all fields **except**:
  - `enabledRoutes`
  - `advertisedRoutes`
  - `clientConnectivity` (which contains the following fields: `mappingVariesByDestIP`, `derp`, `endpoints`, `latency`, and `clientSupports`)

If the `fields` parameter is not supplied, then the default (limited fields) option is used.

### Request example for default set of fields

```sh
curl "https://api.tailscale.com/api/v2/tailnet/example.com/devices" \
  -u "tskey-api-xxxxx:"
```

### Request example for all fields

```sh
curl "https://api.tailscale.com/api/v2/tailnet/example.com/devices?fields=all" \
  -u "tskey-api-xxxxx:"
```

### Response

On success, returns a 200 status code and a JSON array of the tailnet devices and their details.

## Tailnet keys

These methods operate primarily on auth keys, and in some cases on [API access tokens](#authentication).

- Auth keys: Pre-authentication keys (or "auth keys") let you register new devices on a tailnet without needing to sign in via a web browser.
  Auth keys are identifiable by the prefix `tskey-auth-`. Learn more about [auth keys](https://tailscale.com/kb/1085/).

- API access tokens: used to [authenticate API requests](#authentication).

If you authenticate with a user-owned API access token, all the methods on tailnet keys operate on _keys owned by that user_.
If you authenticate with an access token derived from an OAuth client, then these methods operate on _keys owned by the tailnet_.
Learn more about [OAuth clients](https://tailscale.com/kb/1215).

The `POST /api/v2/tailnet/{tailnet}/keys` method is used to create auth keys only.
The remaining three methods operate on auth keys and API access tokens.

### Attributes

```jsonc
{
  // capabilities (JSON object) is a mapping of resources to permissible
  // actions.
  "capabilities": {

    // devices (JSON object) specifies the key's permissions over devices.
    "devices": {

      // create (JSON object) specifies the key's permissions when
      // creating devices.
      "create": {

        // reusable (boolean) for auth keys only; reusable auth keys
        // can be used multiple times to register different devices.
        // Learn more about reusable auth keys at
        // https://tailscale.com/kb/1085/#types-of-auth-keys
        "reusable": false,

        // ephemeral (boolean) for auth keys only; ephemeral keys are
        // used to connect and then clean up short-lived devices.
        // Learn about ephemeral nodes at https://tailscale.com/kb/1111/.
        "ephemeral": false,

        // preauthorized (boolean) for auth keys only; these are also
        // referred to as "pre-approved" keys. 'true' means that devices
        // registered with this key won't require additional approval from a
        // tailnet admin.
        // Learn about device approval at https://tailscale.com/kb/1099/.
        "preauthorized": false,

        // tags (string) are the tags that will be set on devices registered
        // with this key.
        // Learn about tags at https://tailscale.com/kb/1068/.
        "tags": [
          "tag:example"
            ]
          }
        }
  }

  // expirySeconds (int) is the duration in seconds a new key is valid.
  "expirySeconds": 86400

  // description (string) is an optional short phrase that describes what
  // this key is used for. It can be a maximum of 50 alphanumeric characters.
  // Hyphens and underscores are also allowed.
  "description": "short description of key purpose"
}
```

<a href="tailnet-keys-get"></a>

## List tailnet keys

```http
GET /api/v2/tailnet/{tailnet}/keys
```

Returns a list of active auth keys and API access tokens. The set of keys returned depends on the access token used to make the request:

- If the API call is made with a user-owned API access token, this returns only the keys owned by that user.
- If the API call is made with an access token derived from an OAuth client, this returns all keys owned directly by the tailnet.

### Parameters

#### `tailnet` (required in URL path)

The tailnet organization name.

### Request example

```sh
curl "https://api.tailscale.com/api/v2/tailnet/example.com/keys" \
  -u "tskey-api-xxxxx:"
```

### Response

Returns a JSON object with the IDs of all active keys.

```jsonc
{
  "keys": [
    { "id": "XXXX14CNTRL" },
    { "id": "XXXXZ3CNTRL" },
    { "id": "XXXX43CNTRL" },
    { "id": "XXXXgj1CNTRL" }
  ]
}
```

<a href="tailnet-keys-post"></a>

## Create auth key

```http
POST /api/v2/tailnet/{tailnet}/keys
```

Creates a new auth key in the specified tailnet.
The key will be associated with the user who owns the API access token used to make this call,
or, if the call is made with an access token derived from an OAuth client, the key will be owned by the tailnet.

Returns a JSON object with the supplied capabilities in addition to the generated key.
The key should be recorded and kept safe and secure because it wields the capabilities specified in the request.
The identity of the key is embedded in the key itself and can be used to perform operations on the key (e.g., revoking it or retrieving information about it).
The full key can no longer be retrieved after the initial response.

### Parameters

#### `tailnet` (required in URL path)

The tailnet organization name.

#### Tailnet key object (required in `POST` body)

Supply the tailnet key attributes as a JSON object in the `POST` body following the request example below.

At minimum, the request `POST` body must have a `capabilities` object (see below).
With nothing else supplied, such a request generates a single-use key with no tags.

Note the following about required vs. optional values:

- **`capabilities`:** A `capabilities` object is required and must contain `devices`.

- **`devices`:** A `devices` object is required within `capabilities`, but can be an empty JSON object.

- **`tags`:** Whether tags are required or optional depends on the owner of the auth key:

  - When creating an auth key _owned by the tailnet_ (using OAuth), it must have tags.
    The auth tags specified for that new auth key must exactly match the tags that are on the OAuth client used to create that auth key (or they must be tags that are owned by the tags that are on the OAuth client used to create the auth key).
  - When creating an auth key _owned by a user_ (using a user's access token), tags are optional.

- **`expirySeconds`:** Optional in `POST` body.
  Specifies the duration in seconds until the key should expire.
  Defaults to 90 days if not supplied.

- **`description`:** Optional in `POST` body.
  A short string specifying the purpose of the key. Can be a maximum of 50 alphanumeric characters. Hyphens and spaces are also allowed.

### Request example

```jsonc
curl "https://api.tailscale.com/api/v2/tailnet/example.com/keys" \
  -u "tskey-api-xxxxx:" \
  -H "Content-Type: application/json" \
  --data-binary '
{
  "capabilities": {
    "devices": {
      "create": {
        "reusable": false,
        "ephemeral": false,
        "preauthorized": false,
        "tags": [ "tag:example" ]
      }
    }
  },
  "expirySeconds": 86400,
  "description": "dev access"
}'
```

### Response

The response is a JSON object that includes the `key` value, which will only be returned once.
Record and safely store the `key` returned.
It holds the capabilities specified in the request and can no longer be retrieved by the server.

```jsonc
{
  "id": "k123456CNTRL",
  "key": "tskey-auth-k123456CNTRL-abcdefghijklmnopqrstuvwxyz",
  "created": "2021-12-09T23:22:39Z",
  "expires": "2022-03-09T23:22:39Z",
  "revoked": "2022-03-12T23:22:39Z",
  "capabilities": {
    "devices": {
      "create": {
        "reusable": false,
        "ephemeral": false,
        "preauthorized": false,
        "tags": ["tag:example"]
      }
    }
  },
  "description": "dev access"
}
```

<a href="tailnet-keys-key-get"></a>

## Get key

```http
GET /api/v2/tailnet/{tailnet}/keys/{keyid}
```

Returns a JSON object with information about a specific key, such as its creation and expiration dates and its capabilities.

### Parameters

#### `tailnet` (required in URL path)

The tailnet organization name.

#### `keyId` (required in URL path)

The ID of the key.

### Request example

```sh
curl "https://api.tailscale.com/api/v2/tailnet/example.com/keys/k123456CNTRL" \
  -u "tskey-api-xxxxx:"
```

### Response

The response is a JSON object with information about the key supplied.

```jsonc
{
  "id": "abc123456CNTRL",
  "created": "2022-05-05T18:55:44Z",
  "expires": "2022-08-03T18:55:44Z",
  "capabilities": {
    "devices": {
      "create": {
        "reusable": false,
        "ephemeral": true,
        "preauthorized": false,
        "tags": ["tag:bar", "tag:foo"]
      }
    }
  },
  "description": "dev access"
}
```

Response for a revoked (deleted) or expired key will have an `invalid` field set to `true`:

```jsonc
{
  "id": "abc123456CNTRL",
  "created": "2022-05-05T18:55:44Z",
  "expires": "2022-08-03T18:55:44Z",
  "revoked": "2023-04-01T20:50:00Z",
  "invalid": true
}
```

<a href="tailnet-keys-key-delete"></a>

## Delete key

```http
DELETE /api/v2/tailnet/{tailnet}/keys/{keyid}
```

Deletes a specific key.

### Parameters

#### `tailnet` (required in URL path)

The tailnet organization name.

#### `keyId` (required in URL path)

The ID of the key. The key ID can be found in the [admin console](https://login.tailscale.com/admin/settings/keys).

### Request example

```sh
curl -X DELETE 'https://api.tailscale.com/api/v2/tailnet/example.com/keys/k123456CNTRL' \
  -u "tskey-api-xxxxx:"
```

### Response

This returns status 200 upon success.

<a href="tailnet-dns"></a>

## DNS

The tailnet DNS methods are provided for fetching and modifying various DNS settings for a tailnet.
These include nameservers, DNS preferences, and search paths.
Learn more about [DNS in Tailscale](https://tailscale.com/kb/1054/).

<a href="tailnet-dns-nameservers-get"></a>

## Get nameservers

```http
GET /api/v2/tailnet/{tailnet}/dns/nameservers
```

Lists the global DNS nameservers for a tailnet.

### Parameters

#### `tailnet` (required in URL path)

The tailnet organization name.

### Request example

```sh
curl "https://api.tailscale.com/api/v2/tailnet/example.com/dns/nameservers" \
  -u "tskey-api-xxxxx:"
```

### Response

```jsonc
{
  "dns": ["8.8.8.8"]
}
```

<a href="tailnet-dns-nameservers-post"></a>

## Set nameservers

```http
POST /api/v2/tailnet/{tailnet}/dns/nameservers
```

Replaces the list of global DNS nameservers for the given tailnet with the list supplied in the request.
Note that changing the list of DNS nameservers may also affect the status of MagicDNS (if MagicDNS is on; learn about [MagicDNS](https://tailscale.com/kb/1081).
If all nameservers have been removed, MagicDNS will be automatically disabled (until explicitly turned back on by the user).

### Parameters

#### `tailnet` (required in URL path)

The tailnet organization name.

#### `dns` (required in `POST` body)

The new list of DNS nameservers in JSON.

```jsonc
{
  "dns": ["8.8.8.8"]
}
```

### Request example: adding DNS nameservers with MagicDNS on

Adding DNS nameservers with the MagicDNS on:

```sh
curl "https://api.tailscale.com/api/v2/tailnet/example.com/dns/nameservers" \
  -u "tskey-api-xxxxx:" \
  -H "Content-Type: application/json" \
  --data-binary '{"dns": ["8.8.8.8"]}'
```

### Response example: adding DNS nameservers, MagicDNS on

The response is a JSON object containing the new list of nameservers and the status of MagicDNS.

```jsonc
{
  "dns": ["8.8.8.8"],
  "magicDNS": true
}
```

### Request example: removing all DNS nameservers, MagicDNS on

```sh
curl "https://api.tailscale.com/api/v2/tailnet/example.com/dns/nameservers" \
  -u "tskey-api-xxxxx:" \
  -H "Content-Type: application/json" \
  --data-binary '{"dns": []}'
```

### Response example: removing all DNS nameservers with MagicDNS on

The response is a JSON object containing the new list of nameservers and the status of MagicDNS.

```jsonc
{
  "dns": [],
  "magicDNS": false
}
```

<a href="tailnet-dns-preferences-get"></a>

## Get DNS preferences

```http
GET /api/v2/tailnet/{tailnet}/dns/preferences`
```

Retrieves the DNS preferences that are currently set for the given tailnet.

### Parameters

#### `tailnet` (required in URL path)

The tailnet organization name.

### Request example

```sh
curl "https://api.tailscale.com/api/v2/tailnet/example.com/dns/preferences" \
  -u "tskey-api-xxxxx:"
```

### Response

```jsonc
{
  "magicDNS": false
}
```

<a href="tailnet-dns-preferences-post"></a>

## Set DNS preferences

```http
POST /api/v2/tailnet/{tailnet}/dns/preferences
```

Set the DNS preferences for a tailnet; specifically, the MagicDNS setting.
Note that MagicDNS is dependent on DNS servers.
Learn about [MagicDNS](https://tailscale.com/kb/1081).

If there is at least one DNS server, then MagicDNS can be enabled.
Otherwise, it returns an error.

Note that removing all nameservers will turn off MagicDNS.
To reenable it, nameservers must be added back, and MagicDNS must be explicitly turned on.

### Parameters

#### `tailnet` (required in URL path)

The tailnet organization name.

#### DNS preference (required in `POST` body)

The DNS preferences in JSON. Currently, MagicDNS is the only setting available:

- **`magicDNS`:** Automatically registers DNS names for devices in your tailnet.

```jsonc
{
  "magicDNS": true
}
```

### Request example

```sh
curl "https://api.tailscale.com/api/v2/tailnet/example.com/dns/preferences" \
  -u "tskey-api-xxxxx:" \
  -H "Content-Type: application/json" \
  --data-binary '{"magicDNS": true}'
```

### Response

If there are no DNS servers, this returns an error message:

```jsonc
{
  "message": "need at least one nameserver to enable MagicDNS"
}
```

If there are DNS servers, this returns the MagicDNS status:

```jsonc
{
  "magicDNS": true
}
```

<a href="tailnet-dns-searchpaths-get"></a>

## Get search paths

```http
GET /api/v2/tailnet/{tailnet}/dns/searchpaths
```

Retrieves the list of search paths, also referred to as _search domains_, that is currently set for the given tailnet.

### Parameters

#### `tailnet` (required in URL path)

The tailnet organization name.

### Request example

```sh
curl "https://api.tailscale.com/api/v2/tailnet/example.com/dns/searchpaths" \
  -u "tskey-api-xxxxx:"
```

### Response

```jsonc
{
  "searchPaths": ["user1.example.com"]
}
```

<a href="tailnet-dns-searchpaths-post"></a>

## Set search paths

```http
POST /api/v2/tailnet/{tailnet}/dns/searchpaths
```

Replaces the list of search paths with the list supplied by the user and returns an error otherwise.

### Parameters

#### `tailnet` (required in URL path)

The tailnet organization name.

#### `searchPaths` (required in `POST` body)

Specify a list of search paths in a JSON object:

```jsonc
{
  "searchPaths": ["user1.example.com", "user2.example.com"]
}
```

### Request example

```sh
curl "https://api.tailscale.com/api/v2/tailnet/example.com/dns/searchpaths" \
  -u "tskey-api-xxxxx:" \
  -H "Content-Type: application/json" \
  --data-binary '{"searchPaths": ["user1.example.com", "user2.example.com"]}'
```

### Response

The response is a JSON object containing the new list of search paths.

```jsonc
{
  "searchPaths": ["user1.example.com", "user2.example.com"]
}
```

## Get split DNS

```http
GET /api/v2/tailnet/{tailnet}/dns/split-dns
```

Retrieves the split DNS settings, which is a map from domains to lists of nameservers, that is currently set for the given tailnet.

### Parameters

#### `tailnet` (required in URL path)

The tailnet organization name.

### Request example

```sh
curl "https://api.tailscale.com/api/v2/tailnet/example.com/dns/split-dns" \
  -u "tskey-api-xxxxx:"
```

### Response

```jsonc
{
  "example.com": ["1.1.1.1", "1.2.3.4"],
  "other.com": ["2.2.2.2"]
}
```

## Update split DNS

```http
PATCH /api/v2/tailnet/{tailnet}/dns/split-dns
```

Performs partial updates of the split DNS settings for a given tailnet. Only domains specified in the request map will be modified. Setting the value of a mapping to "null" clears the nameservers for that domain.

### Parameters

#### `tailnet` (required in URL path)

The tailnet organization name.

#### `PATCH` body format

Specify mappings from domain name to a list of nameservers in a JSON object:

```jsonc
{
  "example.com": ["1.1.1.1", "1.2.3.4"],
  "other.com": ["2.2.2.2"]
}
```

### Request example: updating split DNS settings for multiple domains

```sh
curl -X PATCH "https://api.tailscale.com/api/v2/tailnet/example.com/dns/split-dns" \
  -u "tskey-api-xxxxx:" \
  -H "Content-Type: application/json" \
  --data-binary '{"example.com": ["1.1.1.1", "1.2.3.4"], "other.com": ["2.2.2.2"]}'
```

### Response: updating split DNS settings for multiple domains

The response is a JSON object containing the updated map of split DNS settings.

```jsonc
{
  "example.com": ["1.1.1.1", "1.2.3.4"],
  "other.com": ["2.2.2.2"],
  <existing unmodified key / value pairs>
}
```

### Request example: unsetting nameservers for a domain

```sh
curl -X PATCH "https://api.tailscale.com/api/v2/tailnet/example.com/dns/split-dns" \
  -u "tskey-api-xxxxx:" \
  -H "Content-Type: application/json" \
  --data-binary '{"example.com": null}'
```

### Response: unsetting nameservers for a domain

The response is a JSON object containing the updated map of split DNS settings.

```jsonc
{
  <existing unmodified key / value pairs without example.com>
}
```

## Set split DNS

```http
PUT /api/v2/tailnet/{tailnet}/dns/split-dns
```

Replaces the split DNS settings for a given tailnet. Setting the value of a mapping to "null" clears the nameservers for that domain. Sending an empty object clears nameservers for all domains.

### Parameters

#### `tailnet` (required in URL path)

The tailnet organization name.

#### `PUT` body format

Specify mappings from domain name to a list of nameservers in a JSON object:

```jsonc
{
  "example.com": ["1.2.3.4"],
  "other.com": ["2.2.2.2"]
}
```

### Request example: setting multiple domains

```sh
curl -X PUT "https://api.tailscale.com/api/v2/tailnet/example.com/dns/split-dns" \
  -u "tskey-api-xxxxx:" \
  -H "Content-Type: application/json" \
  --data-binary '{"example.com": ["1.2.3.4"], "other.com": ["2.2.2.2"]}'
```

### Response: unsetting nameservers for a domain

The response is a JSON object containing the updated map of split DNS settings.

```jsonc
{
  "example.com": ["1.2.3.4"],
  "other.com": ["2.2.2.2"]
}
```

### Request example: unsetting all domains

```sh
curl -X PUT "https://api.tailscale.com/api/v2/tailnet/example.com/dns/split-dns" \
  -u "tskey-api-xxxxx:" \
  -H "Content-Type: application/json" \
  --data-binary '{}'
```

### Response: unsetting nameservers for a domain

The response is a JSON object containing the updated map of split DNS settings.

```jsonc
{}
```

## Tailnet user invites

The tailnet user invite methods let you create and list [invites](https://tailscale.com/kb/1371/invite-users).

## List user invites

```http
GET /api/v2/tailnet/{tailnet}/user-invites
```

List all user invites that haven't been accepted.

### Parameters

#### `tailnet` (required in URL path)

The tailnet organization name.

### Request example

```sh
curl -X GET "https://api.tailscale.com/api/v2/tailnet/example.com/user-invites" \
-u "tskey-api-xxxxx:"
```

### Response

```jsonc
[
  {
    "id": "29214",
    "role": "member",
    "tailnetId": 12345,
    "inviterId": 34567,
    "email": "user@example.com",
    "lastEmailSentAt": "2024-05-09T16:13:16.084568545Z",
    "inviteUrl": "https://login.tailscale.com/uinv/<code>"
  },
  {
    "id": "29215",
    "role": "admin",
    "tailnetId": 12345,
    "inviterId": 34567,
    "inviteUrl": "https://login.tailscale.com/uinv/<code>"
  }
]
```

## Create user invites

```http
POST /api/v2/tailnet/{tailnet}/user-invites
```

Create new user invites to join the tailnet.

### Parameters

#### `tailnet` (required in URL path)

The tailnet organization name.

#### List of invite requests (required in `POST` body)

Each invite request is an object with the following optional fields:

- **`role`:** (Optional) Specify a [user role](https://tailscale.com/kb/1138/user-roles) to assign the invited user. Defaults to the `"member"` role. Valid options are:
  - `"member"`: Assign the Member role.
  - `"admin"`: Assign the Admin role.
  - `"it-admin"`: Assign the IT admin role.
  - `"network-admin"`: Assign the Network admin role.
  - `"billing-admin"`: Assign the Billing admin role.
  - `"auditor"`: Assign the Auditor role.
- **`email`:** (Optional) Specify the email to send the created invite. If not set, the endpoint generates and returns an invite URL (but doesn't send it out).

### Request example

```sh
curl -X POST "https://api.tailscale.com/api/v2/tailnet/example.com/user-invites" \
-u "tskey-api-xxxxx:" \
-H "Content-Type: application/json" \
--data-binary '[{"role": "admin", "email":"user@example.com"}]'
```

### Response

```jsonc
[
  {
    "id": "29214",
    "role": "admin",
    "tailnetId": 12345,
    "inviterId": 34567,
    "email": "user@example.com",
    "lastEmailSentAt": "2024-05-09T16:23:26.91778771Z",
    "inviteUrl": "https://login.tailscale.com/uinv/<code>"
  }
]
```

# User invites

A user invite is an active invitation that lets a user join a tailnet with a pre-assigned [user role](https://tailscale.com/kb/1138/user-roles).

Each user invite has a unique ID that is used to identify the invite in API calls.
You can find all user invite IDs for a particular tailnet by [listing user invites](#list-user-invites).

### Attributes

```jsonc
{
  // id (string) is the unique identifier for the invite.
  // Supply this value wherever {userInviteId} is indicated in the endpoint.
  "id": "12346",

  // role is the tailnet user role to assign to the invited user upon accepting
  // the invite. Value options are "member", "admin", "it-admin", "network-admin",
  // "billing-admin", and "auditor".
  "role": "admin",

  // tailnetId is the ID of the tailnet to which the user was invited.
  "tailnetId": 59954,

  // inviterId is the ID of the user who created the invite.
  "inviterId": 22012,

  // email is the email to which the invite was sent.
  // If empty, the invite was not emailed to anyone, but the inviteUrl can be
  // shared manually.
  "email": "user@example.com",

  // lastEmailSentAt is the last time the invite was attempted to be sent to
  // Email. Only ever set if `email` is not empty.
  "lastEmailSentAt": "2024-04-03T21:38:49.333829261Z",

  // inviteUrl is included when `email` is not part of the tailnet's domain,
  // or when `email` is empty. It is the link to accept the invite.
  //
  // When included, anyone with this link can accept the invite.
  // It is not restricted to the person to which the invite was emailed.
  //
  // When `email` is part of the tailnet's domain (has the same @domain.com
  // suffix as the tailnet), the user can join the tailnet automatically by
  // logging in with their domain email at https://login.tailscale.com/start.
  // They'll be assigned the specified `role` upon signing in for the first
  // time.
  "inviteUrl": "https://login.tailscale.com/admin/invite/<code>"
}
```

## Get user invite

```http
GET /api/v2/user-invites/{userInviteId}
```

Retrieve the specified user invite.

### Parameters

#### `userInviteId` (required in URL path)

The ID of the user invite.

### Request example

```sh
curl "https://api.tailscale.com/api/v2/user-invites/29214" \
  -u "tskey-api-xxxxx:"
```

### Response

```jsonc
{
  "id": "29214",
  "role": "admin",
  "tailnetId": 12345,
  "inviterId": 34567,
  "email": "user@example.com",
  "lastEmailSentAt": "2024-05-09T16:23:26.91778771Z",
  "inviteUrl": "https://login.tailscale.com/uinv/<code>"
}
```

## Delete user invite

```http
DELETE /api/v2/user-invites/{userInviteId}
```

Delete the specified user invite.

### Parameters

#### `userInviteId` (required in URL path)

The ID of the user invite.

### Request example

```sh
curl -X DELETE "https://api.tailscale.com/api/v2/user-invites/29214" \
  -u "tskey-api-xxxxx:"
```

### Response

The response is 2xx on success. The response body is an empty JSON object.

## Resend user invite

```http
POST /api/v2/user-invites/{userInviteId}/resend
```

Resend the specified user invite by email. You can only use this if the specified invite was originally created with an email specified. Refer to [creating user invites for a tailnet](#create-user-invites).

Note: Invite resends are rate limited to one per minute.

### Parameters

#### `userInviteId` (required in URL path)

The ID of the user invite.

### Request example

```sh
curl -X POST "https://api.tailscale.com/api/v2/user-invites/29214/resend" \
  -u "tskey-api-xxxxx:"
```

### Response

The response is 2xx on success. The response body is an empty JSON object.

# Device invites

A device invite is an invitation that shares a device with an external user (a user not in the device's tailnet).

Each device invite has a unique ID that is used to identify the invite in API calls.
You can find all device invite IDs for a particular device by [listing all device invites for a device](#list-device-invites).

### Attributes

```jsonc
{
  // id (strings) is the unique identifier for the invite.
  // Supply this value wherever {deviceInviteId} is indicated in the endpoint.
  "id": "12346",

  // created is the creation time of the invite.
  "created": "2024-04-03T21:38:49.333829261Z",

  // tailnetId is the ID of the tailnet to which the shared device belongs.
  "tailnetId": 59954,

  // deviceId is the ID of the device being shared.
  "deviceId": 11055,

  // sharerId is the ID of the user who created the share invite.
  "sharerId": 22012,

  // multiUse specifies whether this device invite can be accepted more than
  // once.
  "multiUse": false,

  // allowExitNode specifies whether the invited user is able to use the
  // device as an exit node when the device is advertising as one.
  "allowExitNode": true,

  // email is the email to which the invite was sent.
  // If empty, the invite was not emailed to anyone, but the inviteUrl can be
  // shared manually.
  "email": "user@example.com",

  // lastEmailSentAt is the last time the invite was attempted to be sent to
  // Email. Only ever set if Email is not empty.
  "lastEmailSentAt": "2024-04-03T21:38:49.333829261Z",

  // inviteUrl is the link to accept the invite.
  // Anyone with this link can accept the invite.
  // It is not restricted to the person to which the invite was emailed.
  "inviteUrl": "https://login.tailscale.com/admin/invite/<code>",

  // accepted is true when share invite has been accepted.
  "accepted": true,

  // acceptedBy is set when the invite has been accepted.
  // It holds information about the user who accepted the share invite.
  "acceptedBy": {
    // id is the ID of the user who accepted the share invite.
    "id": 33223,

    // loginName is the login name of the user who accepted the share invite.
    "loginName": "someone@example.com",

    // profilePicUrl is optionally the profile pic URL for the user who accepted
    // the share invite.
    "profilePicUrl": ""
  }
}
```

## Get device invite

```http
GET /api/v2/device-invites/{deviceInviteId}
```

Retrieve the specified device invite.

### Parameters

#### `deviceInviteId` (required in URL path)

The ID of the device share invite.

### Request example

```sh
curl "https://api.tailscale.com/api/v2/device-invites/12346" \
  -u "tskey-api-xxxxx:"
```

### Response

```jsonc
{
  "id": "12346",
  "created": "2024-04-03T21:38:49.333829261Z",
  "tailnetId": 59954,
  "deviceId": 11055,
  "sharerId": 22012,
  "multiUse": true,
  "allowExitNode": true,
  "email": "user@example.com",
  "lastEmailSentAt": "2024-04-03T21:38:49.333829261Z",
  "inviteUrl": "https://login.tailscale.com/admin/invite/<code>",
  "accepted": false
}
```

## Delete device invite

```http
DELETE /api/v2/device-invites/{deviceInviteId}
```

Delete the specified device invite.

### Parameters

#### `deviceInviteId` (required in URL path)

The ID of the device share invite.

### Request example

```sh
curl -X DELETE "https://api.tailscale.com/api/v2/device-invites/12346" \
  -u "tskey-api-xxxxx:"
```

### Response

The response is 2xx on success. The response body is an empty JSON object.

## Resend device invite

```http
POST /api/v2/device-invites/{deviceInviteId}/resend
```

Resend the specified device invite by email. You can only use this if the specified invite was originally created with an email specified. Refer to [creating device invites for a device](#create-device-invites).

Note: Invite resends are rate limited to one per minute.

### Parameters

#### `deviceInviteId` (required in URL path)

The ID of the device share invite.

### Request example

```sh
curl -X POST "https://api.tailscale.com/api/v2/device-invites/12346/resend" \
  -u "tskey-api-xxxxx:"
```

### Response

The response is 2xx on success. The response body is an empty JSON object.

## Accept device invite

```http
POST /api/v2/device-invites/-/accept
```

Resend the specified device invite by email. This can only be used if the specified invite was originally created with an email specified.
See [creating device invites for a device](#create-device-invites).

Note that invite resends are rate limited to once per minute.

### Parameters

#### `invite` (required in `POST` body)

The URL of the invite (in the form "https://login.tailscale.com/admin/invite/{code}") or the "{code}" component of the URL.

### Request example

```sh
curl -X POST "https://api.tailscale.com/api/v2/device-invites/-/accept" \
  -u "tskey-api-xxxxx:" \
  -H "Content-Type: application/json" \
  --data-binary '[{"invite": "https://login.tailscale.com/admin/invite/xxxxxx"}]'
```

### Response

```jsonc
{
  "device": {
    "id": "11055",
    "os": "iOS",
    "name": "my-phone",
    "fqdn": "my-phone.something.ts.net",
    "ipv4": "100.x.y.z",
    "ipv6": "fd7a:115c:x::y:z",
    "includeExitNode": false
  },
  "sharer": {
    "id": "22012",
    "displayName": "Some User",
    "loginName": "someuser@example.com",
    "profilePicURL": ""
  },
  "acceptedBy": {
    "id": "33233",
    "displayName": "Another User",
    "loginName": "anotheruser@exmaple2.com",
    "profilePicURL": ""
  }
}
```