Skip to main content
This operation performs a soft delete, marking the wallet as deleted in the system while preserving its records for audit purposes.
Deleting a wallet is permanent and will immediately prevent the wallet from authenticating or using the API. Any active sessions for the wallet will be terminated.

Endpoint

curl -X DELETE "https://api.g2cplatform.com/v2/wallets/wal_7f8a9b2c-4d5e-6f7g-8h9i-0j1k2l3m4n5o" \
  -H "X-API-Key: YOUR_API_KEY"

Request

HTTP Method

DELETE

URL

https://api.g2cplatform.com/v2/wallets/{walletId}

Path Parameters

ParameterTypeRequiredDescription
walletIdstringUnique identifier of the wallet to delete

Headers

X-API-Key: YOUR_API_KEY

Response

Success Response (204 No Content)

A successful delete operation returns an HTTP 204 No Content status with no response body.

Error Responses

401 Unauthorized

{
  "error": "Invalid or missing API key",
  "code": "UNAUTHORIZED",
  "timestamp": "2025-08-04T12:30:00Z"
}

404 Not Found

{
  "error": "Wallet not found",
  "code": "RESOURCE_NOT_FOUND",
  "timestamp": "2025-08-04T12:30:00Z"
}

Implementation Examples

Delete a Single Wallet

async function deleteWallet(walletId) {
  try {
    const response = await fetch(
      `https://api.g2cplatform.com/v2/wallets/${walletId}`,
      {
        method: 'DELETE',
        headers: {
          'X-API-Key': process.env.G2C_API_KEY
        }
      }
    );

    if (response.status === 204) {
      console.log(`✅ Wallet ${walletId} deleted successfully`);
      return true;
    } else {
      const error = await response.json();
      throw new Error(`Failed to delete wallet: ${error.error}`);
    }
  } catch (error) {
    console.error(`❌ Delete error for wallet ${walletId}:`, error.message);
    throw error;
  }
}

Delete with Confirmation

async function deleteWalletWithConfirmation(walletId, confirmationCallback) {
  try {
    // First, get the wallet details to show in confirmation
    const getResponse = await fetch(
      `https://api.g2cplatform.com/v2/wallets/${walletId}`,
      {
        headers: {
          'X-API-Key': process.env.G2C_API_KEY,
          'Content-Type': 'application/json'
        }
      }
    );

    if (!getResponse.ok) {
      const error = await getResponse.json();
      throw new Error(`Failed to retrieve wallet: ${error.error}`);
    }

    const wallet = await getResponse.json();

    // Call the confirmation callback with wallet details
    const confirmed = await confirmationCallback(wallet);

    if (!confirmed) {
      console.log('Wallet deletion cancelled by user');
      return false;
    }

    // Proceed with deletion
    const deleteResponse = await fetch(
      `https://api.g2cplatform.com/v2/wallets/${walletId}`,
      {
        method: 'DELETE',
        headers: {
          'X-API-Key': process.env.G2C_API_KEY
        }
      }
    );

    if (deleteResponse.status === 204) {
      console.log(`✅ Wallet ${wallet.username} deleted successfully`);
      return true;
    } else {
      const error = await deleteResponse.json();
      throw new Error(`Failed to delete wallet: ${error.error}`);
    }
  } catch (error) {
    console.error('❌ Delete error:', error.message);
    throw error;
  }
}

// Example usage with a confirmation prompt
async function deleteWalletUI(walletId) {
  return deleteWalletWithConfirmation(walletId, (wallet) => {
    return new Promise((resolve) => {
      // Example of a browser confirmation
      const confirmed = window.confirm(
        `Are you sure you want to delete the wallet "${wallet.username}"?\n\n` +
        `This action cannot be undone and will immediately invalidate any active sessions.`
      );
      resolve(confirmed);
    });
  });
}

Bulk Delete Wallets

async function bulkDeleteWallets(walletIds) {
  const results = {
    successful: [],
    failed: []
  };

  for (const walletId of walletIds) {
    try {
      const success = await deleteWallet(walletId);
      if (success) {
        results.successful.push(walletId);
      }
    } catch (error) {
      results.failed.push({
        walletId,
        error: error.message
      });
    }
  }

  console.log(`✅ Successfully deleted ${results.successful.length} wallets`);
  if (results.failed.length > 0) {
    console.warn(`⚠️ Failed to delete ${results.failed.length} wallets`);
  }

  return results;
}

