I asked the GPT bot, and it probably came close, but I’m a novice and would love some smart insight before I break something.
I have a list of 100 group names (can be comma delimited, or a file, or whatever)
I want to import them and have them all have the same settings, as listed here:
Allow users to join the group freely (Requires publicly visible group)
Allow users to leave the group freely
–no automatic members–
and
The following from the bot seems like a start, but I’m not really comfortable hacking my way through it:
GPT SAYS:
However, you can use the Discourse API to create groups programmatically. This will require some technical knowledge and familiarity with APIs.
Here’s a basic example of how you might do this in Python using the requests
library:
import requests
api_key = 'your_api_key'
api_username = 'your_api_username'
base_url = 'https://your_discourse_url.com'
headers = {
'Api-Key': api_key,
'Api-Username': api_username,
}
for i in range(1, 101):
data = {
'name': f'group_{i}',
'visible': True,
'automatic_membership_email_domains': 'example.com'
}
response = requests.post(f'{base_url}/admin/groups', headers=headers, data=data)
print(f'Created group {i}, response code: {response.status_code}')
Replace 'your_api_key'
, 'your_api_username'
, and 'https://your_discourse_url.com'
with your actual API key, API username, and Discourse URL.
THANKS.