Hello,
I wrote a python script which creates 70 test users at once. The code is as follows:
import requests
def get_access_token(client_id, client_secret):
token_url = "http://localhost:8080/auth/oauth2/token"
payload = {
"grant_type": "client_credentials",
"scope": "profile api"
}
response = requests.post(token_url, data=payload, auth=(client_id, client_secret))
if response.status_code == 200:
token_data = response.json()
access_token = token_data.get("access_token")
return access_token
else:
print("Error obtaining access token. Status code:", response.status_code)
print(response.text)
return None
def main():
client_id = "349706746018660355"
client_secret = "D2rvKUO9NDGKMtrnA5NsDF8yj4EX9jc3K9k0c0p0XqQngV7A76M2KaTSjhbKmqya"
access_token = get_access_token(client_id, client_secret)
if access_token:
url = "http://localhost:8080/api/system/users/"
jwt = access_token
for i in range(1, 70 + 1):
headers = {
"Authorization": f"Bearer {jwt}",
"Accept": "application/json",
"Content-Type": "application/json"
}
user_data = {
"email": f"Test.User{i}@example.com",
"name": f"Test User{i}",
"handle": f"TU{i}",
"kind": f"string{i}",
"labels": f"string{i}"
}
response = requests.post(url, json=user_data, headers=headers)
if response.status_code == 200:
print("Users successfully created.")
else:
print("Error in the request. Status code:", response.status_code)
main()
and so far the code works, I receive the status code 200 which is right, according to this doc and I’m also using the same keys as mentioned in that doc (however I’m also wondering how one of those created users is supposed to login without a password being set?), BUT even tho I get status code 200, there are no new users anywhere to be seen/found in the users section of the Admin Area, why is that? Did I perhaps miss something?
Any and every help is much appreciated.