Skip to main content
This endpoint provides all the wallet’s properties including metadata and login history.
This endpoint can only be accessed using the API key of the App that owns the wallet.

Endpoint

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

Request

HTTP Method

GET

URL

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

Path Parameters

ParameterTypeRequiredDescription
walletIdstringUnique identifier of the wallet to retrieve

Headers

X-API-Key: YOUR_API_KEY
Content-Type: application/json

Response

Success Response (200 OK)

{
  "id": "wal_7f8a9b2c-4d5e-6f7g-8h9i-0j1k2l3m4n5o",
  "username": "sensor01",
  "appId": "app_1a2b3c4d-5e6f-7g8h-9i0j-1k2l3m4n5o6p",
  "fullUsername": "sensor01@app_1a2b3c4d-5e6f-7g8h-9i0j-1k2l3m4n5o6p",
  "status": "active",
  "metadata": {
    "role": "device",
    "label": "Sensor at gate 3",
    "location": "Building A",
    "serialNumber": "SN12345678"
  },
  "createdAt": "2025-08-01T10:30:00Z",
  "updatedAt": "2025-08-03T15:45:22Z",
  "lastLoginAt": "2025-08-04T09:15:30Z",
  "stats": {
    "loginCount": 12,
    "apiCallCount": 346,
    "lastApiCallAt": "2025-08-04T10:12:45Z"
  }
}

Error Responses

401 Unauthorized

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

404 Not Found

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

Implementation Examples

Retrieve and Display Wallet Information

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

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

    const wallet = await response.json();
    return wallet;
  } catch (error) {
    console.error('Error fetching wallet details:', error.message);
    throw error;
  }
}

// Usage
async function displayWalletInfo(walletId) {
  try {
    const wallet = await getWalletDetails(walletId);

    console.log('======= Wallet Information =======');
    console.log(`ID: ${wallet.id}`);
    console.log(`Username: ${wallet.username}`);
    console.log(`Full Username: ${wallet.fullUsername}`);
    console.log(`Status: ${wallet.status}`);
    console.log(`Created: ${new Date(wallet.createdAt).toLocaleString()}`);

    if (wallet.lastLoginAt) {
      console.log(`Last Login: ${new Date(wallet.lastLoginAt).toLocaleString()}`);
    } else {
      console.log('Last Login: Never');
    }

    console.log('\nMetadata:');
    for (const [key, value] of Object.entries(wallet.metadata || {})) {
      console.log(`  ${key}: ${value}`);
    }

    if (wallet.stats) {
      console.log('\nActivity Statistics:');
      console.log(`  Login Count: ${wallet.stats.loginCount}`);
      console.log(`  API Call Count: ${wallet.stats.apiCallCount}`);
      console.log(`  Last API Call: ${new Date(wallet.stats.lastApiCallAt).toLocaleString()}`);
    }

    return wallet;
  } catch (error) {
    console.error(`❌ Could not display wallet: ${error.message}`);
  }
}

Check Wallet Status Before Operation

async function checkWalletBeforeOperation(walletId) {
  try {
    const wallet = await getWalletDetails(walletId);

    if (wallet.status !== 'active') {
      console.warn(`⚠️ Wallet ${wallet.username} is not active (status: ${wallet.status})`);
      return false;
    }

    // Check if wallet has been used recently (within 30 days)
    if (wallet.lastLoginAt) {
      const lastLoginDate = new Date(wallet.lastLoginAt);
      const thirtyDaysAgo = new Date();
      thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);

      if (lastLoginDate < thirtyDaysAgo) {
        console.warn(`⚠️ Wallet ${wallet.username} has not been used in over 30 days`);
        return false;
      }
    } else {
      console.warn(`⚠️ Wallet ${wallet.username} has never logged in`);
      return false;
    }

    console.log(`✅ Wallet ${wallet.username} is active and recently used`);
    return true;
  } catch (error) {
    console.error(`❌ Wallet check failed: ${error.message}`);
    return false;
  }
}

