Skip to content
This repository was archived by the owner on Jul 27, 2023. It is now read-only.

Commit 572084b

Browse files
Added Update Site Templates and examples
1 parent d7b23aa commit 572084b

3 files changed

Lines changed: 323 additions & 2 deletions

File tree

Examples/AP_version_compliance.csv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
site_name,id,name
2+
Idaho,,
3+
,4599cb58-e197-4bc1-b8da-xxxxxxxxxxxx,TestSite
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
site_name,rftemplate_id,networktemplate_id
2+
IDA,72138cc0-ed78-4c85-a98a-790526db88f5,566ab79d-aef2-43b9-a19b-3657c69df3ed
3+
NEV,72138cc0-ed78-4c85-a98a-790526db88f5,566ab79d-aef2-43b9-a19b-3657c69df3ed

Postman Collection/Mist_Runner_collection.json.json

Lines changed: 317 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"info": {
33
"_postman_id": "f8534122-72a7-4d7e-81ca-3b19771a88f3",
4-
"name": "Mist Runner Collections 0.3.2",
4+
"name": "Mist Runner Collections 0.3.3",
55
"description": "This collection will use a CSV Template to create multiple sites via the Mist API.\n\nIt also uses a google API to get the lat/long of the address and use the properly formatted address returned from Google Maps.\n\n\nRequired Environmental Variables:\n\n{{apitoken}} This your Mist dashboard API token. It should have permissions to create sites\n{{google_api_token}} This is a google API token that has access to geocode APIs.\n\n\nCSV Required Values:\nsite_name\nsite_address (Note, must be URL Encoded (replace \" \" with \"+\" and enclosed in quotes)\n\nCSV Optional Values:\nsite_groups\nrf_template_id\n\nExample CSV:\n\nsite_name,site_address,site_groups,rf_template_id\n```\nAdonis,\"5592+S+Adonis+Pl,+Boise,+ID+83716\",xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\n```",
66
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
77
},
@@ -1339,7 +1339,6 @@
13391339
"// Ensure all collection variables are removed before running.",
13401340
"pm.collectionVariables.unset(\"c_site_name\");",
13411341
"pm.collectionVariables.unset(\"c_site_id\");",
1342-
"",
13431342
"//Handling of digit only sites with quotes.",
13441343
"var formatted_string = pm.iterationData.get(\"site_name\")",
13451344
"if (!!pm.iterationData.get(\"site_name\")) {",
@@ -1354,6 +1353,9 @@
13541353
" pm.collectionVariables.set(\"c_site_name\", pm.iterationData.get(\"site_name\"))",
13551354
" }",
13561355
"}",
1356+
"else if (!!pm.iterationData.get(\"name\")) {",
1357+
" pm.collectionVariables.set(\"c_site_name\", pm.iterationData.get(\"name\"))",
1358+
" }",
13571359
"console.info(`Site Name = ${pm.collectionVariables.get(\"c_site_name\")}`)"
13581360
],
13591361
"type": "text/javascript"
@@ -1502,6 +1504,315 @@
15021504
}
15031505
]
15041506
},
1507+
{
1508+
"name": "Update Site Templates",
1509+
"item": [
1510+
{
1511+
"name": "getSiteIDByName_Templates",
1512+
"event": [
1513+
{
1514+
"listen": "test",
1515+
"script": {
1516+
"exec": [
1517+
"console.log(`Starting Site ${pm.iterationData.get(\"site_name\")}`)",
1518+
"var nextRequest = null",
1519+
"var foundDup = false",
1520+
"var jsonData = JSON.parse(responseBody);",
1521+
"",
1522+
"",
1523+
"",
1524+
"if (!!pm.collectionVariables.get(\"c_site_name\")) {",
1525+
" console.info(`searching for site ${pm.collectionVariables.get(\"c_site_name\")} `);",
1526+
" for (var i = 0; i < jsonData.length; i++) {",
1527+
" if (jsonData[i].name == pm.collectionVariables.get(\"c_site_name\")) {",
1528+
" pm.collectionVariables.set(\"c_site_id\", jsonData[i].id)",
1529+
" console.info(\"Found Site\")",
1530+
" console.info(`Site ID = ${pm.collectionVariables.get(\"c_site_id\")}`)",
1531+
" nextRequest = \"updateSite_Templates\"",
1532+
" }",
1533+
"}",
1534+
"}",
1535+
"else if (!!pm.iterationData.get(\"id\")) {",
1536+
" pm.collection.set(\"c_site_id\", pm.iterationData.get(\"id\"))",
1537+
" nextRequest = \"updateSite_Templates\"",
1538+
"};",
1539+
"",
1540+
"var template_data = {}",
1541+
"",
1542+
"",
1543+
"if(!!pm.iterationData.get(\"networktemplate_id\")){",
1544+
" template_data[\"networktemplate_id\"] = pm.iterationData.get(\"networktemplate_id\");",
1545+
"};",
1546+
"if(!!pm.iterationData.get(\"alarmtemplate_id\")){",
1547+
" template_data[\"alarmtemplate_id\"] = pm.iterationData.get(\"alarmtemplate_id\");",
1548+
"};",
1549+
"if(!!pm.iterationData.get(\"rftemplate_id\")){",
1550+
" template_data[\"rftemplate_id\"] = pm.iterationData.get(\"rftemplate_id\");",
1551+
"};",
1552+
"if(!!pm.iterationData.get(\"secpolicy_id\")){",
1553+
" template_data[\"secpolicy_id\"] = pm.iterationData.get(\"secpolicy_id\");",
1554+
"};",
1555+
"",
1556+
"pm.collectionVariables.set(\"c_site_template_settings\", JSON.stringify(template_data))",
1557+
"",
1558+
"console.info(JSON.stringify(pm.collectionVariables.get(\"c_site_template_settings\")))",
1559+
"",
1560+
"pm.test(\"Status code is 200\", function() {",
1561+
" pm.expect(pm.response.code).to.equal(200);",
1562+
"});",
1563+
"",
1564+
"",
1565+
"",
1566+
"console.log(`setting next request ${nextRequest}`);",
1567+
"postman.setNextRequest(nextRequest);"
1568+
],
1569+
"type": "text/javascript"
1570+
}
1571+
},
1572+
{
1573+
"listen": "prerequest",
1574+
"script": {
1575+
"exec": [
1576+
"// Ensure all collection variables are removed before running.",
1577+
"pm.collectionVariables.unset(\"c_site_name\");",
1578+
"pm.collectionVariables.unset(\"c_site_id\");",
1579+
"//Handling of digit only sites with quotes.",
1580+
"var formatted_string = pm.iterationData.get(\"site_name\")",
1581+
"if (!!pm.iterationData.get(\"site_name\")) {",
1582+
" if (formatted_string.includes(\"\\'\") || formatted_string.includes(\"\\\"\")) {",
1583+
" console.info(\"stripping formatting of site_name\")",
1584+
" formatted_string = formatted_string.replace(/'/g, \"\");",
1585+
" formatted_string = formatted_string.replace(/\"/g, \"\");",
1586+
" console.log(`Formatted Name ${formatted_string}`);",
1587+
" pm.collectionVariables.set(\"c_site_name\", formatted_string)",
1588+
" }",
1589+
" else {",
1590+
" pm.collectionVariables.set(\"c_site_name\", pm.iterationData.get(\"site_name\"))",
1591+
" }",
1592+
"}",
1593+
"else if (!!pm.iterationData.get(\"name\")) {",
1594+
" pm.collectionVariables.set(\"c_site_name\", pm.iterationData.get(\"name\"))",
1595+
" }",
1596+
"console.info(`Site Name = ${pm.collectionVariables.get(\"c_site_name\")}`)"
1597+
],
1598+
"type": "text/javascript"
1599+
}
1600+
}
1601+
],
1602+
"request": {
1603+
"method": "GET",
1604+
"header": [],
1605+
"url": {
1606+
"raw": "https://{{host}}/api/v1/orgs/:orgr_id/sites",
1607+
"protocol": "https",
1608+
"host": [
1609+
"{{host}}"
1610+
],
1611+
"path": [
1612+
"api",
1613+
"v1",
1614+
"orgs",
1615+
":orgr_id",
1616+
"sites"
1617+
],
1618+
"variable": [
1619+
{
1620+
"key": "orgr_id",
1621+
"value": "{{org_id}}",
1622+
"type": "string"
1623+
}
1624+
]
1625+
}
1626+
},
1627+
"response": [
1628+
{
1629+
"name": "ok",
1630+
"originalRequest": {
1631+
"method": "GET",
1632+
"header": [],
1633+
"url": {
1634+
"raw": "",
1635+
"variable": [
1636+
{
1637+
"key": "orgr_id",
1638+
"value": ""
1639+
}
1640+
]
1641+
}
1642+
},
1643+
"status": "OK",
1644+
"code": 200,
1645+
"_postman_previewlanguage": "json",
1646+
"header": [],
1647+
"cookie": [],
1648+
"body": "[\n {\n \"name\": \"Mist Office\",\n \"timezone\": \"America/Los_Angeles\",\n \"country_code\": \"US\",\n \"rftemplate_id\": \"bb8a9017-1e36-5d6c-6f2b-551abe8a76a2\",\n \"secpolicy_id\": \"3bcd0beb-5d0a-4cbd-92c1-14aea91e98ef\",\n \"alarmtemplate_id\": \"684dfc5c-fe77-2290-eb1d-ef3d677fe168\",\n \"latlng\": {\n \"lat\": 37.295833,\n \"lng\": -122.032946\n },\n \"sitegroup_ids\": [\n \"581328b6-e382-f54e-c9dc-999983183a34\",\n \"f57096b9-0c2f-4df6-c77b-ae6ae87a3d43\"\n ],\n \"address\": \"1601 S. Deanza Blvd., Cupertino, CA, 95014\"\n }\n]"
1649+
}
1650+
]
1651+
},
1652+
{
1653+
"name": "updateSite_Templates",
1654+
"event": [
1655+
{
1656+
"listen": "prerequest",
1657+
"script": {
1658+
"exec": [
1659+
""
1660+
],
1661+
"type": "text/javascript"
1662+
}
1663+
},
1664+
{
1665+
"listen": "test",
1666+
"script": {
1667+
"exec": [
1668+
"var nextRequest = null;",
1669+
"let jsonData = pm.response.json();",
1670+
"",
1671+
"if (!!pm.iterationData.get(\"rftemplate_id\")){",
1672+
" pm.test(\"rf_template_id is set\", function() {",
1673+
" pm.expect(pm.iterationData.get(\"rftemplate_id\")).to.equal(jsonData['rftemplate_id']);",
1674+
" });",
1675+
"}",
1676+
"if (!!pm.iterationData.get(\"networktemplate_id\")){",
1677+
" pm.test(\"networktemplate_id is set\", function() {",
1678+
" pm.expect(pm.iterationData.get(\"networktemplate_id\")).to.equal(jsonData['networktemplate_id']);",
1679+
" });",
1680+
"}",
1681+
"if (!!pm.iterationData.get(\"alarmtemplate_id\")){",
1682+
" pm.test(\"alarmtemplate_id is set\", function() {",
1683+
" pm.expect(pm.iterationData.get(\"alarmtemplate_id\")).to.equal(jsonData['alarmtemplate_id']);",
1684+
" });",
1685+
"}",
1686+
"if (!!pm.iterationData.get(\"secpolicy_id\")){",
1687+
" pm.test(\"secpolicy_id is set\", function() {",
1688+
" pm.expect(pm.iterationData.get(\"secpolicy_id\")).to.equal(jsonData['secpolicy_id']);",
1689+
" });",
1690+
"}",
1691+
"",
1692+
"",
1693+
"",
1694+
"console.info(\"Updated site: \" + jsonData.name);",
1695+
"postman.setNextRequest(nextRequest);"
1696+
],
1697+
"type": "text/javascript"
1698+
}
1699+
}
1700+
],
1701+
"protocolProfileBehavior": {
1702+
"disabledSystemHeaders": {
1703+
"accept-encoding": true,
1704+
"connection": true,
1705+
"user-agent": true
1706+
}
1707+
},
1708+
"request": {
1709+
"method": "PUT",
1710+
"header": [],
1711+
"body": {
1712+
"mode": "raw",
1713+
"raw": "{{c_site_template_settings}}",
1714+
"options": {
1715+
"raw": {
1716+
"language": "json"
1717+
}
1718+
}
1719+
},
1720+
"url": {
1721+
"raw": "https://{{host}}/api/v1/sites/:site_id",
1722+
"protocol": "https",
1723+
"host": [
1724+
"{{host}}"
1725+
],
1726+
"path": [
1727+
"api",
1728+
"v1",
1729+
"sites",
1730+
":site_id"
1731+
],
1732+
"variable": [
1733+
{
1734+
"key": "site_id",
1735+
"value": "{{c_site_id}}"
1736+
}
1737+
]
1738+
},
1739+
"description": "#### Body Parameters\n**Parameter**|**Type**|**Description** \n:-------------: |:-------------: |:-------------: \nname|string|Required. The name of the site\ntimezone|string|Timezone the site is at\ncountry_code|string|country code for the site (for AP config generation), in two-character\nlatlng|latlng|site location\naddress|string|full address of the site\nlat|float|latitude\nlng|float|longitude\nsitegroup_ids|list|sitegroups this site belongs to\nrftemplate_id|string|RF Template ID, this takes precedence over Site Settings\nsecpolicy_id|string|SecPolicy ID\nalarmtemplate_id|string|Alarm Template ID, this takes precedence over the Org-level alarmtemplate_id"
1740+
},
1741+
"response": [
1742+
{
1743+
"name": "OK",
1744+
"originalRequest": {
1745+
"method": "POST",
1746+
"header": [
1747+
{
1748+
"key": "Content-Type",
1749+
"name": "Content-Type",
1750+
"type": "text",
1751+
"value": "application/json"
1752+
}
1753+
],
1754+
"body": {
1755+
"mode": "raw",
1756+
"raw": "{\n \"name\": \"Mist Office\",\n \"timezone\": \"America/Los_Angeles\",\n \"country_code\": \"US\",\n \"rftemplate_id\": \"bb8a9017-1e36-5d6c-6f2b-551abe8a76a2\",\n \"secpolicy_id\": \"3bcd0beb-5d0a-4cbd-92c1-14aea91e98ef\",\n \"alarmtemplate_id\": \"684dfc5c-fe77-2290-eb1d-ef3d677fe168\",\n\n \"latlng\": { \"lat\": 37.295833, \"lng\": -122.032946 },\n \"sitegroup_ids\": [ \"581328b6-e382-f54e-c9dc-999983183a34\", \"f57096b9-0c2f-4df6-c77b-ae6ae87a3d43\" ],\n \"address\": \"1601 S. Deanza Blvd., Cupertino, CA, 95014\"\n}",
1757+
"options": {
1758+
"raw": {
1759+
"language": "json"
1760+
}
1761+
}
1762+
},
1763+
"url": {
1764+
"raw": "https://{{host}}/api/v1/orgs/:org_id/sites",
1765+
"protocol": "https",
1766+
"host": [
1767+
"{{host}}"
1768+
],
1769+
"path": [
1770+
"api",
1771+
"v1",
1772+
"orgs",
1773+
":org_id",
1774+
"sites"
1775+
],
1776+
"variable": [
1777+
{
1778+
"key": "org_id",
1779+
"value": ""
1780+
}
1781+
]
1782+
}
1783+
},
1784+
"status": "OK",
1785+
"code": 200,
1786+
"_postman_previewlanguage": "json",
1787+
"header": [],
1788+
"cookie": [],
1789+
"body": "{\n \"id\": \"4ac1dcf4-9d8b-7211-65c4-057819f0862b\",\n \"name\": \"Mist Office\",\n \"timezone\": \"America/Los_Angeles\",\n \"country_code\": \"US\",\n \"latlng\": {\n \"lat\": 37.295833,\n \"lng\": -122.032946\n },\n \"sitegroup_ids\": [\n \"581328b6-e382-f54e-c9dc-999983183a34\",\n \"f57096b9-0c2f-4df6-c77b-ae6ae87a3d43\"\n ],\n \"address\": \"1601 S. Deanza Blvd., Cupertino, CA, 95014\"\n}"
1790+
}
1791+
]
1792+
}
1793+
],
1794+
"description": "This collection will iterate through site objects in the org and set templates defined in the template.\n\nFor site, please use the `site_name` field. for the remaining fields, use their respective IDs\n`networktemplate_id`\n`alarmttemplate_id`\n`rftemplate_id`\n\nThere is currently not support for the template name, you will need the ID for the templates.\n\nRequired Environmental Variables:\n`apitoken` This your Mist dashboard API token. It should have permissions to modify sites\n\n\nExamples CSV:\n```csv\nsite_name,rftemplate_id,networktemplate_id,alarmtemplate_id,secpolicy_id\nIDA,xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,,,\n\n```",
1795+
"event": [
1796+
{
1797+
"listen": "prerequest",
1798+
"script": {
1799+
"type": "text/javascript",
1800+
"exec": [
1801+
""
1802+
]
1803+
}
1804+
},
1805+
{
1806+
"listen": "test",
1807+
"script": {
1808+
"type": "text/javascript",
1809+
"exec": [
1810+
""
1811+
]
1812+
}
1813+
}
1814+
]
1815+
},
15051816
{
15061817
"name": "Set Site Variables",
15071818
"item": [
@@ -4406,6 +4717,10 @@
44064717
{
44074718
"key": "c_site_versions",
44084719
"value": ""
4720+
},
4721+
{
4722+
"key": "c_site_template_settings",
4723+
"value": ""
44094724
}
44104725
]
44114726
}

0 commit comments

Comments
 (0)