// Example: Delete inactive wallets
async function cleanupInactiveWallets(daysInactive = 180) {
  // First, list all inactive wallets
  const response = await fetch(
    'https://api.g2cplatform.com/v2/wallets?status=inactive',
    {
      headers: {
        'X-API-Key': process.env.G2C_API_KEY,
        'Content-Type': 'application/json'
      }
    }
  );

  const { data: wallets } = await response.json();

  // Calculate cutoff date
  const cutoffDate = new Date();
  cutoffDate.setDate(cutoffDate.getDate() - daysInactive);

  // Find wallets inactive for longer than the specified period
  const oldInactiveWalletIds = wallets
    .filter(wallet => {
      const lastUpdated = new Date(wallet.updatedAt);
      return lastUpdated < cutoffDate;
    })
    .map(wallet => wallet.id);

  console.log(`Found ${oldInactiveWalletIds.length} inactive wallets older than ${daysInactive} days`);

  // Delete the old inactive wallets
  if (oldInactiveWalletIds.length > 0) {
    return bulkDeleteWallets(oldInactiveWalletIds);
  }

  return { successful: [], failed: [] };
}

Usage Scenarios

Wallet Decommissioning Process

async function decommissionWallet(walletId, reason) {
  try {
    // 1. Get current wallet details
    const getResponse = await fetch(
      `https://api.g2cplatform.com/v2/wallets/${walletId}`,
      {
        headers: {
          'X-API-Key': process.env.G2C_API_KEY,
          'Content-Type': 'application/json'
        }
      }
    );

    if (!getResponse.ok) {
      const error = await getResponse.json();
      throw new Error(`Failed to retrieve wallet: ${error.error}`);
    }

    const wallet = await getResponse.json();

    // 2. Log decommissioning information
    console.log(`Starting decommissioning process for wallet: ${wallet.username}`);
    console.log(`Reason: ${reason}`);
    console.log(`Timestamp: ${new Date().toISOString()}`);

    // 3. Update status to inactive with decommission reason
    const updateResponse = await fetch(
      `https://api.g2cplatform.com/v2/wallets/${walletId}`,
      {
        method: 'PUT',
        headers: {
          'X-API-Key': process.env.G2C_API_KEY,
          'Content-Type': 'application/json'
        },
        body: JSON.stringify({
          status: 'inactive',
          metadata: {
            ...wallet.metadata,
            decommissionReason: reason,
            decommissionDate: new Date().toISOString(),
            decommissionedBy: 'Admin'
          }
        })
      }
    );

    if (!updateResponse.ok) {
      const error = await updateResponse.json();
      throw new Error(`Failed to update wallet status: ${error.error}`);
    }

    // 4. Delete the wallet
    const deleteResponse = await fetch(
      `https://api.g2cplatform.com/v2/wallets/${walletId}`,
      {
        method: 'DELETE',
        headers: {
          'X-API-Key': process.env.G2C_API_KEY
        }
      }
    );

    if (deleteResponse.status !== 204) {
      const error = await deleteResponse.json();
      throw new Error(`Failed to delete wallet: ${error.error}`);
    }

    console.log(`✅ Wallet ${wallet.username} successfully decommissioned`);
    return true;
  } catch (error) {
    console.error(`❌ Decommissioning failed:`, error.message);
    throw error;
  }
}

Best Practices

  • Always require confirmation for wallet deletion
  • Implement a grace period for critical wallets
  • Consider a staged approach (inactive → delete)
  • Keep a deletion log for audit purposes
  • Archive wallet data before deletion if needed
  • Consider implementing soft delete with recovery options
  • Establish data retention policies
  • Export wallet history for long-term storage
  • Restrict deletion permissions to authorized personnel
  • Require additional verification for high-security wallets
  • Implement rate limiting for deletion operations
  • Log all deletion attempts with IP and user information
  • Provide clear warnings about the consequences of deletion
  • Offer alternatives to deletion (e.g., suspension)
  • Send notifications to affected stakeholders
  • Include reason tracking for deletion analytics

Next Steps