rdcore
rdcore copied to clipboard
Import accounts
how to import logins, passwords, email from a file? over 1000 accounts.
You can create a python3 script e.g., batch_import.py with below code and put the csv file in same folder and run in from Ubuntu terminal.
change some parameter based on your requirement e.g., radiusdesk_IP, csv file path and name (here it is users.csv) and API token from radiusdesk.
then run command: sudo python3 batch_import.py
import csv
import json
import requests
from datetime import datetime
# RADIUSdesk API endpoint URL
api_url = "http://<radiusdesk_IP>/cake4/rd_cake/permanent-users/add.json"
# CSV file path
csv_file_path = "users.csv"
# Read and process CSV data
with open(csv_file_path, "r") as csv_file:
csv_reader = csv.reader(csv_file)
next(csv_reader) # Skip header row
for row in csv_reader:
username, name, surname, profile, phone, email, address, password, to_date = row
today = datetime.today().strftime("%m/%d/%Y")
data = {
"user_id": 0,
"cloud_id": 23, # Can be found from RADIUSdesk
"realm": "<realm name goes here>",
"profile": profile,
"token": "<API token goes here>",
"language": "4_4",
"from_date": today,
"to_date": to_date,
"name": name,
"surname": surname,
"phone": phone,
"email": email,
"address": address,
"username": username,
"password": password,
"active":1,
}
headers = {
"Content-Type": "application/json"
}
# Send POST request
response = requests.post(api_url, data=json.dumps(data), headers=headers, verify=False)
if response.status_code == 200:
api_response = response.json()
if api_response.get("success"):
print(f"Record for {username} uploaded successfully.")
else:
print(f"Error uploading record for {username}: {api_response.get('message')}")
else:
print(f"Failed to upload record for {username}. Status code: {response.status_code}")