Skip to main content

Create multiple accounts at once

This guide explains how to automatically create multiple accounts using the Automation API while complying with API rate limits. It uses the /accounts endpoint.

Prerequisites

Before you use the Automation API, ensure that you have an access token.

To obtain a token, see the Authentication guide. Include the token in your request's Authorization header:

Authorization: Bearer YOUR_ACCESS_TOKEN

Handle rate limits

The Automation API enforces two rate-limiting windows to control request traffic:

Time WindowMaximum Requests
10 seconds50 requests
1 hour1,000 requests

If you send requests too quickly when you create many accounts, the API returns an HTTP 429 (Too Many Requests) response.

To avoid these limits, process your requests in controlled batches:

  • Send a maximum of 50 requests every 10 seconds.
  • Send a maximum of 1,000 requests per hour.

For example, to create 230 accounts, divide your requests as follows:

BatchRequestsWait Time
150Wait 10 seconds
250Wait 10 seconds
350Wait 10 seconds
450Wait 10 seconds
530Complete

Format the input data

Define your accounts in a JSON file. Each object in the array represents the request body for a single account.

[
{
"firstName": "Elton",
"lastName": "John",
"email": "elton@john.com",
"preferredLocale": "en",
"password": "pwd",
"passwordConfirm": "pwd",
"status": "ACTIVATED",
"roles": [
{
"name": "ROLE_CUSTOMER_ADMIN",
"sites": [],
"customers": [99999],
"privileges": []
}
],
"isProductRecoAllowed": true,
"solutions": ["WEB_EXPERIMENTATION", "FEATURE_EXPERIMENTATION"]
},
{
"firstName": "Poussiere",
"lastName": "Etoile",
"email": "poussiere@etoile.com",
"password": "pwd",
"passwordConfirm": "pwd",
"preferredLocale": "en",
"status": "ACTIVATED",
"roles": [
{
"name": "ROLE_CUSTOMER_ADMIN",
"sites": [],
"customers": [99999],
"privileges": []
}
],
"isProductRecoAllowed": false,
"solutions": ["WEB_EXPERIMENTATION", "FEATURE_EXPERIMENTATION"]
}
]

Create accounts using Python

The following Python script reads the accounts from your JSON file, sends the requests sequentially, and manages the rate limits automatically:

import json
import time
import requests

API_URL = "https://api.kameleoon.com/accounts"
ACCESS_TOKEN = "YOUR_ACCESS_TOKEN"

INPUT_FILE = "accounts.json"

MAX_PER_10_SECONDS = 50
MAX_PER_HOUR = 1000

TEN_SECONDS = 10
ONE_HOUR = 3600

MAX_RETRIES = 3

def load_accounts(file_path):
with open(file_path, "r") as f:
return json.load(f)


def create_account(session, payload):
headers = {
"Authorization": f"Bearer {ACCESS_TOKEN}",
"Content-Type": "application/json",
}

for attempt in range(MAX_RETRIES):
response = session.post(API_URL, json=payload, headers=headers)

if response.status_code == 429:
print("Rate limit reached. Waiting 10 seconds...")
time.sleep(10)
continue

if response.status_code in (200, 201):
return True, response.json()

print(f"Error {response.status_code}: {response.text}")
return False, response.text

return False, "Max retries exceeded"


def process_accounts(accounts):

session = requests.Session()

start_hour = time.time()
hour_count = 0

for i in range(0, len(accounts), MAX_PER_10_SECONDS):

batch = accounts[i:i + MAX_PER_10_SECONDS]

if hour_count + len(batch) > MAX_PER_HOUR:

elapsed = time.time() - start_hour
sleep_time = max(0, ONE_HOUR - elapsed)

print(f"Hourly limit reached. Sleeping {sleep_time:.2f} seconds")
time.sleep(sleep_time)

start_hour = time.time()
hour_count = 0

batch_start = time.time()

for account in batch:

success, result = create_account(session, account)

if success:
print("Account created:", result)
else:
print("Request failed:", result)

hour_count += 1

elapsed = time.time() - batch_start

if elapsed < TEN_SECONDS:
sleep_time = TEN_SECONDS - elapsed
print(f"Waiting {sleep_time:.2f} seconds before next batch")
time.sleep(sleep_time)


def main():

accounts = load_accounts(INPUT_FILE)

print(f"Loaded {len(accounts)} accounts")

process_accounts(accounts)


if __name__ == "__main__":
main()

The provided script safely creates large numbers of accounts while complying with Automation API rate limits. It performs the following actions:

  • Reads accounts from a JSON file.
  • Sends requests sequentially.
  • Processes accounts in batches of 50.
  • Waits between batches to enforce the 10-second limit.
  • Pauses if the process reaches the hourly limit of 1,000 requests.

This approach prevents rate-limit errors and ensures reliable account creation during large migrations or bulk onboarding operations.