[{"element_type":"text","content":"\n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n        \u003cp\u003eA user contacted support wondering how best to duplicate a group with a bunch of feeds inside.\u003c/p\u003e\n\u003cp\u003eThey required 20 duplicate copies / groups, with the group name having an increasing number.\u003c/p\u003e\n      \n\n\n\n\n\n\n\n\n\n","metadata":{}},{"element_type":"text","content":"\n  \n        \u003ch2\u003ePython Code Solution\u003c/h2\u003e\n\u003cp\u003eI went and created a simple python script to allow other users to benefit from this need/work.\u003cbr\u003e\u003cbr\u003eYou'll need to have installed the Adafruit IO Python library using\u0026nbsp;\u003ccode\u003epip install adafruit_io --upgrade\u003c/code\u003e\u003cbr\u003eThen run the code (assuming the file is saved as script.py in the current folder) with \u003ccode\u003epython ./script.py\u003c/code\u003e\u003c/p\u003e\n\u003cp\u003eNotice the values that need filling in, like IO username+key, group key, new group name template, count, etc.\u003cbr\u003e\u003cbr\u003eThe first argument to os.getenv is the key used to retrieve a value from Environment Variables, and the second argument is the default value if the key is not found in your environment variables.\u003c/p\u003e\n      \n","metadata":{}},{"element_type":"code","content":"# Simple example of recreating similar groups on Adafruit IO with the REST API client.\n# Author: Tyeth Gundry\n\n# Import Adafruit IO REST client.\nfrom adafruit_io import Client, Feed, Group\nimport json\nimport os\n\n# Set to your Adafruit IO key.\n# Remember, your key is a secret,\n# so make sure not to publish it when you publish this code!\nADAFRUIT_IO_KEY = os.getenv('ADAFRUIT_IO_KEY', 'YOUR_AIO_KEY')\n\n# Set to your Adafruit IO username.\n# (go to https://accounts.adafruit.com to find your username)\nADAFRUIT_IO_USERNAME = os.getenv('ADAFRUIT_IO_USERNAME', 'YOUR_AIO_USERNAME')\n\n# Set to the group key you want to copy\nADAFRUIT_IO_GROUP_KEY = os.getenv('ADAFRUIT_IO_GROUP_KEY', 'enviro')\n\n# new group name template {number} will be replaced with the group number\nADAFRUIT_IO_NEW_GROUP_NAME = os.getenv('ADAFRUIT_IO_NEW_GROUP_NAME', 'enviro {number}')\n\n# new group starting number and count of groups to create\nADAFRUIT_IO_NEW_GROUP_START = int(os.getenv('ADAFRUIT_IO_NEW_GROUP_START', 2))\nADAFRUIT_IO_NEW_GROUP_COUNT = int(os.getenv('ADAFRUIT_IO_NEW_GROUP_COUNT', 19))\n\n\n# Create an instance of the REST client.\naio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)\n\n# Fetch group to be copied\nmain_group = aio.groups(ADAFRUIT_IO_GROUP_KEY)\nif main_group is None:\n    print(f\"Group not found, try visiting https://io.adafruit.com/{ADAFRUIT_IO_USERNAME}/feeds and viewing the group info to find the key\")\n    exit()\n\nif main_group.feeds in [None, []]:\n    print(f\"Group {ADAFRUIT_IO_GROUP_KEY} has no feeds\")\n    exit()\n\nfor i in range(ADAFRUIT_IO_NEW_GROUP_START, ADAFRUIT_IO_NEW_GROUP_START + (ADAFRUIT_IO_NEW_GROUP_COUNT-1)):\n    new_group_name = ADAFRUIT_IO_NEW_GROUP_NAME.format(number=i)\n    print(f\"Creating group {new_group_name}\")\n    new_group = aio.create_group(Group(name=new_group_name))\n    new_group_key = new_group.key\n    print(f\"New group created: {new_group.name} (key: {new_group_key})\")\n\n    # Create feeds in the new group\n    for feed in main_group.feeds:\n        print(f\"Creating feed {feed.name} in group {new_group_key}\")\n        new_feed = Feed(name=feed.name)\n        response = aio.create_feed(new_feed, new_group_key)\n        print(f\"created new feed {new_feed.name} in group {new_group_key}\")","metadata":{"language":"python","linenums":false}},{"element_type":"text","content":"\n        \u003cp\u003eIt's worth noting that Adafruit provide various libraries to make accessing the IO platform easier. \u003cbr\u003eFind them on GitHub for python, arduino, circuitpython, and various unofficial libraries.\u003c/p\u003e\n\u003cp\u003eOn top of that there is an HTTP API which would probably be the easiest way (\u003ca href=\"https://io.adafruit.com/api/docs/#adafruit-io-http-api\" target=\"_blank\"\u003esee the docs here\u003c/a\u003e).\u0026nbsp;\u003c/p\u003e\n\u003cp\u003eThe last thing is that various API endpoints for Adafruit IO actually support creating feeds, for example create a group then post data for multiple non-existant feeds to: \u003cstrong\u003ehttps://io.adafruit.com/api/v2/\u003c/strong\u003e\u003ccode\u003e\u003cspan class=\"inlineVariable resolvedVariable\"\u003e{{io_user}}\u003c/span\u003e\u003c/code\u003e\u003cstrong\u003e/groups/\u003c/strong\u003e\u003ccode\u003e\u003cspan class=\"inlineVariable resolvedVariable\"\u003e{{group_name}}\u003c/span\u003e\u003c/code\u003e\u003cspan\u003e\u003cstrong\u003e/data\u003c/strong\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e with a payload similar to this:\u0026nbsp;\u003c/span\u003e\u003c/p\u003e\n      ","metadata":{}},{"element_type":"code","content":"{\n    \"feeds\": [\n        {\n            \"key\": \"{{feed_name}}\",\n            \"value\": 0\n        },\n        {\n            \"key\": \"voc\",\n            \"value\": 100,\n            \"created_at\": \"{{$isoTimestamp}}\"\n        }\n    ],\n    \"location\": {\n        \"lat\": 52,\n        \"lon\": -2\n    }\n}","metadata":{"language":"javascript","linenums":false}}]