Your account
client.account is everything about the logged-in user. It exists after client.login().
ts
/**
* @imvu/client — a read-only tour of the logged-in account: wallet, friends,
* wishlist and inventory. Shows the two ways to read a collection: one bounded
* page, or `for await` over every item.
*
* node --env-file=.env examples/account-overview.ts
*/
import { Client } from '@imvu/client';
const username = process.env.IMVU_USERNAME;
const password = process.env.IMVU_PASSWORD ?? '';
if (!username) {
console.error('Set IMVU_USERNAME (and IMVU_PASSWORD) — see examples/README.md');
process.exit(1);
}
const client = new Client();
await client.login(username, password);
const { account } = client;
console.log(`${account.username} (id ${account.id})`);
// Wallet: a plain data object, not a resource.
const wallet = await account.wallet.status();
console.log(`Credits: ${wallet.credits} (+${wallet.promo_credits} promo)`);
// Counting asks for zero items, so it's cheap even for huge collections.
console.log(`Friends: ${await account.friends.count()}`);
// One bounded page of the wishlist.
const wishlist = account.wishlist.list();
const firstPage = await wishlist.page({ offset: 0, limit: 5 });
console.log(`Wishlist (${wishlist.totalCount} items), first ${firstPage.length}:`);
for (const product of firstPage) {
console.log(` ${product.name} by ${product.creatorName}: ${product.price} credits`);
}
// `for await` fetches pages as it goes; break early to stop fetching.
console.log('Inventory, first 10:');
let shown = 0;
for await (const product of account.inventory()) {
console.log(` [${product.id}] ${product.name}`);
if (++shown === 10) break;
}Who am I?
ts
client.account.id;
client.account.username;
client.account.user; // your full User, with the same fields as any other user
const avatar = await client.account.avatar();
for await (const product of avatar.products()) {
console.log('wearing', product.name);
}Wallet
ts
const wallet = await client.account.wallet.status();
wallet.credits;
wallet.promo_credits;
wallet.vcoin_total;The wallet is returned as IMVU sends it (snake_case), not as a resource.
Friends
ts
const friends = client.account.friends.list();
console.log(`${await friends.count()} friends`);
for await (const friend of friends) console.log(friend.username);
await client.account.friends.add('Alice'); // friend request
await client.account.friends.remove(someUser);Wishlist
ts
const wishlist = client.account.wishlist.list();
const top = await wishlist.page({ limit: 10 });
await client.account.wishlist.add(51522827); // a product id or Product
await client.account.wishlist.remove(51522827);Anyone's wishlist is available from their User: user.wishlist().
Inventory, blocklist and following
ts
for await (const product of client.account.inventory()) {
// everything you own
}
for await (const blocked of client.account.blocklist()) {
console.log('blocked:', blocked.username);
}
for await (const profile of client.account.followers.following()) {
console.log('following:', profile.username);
}All three are ordinary collections: use count() for a total, or page() for a slice.
Daily spin
ts
if (await client.account.roulette.available()) {
const result = await client.account.roulette.spin();
console.log('won:', result.reward?.text);
} else {
const { next_available_datetime } = await client.account.roulette.status();
console.log('next spin at', next_available_datetime);
}