Skip to main content
The users module provides server-side access to user profiles, social graph data (follows and connections), and username availability. All operations use your project API key and do not require a user access token.

fetchUserById

Fetches a user profile by their internal Replyke user ID.
const user = await replyke.users.fetchUserById({ userId: "usr_abc123" });
userId
string
required
The Replyke user ID.
ReturnsPromise<User>

fetchUserByForeignId

Fetches a user profile by your application’s own user identifier. Optionally creates the user if not found.
const user = await replyke.users.fetchUserByForeignId({
  foreignId: "external-user-42",
  createIfNotFound: true,
  name: "Bob Smith",
  username: "bob",
});
foreignId
string
required
Your application’s user identifier.
createIfNotFound
boolean
When true, creates the user with the provided profile fields if no match is found. Defaults to false.
name
string
Display name — used only when creating a new user.
username
string
Username — used only when creating a new user.
avatar
string
Avatar URL — used only when creating a new user.
bio
string
Bio text — used only when creating a new user.
metadata
object
Public metadata — used only when creating a new user.
secureMetadata
object
Secure metadata (not exposed to the client) — used only when creating a new user.
ReturnsPromise<User>

fetchUserByUsername

Fetches a user profile by their username.
const user = await replyke.users.fetchUserByUsername({ username: "alice" });
username
string
required
The user’s unique username.
ReturnsPromise<User>

updateUser

Updates a user’s profile fields.
const updatedUser = await replyke.users.updateUser({
  userId: "usr_abc123",
  name: "Alice Updated",
  bio: "New bio",
  avatar: "https://cdn.example.com/avatar.jpg",
  location: { latitude: 37.7749, longitude: -122.4194 },
});
userId
string
required
The Replyke user ID to update.
name
string
New display name.
username
string
New username. Must be available.
bio
string
New bio text.
avatar
string
New avatar URL.
metadata
object
Updated public metadata. Merged with existing metadata.
birthdate
string
ISO 8601 date string for the user’s birthdate.
location
object
Geographic location { latitude: number; longitude: number }.
ReturnsPromise<UserFull>

fetchUserSuggestions

Returns users whose name or username matches a partial query string. Useful for mention autocomplete on the server.
const users = await replyke.users.fetchUserSuggestions({
  query: "ali",
  limit: 10,
});
query
string
required
Partial name or username to search for.
limit
number
Maximum number of results to return.
ReturnsPromise<User[]>

checkUsernameAvailability

Checks whether a username is available for registration.
const { available } = await replyke.users.checkUsernameAvailability({
  username: "alice",
});
username
string
required
The username to check.
ReturnsPromise<{ available: boolean }>

fetchFollowersByUserId

Returns a paginated list of users following the specified user.
const { data, metadata } = await replyke.users.fetchFollowersByUserId({
  userId: "usr_abc123",
  page: 1,
  limit: 20,
});
userId
string
required
The Replyke user ID.
page
number
Page number (1-indexed). Defaults to 1.
limit
number
Results per page. Defaults to 20.
ReturnsPromise<PaginatedResponse<User>>

fetchFollowersCountByUserId

Returns the total number of followers for a user.
const { count } = await replyke.users.fetchFollowersCountByUserId({
  userId: "usr_abc123",
});
userId
string
required
The Replyke user ID.
ReturnsPromise<{ count: number }>

fetchFollowingByUserId

Returns a paginated list of users that the specified user is following.
const { data, metadata } = await replyke.users.fetchFollowingByUserId({
  userId: "usr_abc123",
  page: 1,
  limit: 20,
});
userId
string
required
The Replyke user ID.
page
number
Page number (1-indexed). Defaults to 1.
limit
number
Results per page. Defaults to 20.
ReturnsPromise<PaginatedResponse<User>>

fetchFollowingCountByUserId

Returns the number of users the specified user is following.
const { count } = await replyke.users.fetchFollowingCountByUserId({
  userId: "usr_abc123",
});
userId
string
required
The Replyke user ID.
ReturnsPromise<{ count: number }>

fetchConnectionsByUserId

Returns a paginated list of established mutual connections for a user.
const { data, metadata } = await replyke.users.fetchConnectionsByUserId({
  userId: "usr_abc123",
  page: 1,
  limit: 20,
});
userId
string
required
The Replyke user ID.
page
number
Page number (1-indexed). Defaults to 1.
limit
number
Results per page. Defaults to 20.
ReturnsPromise<PaginatedResponse<EstablishedConnection>>

fetchConnectionsCountByUserId

Returns the number of established connections for a user.
const { count } = await replyke.users.fetchConnectionsCountByUserId({
  userId: "usr_abc123",
});
userId
string
required
The Replyke user ID.
ReturnsPromise<{ count: number }>