use crate::api::*;
use crate::{ApiError, ClientConfig, HttpClient, QueryBuilder, RequestOptions};
use reqwest::Method;
pub struct TeamMembersClient {
pub http_client: HttpClient,
}
impl TeamMembersClient {
pub fn new(config: ClientConfig) -> Result<Self, ApiError> {
Ok(Self {
http_client: HttpClient::new(config.clone())?,
})
}
/// Lists an account's team members, including pending invites (`status: "pending"`, `ausri_` ids; `user` is `null` for invites sent to an email with no Whop account yet). For accepted members, `email` requires the `company:authorized_user:email:read` scope and is `null` otherwise. Listing `role=workforce` is also allowed with the `bounty:create` scope.
///
/// # Arguments
///
/// * `account_id` - Account ID, prefixed `biz_`.
/// * `status` - Only return members with this status: `joined` (accepted members) or `pending` (pending invites). Both are returned by default.
/// * `user_id` - Only return the membership for this user ID, prefixed `user_`.
/// * `role` - Only return members with this role. `custom` matches members on a dashboard-managed custom role.
/// * `created_before` - Only return members added before this ISO 8601 timestamp.
/// * `created_after` - Only return members added after this ISO 8601 timestamp.
/// * `order` - Field used to sort members.
/// * `direction` - Sort direction. Defaults to `desc`.
/// * `first` - Number of members to return. Defaults to 20; maximum 100.
/// * `after` - Cursor for the next page of members.
/// * `last` - Number of members to return from the end of the window.
/// * `before` - Cursor to paginate backwards from.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use whop_sdk::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// token: Some("<token>".to_string()),
/// ..Default::default()
/// };
/// let client = Whop::new(config).expect("Failed to build client");
/// client
/// .team_members
/// .list(
/// &TeamMembersListQueryRequest {
/// account_id: "account_id".to_string(),
/// status: None,
/// user_id: None,
/// role: None,
/// created_before: None,
/// created_after: None,
/// order: None,
/// direction: None,
/// first: None,
/// after: None,
/// last: None,
/// before: None,
/// },
/// None,
/// )
/// .await;
/// }
/// ```
pub async fn list(
&self,
request: &TeamMembersListQueryRequest,
options: Option<RequestOptions>,
) -> Result<ListTeamMembersResponse, ApiError> {
self.http_client
.execute_request(
Method::GET,
"team_members",
None,
QueryBuilder::new()
.string("account_id", request.account_id.clone())
.serialize("status", request.status.clone())
.string("user_id", request.user_id.clone())
.serialize("role", request.role.clone())
.string("created_before", request.created_before.clone())
.string("created_after", request.created_after.clone())
.serialize("order", request.order.clone())
.serialize("direction", request.direction.clone())
.int("first", request.first.clone())
.string("after", request.after.clone())
.int("last", request.last.clone())
.string("before", request.before.clone())
.build(),
options,
)
.await
}
/// Adds a member to an account's team with a system role. Identify them by exactly one of `user_id` or `email`. If the person has not yet accepted — or the email does not belong to a Whop account yet — an invitation is sent instead and the response is `202` with `{ "object": "team_member_invite", "invitation_sent": true }`. If they already have a pending invite, the request fails with a `400`. Custom roles cannot be granted via the API. Granting the `workforce` role is also allowed with the `bounty:create` scope.
///
/// # Arguments
///
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use whop_sdk::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// token: Some("<token>".to_string()),
/// ..Default::default()
/// };
/// let client = Whop::new(config).expect("Failed to build client");
/// client
/// .team_members
/// .create(
/// &CreateTeamMembersRequest {
/// account_id: "biz_xxxxxxxxxxxxxx".to_string(),
/// role: CreateTeamMembersRequestRole::Owner,
/// email: None,
/// user_id: None,
/// },
/// None,
/// )
/// .await;
/// }
/// ```
pub async fn create(
&self,
request: &CreateTeamMembersRequest,
options: Option<RequestOptions>,
) -> Result<TeamMember, ApiError> {
self.http_client
.execute_request(
Method::POST,
"team_members",
Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
None,
options,
)
.await
}
/// Retrieves a team member by ID. `email` requires the `company:authorized_user:email:read` scope and is `null` otherwise.
///
/// # Arguments
///
/// * `id` - Team member ID — `ausr_` for accepted members, `ausri_` for pending invites.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use whop_sdk::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// token: Some("<token>".to_string()),
/// ..Default::default()
/// };
/// let client = Whop::new(config).expect("Failed to build client");
/// client.team_members.retrieve(&"id".to_string(), None).await;
/// }
/// ```
pub async fn retrieve(
&self,
id: &str,
options: Option<RequestOptions>,
) -> Result<TeamMember, ApiError> {
self.http_client
.execute_request(
Method::GET,
&format!("team_members/{}", id),
None,
None,
options,
)
.await
}
/// Removes a team member from the account, or revokes a pending invite when given an `ausri_` ID. A user session may delete its own membership to leave the team without the delete scope. Removing a member on the `workforce` role is also allowed with the `bounty:create` scope. The account owner cannot be removed.
///
/// # Arguments
///
/// * `id` - Team member ID — `ausr_` for accepted members, `ausri_` for pending invites.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use whop_sdk::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// token: Some("<token>".to_string()),
/// ..Default::default()
/// };
/// let client = Whop::new(config).expect("Failed to build client");
/// client.team_members.delete(&"id".to_string(), None).await;
/// }
/// ```
pub async fn delete(
&self,
id: &str,
options: Option<RequestOptions>,
) -> Result<DeleteTeamMembersResponse, ApiError> {
self.http_client
.execute_request(
Method::DELETE,
&format!("team_members/{}", id),
None,
None,
options,
)
.await
}
/// Changes a team member's system role. Requires a user session — account API keys cannot change member roles. The account owner's role cannot be changed, and you cannot change your own role.
///
/// # Arguments
///
/// * `id` - Team member ID — `ausr_` for accepted members, `ausri_` for pending invites.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use whop_sdk::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// token: Some("<token>".to_string()),
/// ..Default::default()
/// };
/// let client = Whop::new(config).expect("Failed to build client");
/// client
/// .team_members
/// .update(
/// &"id".to_string(),
/// &UpdateTeamMembersRequest {
/// role: UpdateTeamMembersRequestRole::Owner,
/// },
/// None,
/// )
/// .await;
/// }
/// ```
pub async fn update(
&self,
id: &str,
request: &UpdateTeamMembersRequest,
options: Option<RequestOptions>,
) -> Result<TeamMember, ApiError> {
self.http_client
.execute_request(
Method::PATCH,
&format!("team_members/{}", id),
Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
None,
options,
)
.await
}
}