Skip to content

DELETE /apiv2/subuserdel/

Delete a SUB-user and all related records. History records (orders, delegations) are reassigned to the parent user. Only the parent account or an administrator can delete a SUB-user.

Endpoint URL

DELETE https://netts.io/apiv2/subuserdel/{user_id}

Path Parameters

ParameterTypeRequiredDescription
user_idintegerYesID of the SUB-user to delete

Request Headers

HeaderRequiredDescription
X-API-KEYYesYour API key (must be the parent user's key)
X-Real-IPYesIP address from your whitelist

Authentication & Authorization

This endpoint requires both authentication and authorization:

  1. Authentication: Valid API key + IP from whitelist (same as other endpoints)
  2. Authorization: Only the parent user (who created the SUB-user) can delete their SUB-users

If a user attempts to delete a SUB-user that doesn't belong to them, the request is rejected with 403 Forbidden.

Example Requests

cURL

bash
curl -X DELETE https://netts.io/apiv2/subuserdel/1234 \
  -H "X-API-KEY: your_api_key" \
  -H "X-Real-IP: your_whitelisted_ip"

Python

python
import requests

user_id = 1234
url = f"https://netts.io/apiv2/subuserdel/{user_id}"
headers = {
    "X-API-KEY": "your_api_key",
    "X-Real-IP": "your_whitelisted_ip"
}

response = requests.delete(url, headers=headers)
data = response.json()

if response.status_code == 200:
    print(f"Deleted user: {data['user_id']} ({data['google_id']})")
    print(f"Parent user: {data['parent_user_id']}")
    print(f"Records reassigned: {data['total_reassigned']}")
    print(f"Records deleted: {data['total_deleted']}")
    print(f"Message: {data['message']}")

    print("\nReassigned tables:")
    for table, count in data['reassigned_records'].items():
        if count > 0:
            print(f"  {table}: {count} rows")

    print("\nDeleted tables:")
    for table, count in data['deleted_records'].items():
        if count > 0:
            print(f"  {table}: {count} rows")
else:
    print(f"Error ({response.status_code}): {data.get('detail', 'Unknown error')}")

Node.js

javascript
const axios = require('axios');

async function deleteSubUser(userId, apiKey, whitelistedIp) {
    const url = `https://netts.io/apiv2/subuserdel/${userId}`;

    const response = await axios.delete(url, {
        headers: {
            'X-API-KEY': apiKey,
            'X-Real-IP': whitelistedIp
        },
        timeout: 30000
    });

    const data = response.data;
    console.log(`Deleted: ${data.user_id} (${data.google_id})`);
    console.log(`Reassigned: ${data.total_reassigned} rows`);
    console.log(`Deleted: ${data.total_deleted} records`);
    return data;
}

// Usage
deleteSubUser(1234, 'your_api_key', 'your_whitelisted_ip')
    .then(result => console.log('Done:', result.message))
    .catch(err => console.error('Error:', err.response?.data || err.message));

PHP

php
<?php
$userId = 1234;
$url = "https://netts.io/apiv2/subuserdel/{$userId}";

$options = [
    'http' => [
        'header' => implode("\r\n", [
            "X-API-KEY: your_api_key",
            "X-Real-IP: your_whitelisted_ip"
        ]),
        'method' => 'DELETE',
        'timeout' => 30
    ]
];

$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
$data = json_decode($response, true);

echo "Deleted user: {$data['user_id']} ({$data['google_id']})\n";
echo "Reassigned: {$data['total_reassigned']} rows\n";
echo "Deleted: {$data['total_deleted']} records\n";
echo "Message: {$data['message']}\n";
?>

Response

Success Response (200 OK)

json
{
    "user_id": 1234,
    "google_id": "SUB123456789012345678",
    "parent_user_id": 42,
    "total_reassigned": 787,
    "total_deleted": 8,
    "message": "Mock user 1234 (SUB123456789012345678) deleted. History (787 rows) reassigned to parent 42."
}

Response Fields

FieldTypeDescription
user_idintegerDeleted SUB-user ID
google_idstringDeleted SUB-user's Google ID
parent_user_idintegerParent user ID (history reassigned to this user)
total_reassignedintegerTotal number of reassigned history records
total_deletedintegerTotal number of deleted records
messagestringSummary message

How Deletion Works

The deletion is performed atomically in a single transaction:

  1. History reassignment — all order and delegation history of the SUB-user is reassigned to the parent user. No transaction data is lost.
  2. Record cleanup — SUB-user-specific records (API key, settings, referral data, deposit address) are removed.
  3. Audit trail — a deletion record is saved for tracking purposes.

Safety Protections

  • Only SUB-users can be deleted — real user accounts are protected and cannot be deleted via this endpoint
  • Authorization required — only the parent user can delete their own SUB-users
  • Transaction safety — all operations run in a single database transaction (all-or-nothing)
  • History preserved — order and delegation history is reassigned to the parent, not lost

Error Responses

Bad Request (400)

json
{
    "detail": "User with id=9999 not found"
}
json
{
    "detail": "User 42 is NOT a mock user (google_id=1234567890). Only users with google_id starting with 'SUB' can be deleted."
}

Forbidden (403)

json
{
    "detail": "Not authorized: you can only delete your own SUB-users."
}

Authentication Error (401)

json
{
    "detail": "X-API-KEY header required"
}

Internal Server Error (500)

json
{
    "detail": "Failed to delete mock user: ..."
}

Error Code Reference

HTTP StatusDescription
200SUB-user deleted successfully
400User not found or not a SUB-user
401Missing API key header
403Not authorized (not parent user) / Invalid API key or IP
500Internal server error

Notes

  • Deletion is irreversible — ensure you want to remove the SUB-user before calling this endpoint
  • All SUB-user history (orders, delegations) is reassigned to the parent — no data is lost
  • The deletion record is permanently stored in the database audit table
  • Referral earnings records are not affected by deletion
  • If the SUB-user has a non-zero balance, it is not automatically transferred — withdraw before deleting
  • SUB-users can be created again via POST /apiv2/subusergen endpoint