Retrieve Multiple Wallets

async function getMultipleWallets(walletIds) {
  const results = [];
  const errors = [];

  // Create requests for all wallets
  const requests = walletIds.map(id =>
    fetch(`https://api.g2cplatform.com/v2/wallets/${id}`, {
      headers: {
        'X-API-Key': process.env.G2C_API_KEY,
        'Content-Type': 'application/json'
      }
    }).then(async response => {
      if (response.ok) {
        const wallet = await response.json();
        results.push(wallet);
      } else {
        const error = await response.json();
        errors.push({ id, error: error.error });
      }
    }).catch(error => {
      errors.push({ id, error: error.message });
    })
  );

  // Wait for all requests to complete
  await Promise.all(requests);

  console.log(`✅ Retrieved ${results.length} wallets`);
  if (errors.length > 0) {
    console.warn(`⚠️ Failed to retrieve ${errors.length} wallets`);
  }

  return { results, errors };
}

Usage Scenarios

Wallet Management Dashboard

// Example code for a wallet management dashboard
async function renderWalletDashboard(walletId) {
  const wallet = await getWalletDetails(walletId);

  // Render basic information
  document.getElementById('walletUsername').textContent = wallet.username;
  document.getElementById('walletStatus').textContent = wallet.status;
  document.querySelector('.status-indicator').className = `status-indicator ${wallet.status}`;

  // Render activity statistics
  if (wallet.stats) {
    document.getElementById('loginCount').textContent = wallet.stats.loginCount;
    document.getElementById('apiCallCount').textContent = wallet.stats.apiCallCount;

    // Calculate days since last activity
    if (wallet.stats.lastApiCallAt) {
      const lastActivity = new Date(wallet.stats.lastApiCallAt);
      const today = new Date();
      const diffTime = Math.abs(today - lastActivity);
      const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24));

      document.getElementById('lastActivity').textContent =
        diffDays === 0 ? 'Today' :
        diffDays === 1 ? 'Yesterday' :
        `${diffDays} days ago`;
    } else {
      document.getElementById('lastActivity').textContent = 'Never';
    }
  }

  // Render metadata table
  const metadataTable = document.getElementById('metadataTable');
  metadataTable.innerHTML = ''; // Clear existing entries

  for (const [key, value] of Object.entries(wallet.metadata || {})) {
    const row = document.createElement('tr');

    const keyCell = document.createElement('td');
    keyCell.textContent = key;

    const valueCell = document.createElement('td');
    valueCell.textContent = value;

    row.appendChild(keyCell);
    row.appendChild(valueCell);
    metadataTable.appendChild(row);
  }

  // Set up action buttons based on current status
  const suspendButton = document.getElementById('suspendButton');
  const activateButton = document.getElementById('activateButton');
  const resetPasswordButton = document.getElementById('resetPasswordButton');

  if (wallet.status === 'active') {
    suspendButton.disabled = false;
    activateButton.disabled = true;
  } else {
    suspendButton.disabled = true;
    activateButton.disabled = false;
  }

  resetPasswordButton.disabled = false;
}

Best Practices

  • Implement proper error handling for missing wallets
  • Add friendly error messages for users
  • Provide fallback UI when wallet data cannot be retrieved
  • Log detailed errors for debugging
  • Cache wallet details to reduce API calls
  • Implement cache invalidation when wallets are updated
  • Use appropriate cache expiration times based on data volatility
  • Consider using stale-while-revalidate patterns for UI responsiveness
  • Limit access to wallet details to authorized personnel
  • Never expose sensitive wallet information in logs or UI
  • Implement proper audit logging for wallet access
  • Sanitize and validate wallet IDs before making API calls
  • Show wallet status prominently
  • Provide clear indicators for inactive or suspended wallets
  • Display last activity time to help identify unused wallets
  • Group and organize metadata for better readability

Next Steps