Correct. This is an API call. The data is:
data = {
'api_key': settings.DISCOURSE_API_KEY,
'api_username': settings.DISCOURSE_API_USERNAME,
'name': 'foobar',
'email':email,
'password': password,
'username': 'barbaz',
'active': True,
'approved': True
}
I first tried just sending this API call:
first_res = requests.post('{base}/users.json'.format(base=settings.DISCOURSE_BASE_URL), data
When I did this, my users were not active (despite the active: True
in the data
above).
I then tried to activate them via the api:
data = {
'api_key': settings.DISCOURSE_API_KEY,
'api_username': settings.DISCOURSE_API_USERNAME,
}
requests.put('{base}/admin/users/{id}/activate'.format(
base=settings.DISCOURSE_BASE_URL,
id=json_response_content['user_id']
), data)
When I did this, the users were active, but the activation email was still being sent. I read here (Creating Active Users via the API gem) That I should try deactivating the user and then activating, so I tried that as well:
data = {
'api_key': settings.DISCOURSE_API_KEY,
'api_username': settings.DISCOURSE_API_USERNAME,
}
requests.put('{base}/admin/users/{id}/deactivate'.format(
base=settings.DISCOURSE_BASE_URL,
id=json_response_content['user_id']
), data)
requests.put('{base}/admin/users/{id}/activate'.format(
base=settings.DISCOURSE_BASE_URL,
id=json_response_content['user_id']
), data)
I could not see any difference in behavior between this code and the previous version (creating the user, and then activating).