clerk_sdk_rust_community/apis/
users_api.rs

1/*
2 * Clerk Backend API
3 *
4 * The Clerk REST Backend API, meant to be accessed by backend servers. Please see https://clerk.com/docs for more information.
5 *
6 * The version of the OpenAPI document: v1
7 * Contact: support@clerk.dev
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`ban_user`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum BanUserError {
22    Status402(crate::models::ClerkErrors),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`create_user`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum CreateUserError {
30    Status400(crate::models::ClerkErrors),
31    Status401(crate::models::ClerkErrors),
32    Status422(crate::models::ClerkErrors),
33    UnknownValue(serde_json::Value),
34}
35
36/// struct for typed errors of method [`delete_user`]
37#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum DeleteUserError {
40    Status400(crate::models::ClerkErrors),
41    Status401(crate::models::ClerkErrors),
42    Status404(crate::models::ClerkErrors),
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`disable_mfa`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum DisableMfaError {
50    Status404(crate::models::ClerkErrors),
51    Status500(crate::models::ClerkErrors),
52    UnknownValue(serde_json::Value),
53}
54
55/// struct for typed errors of method [`get_o_auth_access_token`]
56#[derive(Debug, Clone, Serialize, Deserialize)]
57#[serde(untagged)]
58pub enum GetOAuthAccessTokenError {
59    Status422(crate::models::ClerkErrors),
60    UnknownValue(serde_json::Value),
61}
62
63/// struct for typed errors of method [`get_user`]
64#[derive(Debug, Clone, Serialize, Deserialize)]
65#[serde(untagged)]
66pub enum GetUserError {
67    Status400(crate::models::ClerkErrors),
68    Status401(crate::models::ClerkErrors),
69    Status404(crate::models::ClerkErrors),
70    UnknownValue(serde_json::Value),
71}
72
73/// struct for typed errors of method [`get_user_list`]
74#[derive(Debug, Clone, Serialize, Deserialize)]
75#[serde(untagged)]
76pub enum GetUserListError {
77    Status400(crate::models::ClerkErrors),
78    Status401(crate::models::ClerkErrors),
79    Status422(crate::models::ClerkErrors),
80    UnknownValue(serde_json::Value),
81}
82
83/// struct for typed errors of method [`get_users_count`]
84#[derive(Debug, Clone, Serialize, Deserialize)]
85#[serde(untagged)]
86pub enum GetUsersCountError {
87    Status422(crate::models::ClerkErrors),
88    UnknownValue(serde_json::Value),
89}
90
91/// struct for typed errors of method [`unban_user`]
92#[derive(Debug, Clone, Serialize, Deserialize)]
93#[serde(untagged)]
94pub enum UnbanUserError {
95    Status402(crate::models::ClerkErrors),
96    UnknownValue(serde_json::Value),
97}
98
99/// struct for typed errors of method [`update_user`]
100#[derive(Debug, Clone, Serialize, Deserialize)]
101#[serde(untagged)]
102pub enum UpdateUserError {
103    Status400(crate::models::ClerkErrors),
104    Status401(crate::models::ClerkErrors),
105    Status404(crate::models::ClerkErrors),
106    Status422(crate::models::ClerkErrors),
107    UnknownValue(serde_json::Value),
108}
109
110/// struct for typed errors of method [`update_user_metadata`]
111#[derive(Debug, Clone, Serialize, Deserialize)]
112#[serde(untagged)]
113pub enum UpdateUserMetadataError {
114    Status400(crate::models::ClerkErrors),
115    Status401(crate::models::ClerkErrors),
116    Status404(crate::models::ClerkErrors),
117    Status422(crate::models::ClerkErrors),
118    UnknownValue(serde_json::Value),
119}
120
121/// struct for typed errors of method [`users_get_organization_memberships`]
122#[derive(Debug, Clone, Serialize, Deserialize)]
123#[serde(untagged)]
124pub enum UsersGetOrganizationMembershipsError {
125    Status403(crate::models::ClerkErrors),
126    UnknownValue(serde_json::Value),
127}
128
129/// struct for typed errors of method [`verify_password`]
130#[derive(Debug, Clone, Serialize, Deserialize)]
131#[serde(untagged)]
132pub enum VerifyPasswordError {
133    Status400(),
134    Status404(),
135    Status422(),
136    Status500(crate::models::ClerkErrors),
137    UnknownValue(serde_json::Value),
138}
139
140/// struct for typed errors of method [`verify_totp`]
141#[derive(Debug, Clone, Serialize, Deserialize)]
142#[serde(untagged)]
143pub enum VerifyTotpError {
144    Status400(),
145    Status404(),
146    Status422(),
147    Status500(crate::models::ClerkErrors),
148    UnknownValue(serde_json::Value),
149}
150
151
152/// Marks the given user as banned, which means that all their sessions are revoked and they are not allowed to sign in again.
153pub async fn ban_user(configuration: &configuration::Configuration, user_id: &str) -> Result<crate::models::User, Error<BanUserError>> {
154    let local_var_configuration = configuration;
155
156    let local_var_client = &local_var_configuration.client;
157
158    let local_var_uri_str = format!("{}/users/{user_id}/ban", local_var_configuration.base_path, user_id=crate::apis::urlencode(user_id));
159    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
160
161    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
162        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
163    }
164    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
165        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
166    };
167
168    let local_var_req = local_var_req_builder.build()?;
169    let local_var_resp = local_var_client.execute(local_var_req).await?;
170
171    let local_var_status = local_var_resp.status();
172    let local_var_content = local_var_resp.text().await?;
173
174    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
175        serde_json::from_str(&local_var_content).map_err(Error::from)
176    } else {
177        let local_var_entity: Option<BanUserError> = serde_json::from_str(&local_var_content).ok();
178        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
179        Err(Error::ResponseError(local_var_error))
180    }
181}
182
183/// Creates a new user. Your user management settings determine how you should setup your user model.  Any email address and phone number created using this method will be marked as verified.  Note: If you are performing a migration, check out our guide on [zero downtime migrations](https://clerk.com/docs/deployments/import-users).  A rate limit rule of 20 requests per 10 seconds is applied to this endpoint.
184pub async fn create_user(configuration: &configuration::Configuration, create_user_request: crate::models::CreateUserRequest) -> Result<crate::models::User, Error<CreateUserError>> {
185    let local_var_configuration = configuration;
186
187    let local_var_client = &local_var_configuration.client;
188
189    let local_var_uri_str = format!("{}/users", local_var_configuration.base_path);
190    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
191
192    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
193        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
194    }
195    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
196        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
197    };
198    local_var_req_builder = local_var_req_builder.json(&create_user_request);
199
200    let local_var_req = local_var_req_builder.build()?;
201    let local_var_resp = local_var_client.execute(local_var_req).await?;
202
203    let local_var_status = local_var_resp.status();
204    let local_var_content = local_var_resp.text().await?;
205
206    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
207        serde_json::from_str(&local_var_content).map_err(Error::from)
208    } else {
209        let local_var_entity: Option<CreateUserError> = serde_json::from_str(&local_var_content).ok();
210        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
211        Err(Error::ResponseError(local_var_error))
212    }
213}
214
215/// Delete the specified user
216pub async fn delete_user(configuration: &configuration::Configuration, user_id: &str) -> Result<crate::models::DeletedObject, Error<DeleteUserError>> {
217    let local_var_configuration = configuration;
218
219    let local_var_client = &local_var_configuration.client;
220
221    let local_var_uri_str = format!("{}/users/{user_id}", local_var_configuration.base_path, user_id=crate::apis::urlencode(user_id));
222    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
223
224    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
225        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
226    }
227    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
228        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
229    };
230
231    let local_var_req = local_var_req_builder.build()?;
232    let local_var_resp = local_var_client.execute(local_var_req).await?;
233
234    let local_var_status = local_var_resp.status();
235    let local_var_content = local_var_resp.text().await?;
236
237    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
238        serde_json::from_str(&local_var_content).map_err(Error::from)
239    } else {
240        let local_var_entity: Option<DeleteUserError> = serde_json::from_str(&local_var_content).ok();
241        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
242        Err(Error::ResponseError(local_var_error))
243    }
244}
245
246/// Disable all of a user's MFA methods (e.g. OTP sent via SMS, TOTP on their authenticator app) at once.
247pub async fn disable_mfa(configuration: &configuration::Configuration, user_id: &str) -> Result<crate::models::DisableMfa200Response, Error<DisableMfaError>> {
248    let local_var_configuration = configuration;
249
250    let local_var_client = &local_var_configuration.client;
251
252    let local_var_uri_str = format!("{}/users/{user_id}/mfa", local_var_configuration.base_path, user_id=crate::apis::urlencode(user_id));
253    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
254
255    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
256        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
257    }
258    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
259        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
260    };
261
262    let local_var_req = local_var_req_builder.build()?;
263    let local_var_resp = local_var_client.execute(local_var_req).await?;
264
265    let local_var_status = local_var_resp.status();
266    let local_var_content = local_var_resp.text().await?;
267
268    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
269        serde_json::from_str(&local_var_content).map_err(Error::from)
270    } else {
271        let local_var_entity: Option<DisableMfaError> = serde_json::from_str(&local_var_content).ok();
272        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
273        Err(Error::ResponseError(local_var_error))
274    }
275}
276
277/// Fetch the corresponding OAuth access token for a user that has previously authenticated with a particular OAuth provider. For OAuth 2.0, if the access token has expired and we have a corresponding refresh token, the access token will be refreshed transparently the new one will be returned.
278pub async fn get_o_auth_access_token(configuration: &configuration::Configuration, user_id: &str, provider: &str) -> Result<Vec<crate::models::GetOAuthAccessToken200ResponseInner>, Error<GetOAuthAccessTokenError>> {
279    let local_var_configuration = configuration;
280
281    let local_var_client = &local_var_configuration.client;
282
283    let local_var_uri_str = format!("{}/users/{user_id}/oauth_access_tokens/{provider}", local_var_configuration.base_path, user_id=crate::apis::urlencode(user_id), provider=crate::apis::urlencode(provider));
284    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
285
286    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
287        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
288    }
289    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
290        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
291    };
292
293    let local_var_req = local_var_req_builder.build()?;
294    let local_var_resp = local_var_client.execute(local_var_req).await?;
295
296    let local_var_status = local_var_resp.status();
297    let local_var_content = local_var_resp.text().await?;
298
299    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
300        serde_json::from_str(&local_var_content).map_err(Error::from)
301    } else {
302        let local_var_entity: Option<GetOAuthAccessTokenError> = serde_json::from_str(&local_var_content).ok();
303        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
304        Err(Error::ResponseError(local_var_error))
305    }
306}
307
308/// Retrieve the details of a user
309pub async fn get_user(configuration: &configuration::Configuration, user_id: &str) -> Result<crate::models::User, Error<GetUserError>> {
310    let local_var_configuration = configuration;
311
312    let local_var_client = &local_var_configuration.client;
313
314    let local_var_uri_str = format!("{}/users/{user_id}", local_var_configuration.base_path, user_id=crate::apis::urlencode(user_id));
315    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
316
317    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
318        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
319    }
320    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
321        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
322    };
323
324    let local_var_req = local_var_req_builder.build()?;
325    let local_var_resp = local_var_client.execute(local_var_req).await?;
326
327    let local_var_status = local_var_resp.status();
328    let local_var_content = local_var_resp.text().await?;
329
330    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
331        serde_json::from_str(&local_var_content).map_err(Error::from)
332    } else {
333        let local_var_entity: Option<GetUserError> = serde_json::from_str(&local_var_content).ok();
334        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
335        Err(Error::ResponseError(local_var_error))
336    }
337}
338
339/// Returns a list of all users. The users are returned sorted by creation date, with the newest users appearing first.
340pub async fn get_user_list(configuration: &configuration::Configuration, email_address: Option<Vec<String>>, phone_number: Option<Vec<String>>, external_id: Option<Vec<String>>, username: Option<Vec<String>>, web3_wallet: Option<Vec<String>>, user_id: Option<Vec<String>>, organization_id: Option<Vec<String>>, query: Option<&str>, limit: Option<f32>, offset: Option<f32>, order_by: Option<&str>) -> Result<Vec<crate::models::User>, Error<GetUserListError>> {
341    let local_var_configuration = configuration;
342
343    let local_var_client = &local_var_configuration.client;
344
345    let local_var_uri_str = format!("{}/users", local_var_configuration.base_path);
346    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
347
348    if let Some(ref local_var_str) = email_address {
349        local_var_req_builder = match "multi" {
350            "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("email_address".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
351            _ => local_var_req_builder.query(&[("email_address", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
352        };
353    }
354    if let Some(ref local_var_str) = phone_number {
355        local_var_req_builder = match "multi" {
356            "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("phone_number".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
357            _ => local_var_req_builder.query(&[("phone_number", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
358        };
359    }
360    if let Some(ref local_var_str) = external_id {
361        local_var_req_builder = match "multi" {
362            "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("external_id".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
363            _ => local_var_req_builder.query(&[("external_id", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
364        };
365    }
366    if let Some(ref local_var_str) = username {
367        local_var_req_builder = match "multi" {
368            "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("username".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
369            _ => local_var_req_builder.query(&[("username", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
370        };
371    }
372    if let Some(ref local_var_str) = web3_wallet {
373        local_var_req_builder = match "multi" {
374            "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("web3_wallet".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
375            _ => local_var_req_builder.query(&[("web3_wallet", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
376        };
377    }
378    if let Some(ref local_var_str) = user_id {
379        local_var_req_builder = match "multi" {
380            "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("user_id".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
381            _ => local_var_req_builder.query(&[("user_id", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
382        };
383    }
384    if let Some(ref local_var_str) = organization_id {
385        local_var_req_builder = match "multi" {
386            "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("organization_id".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
387            _ => local_var_req_builder.query(&[("organization_id", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
388        };
389    }
390    if let Some(ref local_var_str) = query {
391        local_var_req_builder = local_var_req_builder.query(&[("query", &local_var_str.to_string())]);
392    }
393    if let Some(ref local_var_str) = limit {
394        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
395    }
396    if let Some(ref local_var_str) = offset {
397        local_var_req_builder = local_var_req_builder.query(&[("offset", &local_var_str.to_string())]);
398    }
399    if let Some(ref local_var_str) = order_by {
400        local_var_req_builder = local_var_req_builder.query(&[("order_by", &local_var_str.to_string())]);
401    }
402    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
403        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
404    }
405    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
406        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
407    };
408
409    let local_var_req = local_var_req_builder.build()?;
410    let local_var_resp = local_var_client.execute(local_var_req).await?;
411
412    let local_var_status = local_var_resp.status();
413    let local_var_content = local_var_resp.text().await?;
414
415    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
416        serde_json::from_str(&local_var_content).map_err(Error::from)
417    } else {
418        let local_var_entity: Option<GetUserListError> = serde_json::from_str(&local_var_content).ok();
419        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
420        Err(Error::ResponseError(local_var_error))
421    }
422}
423
424/// Returns a total count of all users that match the given filtering criteria.
425pub async fn get_users_count(configuration: &configuration::Configuration, email_address: Option<Vec<String>>, phone_number: Option<Vec<String>>, external_id: Option<Vec<String>>, username: Option<Vec<String>>, web3_wallet: Option<Vec<String>>, user_id: Option<Vec<String>>, query: Option<&str>) -> Result<crate::models::TotalCount, Error<GetUsersCountError>> {
426    let local_var_configuration = configuration;
427
428    let local_var_client = &local_var_configuration.client;
429
430    let local_var_uri_str = format!("{}/users/count", local_var_configuration.base_path);
431    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
432
433    if let Some(ref local_var_str) = email_address {
434        local_var_req_builder = match "multi" {
435            "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("email_address".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
436            _ => local_var_req_builder.query(&[("email_address", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
437        };
438    }
439    if let Some(ref local_var_str) = phone_number {
440        local_var_req_builder = match "multi" {
441            "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("phone_number".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
442            _ => local_var_req_builder.query(&[("phone_number", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
443        };
444    }
445    if let Some(ref local_var_str) = external_id {
446        local_var_req_builder = match "multi" {
447            "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("external_id".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
448            _ => local_var_req_builder.query(&[("external_id", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
449        };
450    }
451    if let Some(ref local_var_str) = username {
452        local_var_req_builder = match "multi" {
453            "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("username".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
454            _ => local_var_req_builder.query(&[("username", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
455        };
456    }
457    if let Some(ref local_var_str) = web3_wallet {
458        local_var_req_builder = match "multi" {
459            "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("web3_wallet".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
460            _ => local_var_req_builder.query(&[("web3_wallet", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
461        };
462    }
463    if let Some(ref local_var_str) = user_id {
464        local_var_req_builder = match "multi" {
465            "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("user_id".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
466            _ => local_var_req_builder.query(&[("user_id", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
467        };
468    }
469    if let Some(ref local_var_str) = query {
470        local_var_req_builder = local_var_req_builder.query(&[("query", &local_var_str.to_string())]);
471    }
472    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
473        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
474    }
475    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
476        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
477    };
478
479    let local_var_req = local_var_req_builder.build()?;
480    let local_var_resp = local_var_client.execute(local_var_req).await?;
481
482    let local_var_status = local_var_resp.status();
483    let local_var_content = local_var_resp.text().await?;
484
485    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
486        serde_json::from_str(&local_var_content).map_err(Error::from)
487    } else {
488        let local_var_entity: Option<GetUsersCountError> = serde_json::from_str(&local_var_content).ok();
489        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
490        Err(Error::ResponseError(local_var_error))
491    }
492}
493
494/// Removes the ban mark from the given user.
495pub async fn unban_user(configuration: &configuration::Configuration, user_id: &str) -> Result<crate::models::User, Error<UnbanUserError>> {
496    let local_var_configuration = configuration;
497
498    let local_var_client = &local_var_configuration.client;
499
500    let local_var_uri_str = format!("{}/users/{user_id}/unban", local_var_configuration.base_path, user_id=crate::apis::urlencode(user_id));
501    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
502
503    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
504        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
505    }
506    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
507        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
508    };
509
510    let local_var_req = local_var_req_builder.build()?;
511    let local_var_resp = local_var_client.execute(local_var_req).await?;
512
513    let local_var_status = local_var_resp.status();
514    let local_var_content = local_var_resp.text().await?;
515
516    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
517        serde_json::from_str(&local_var_content).map_err(Error::from)
518    } else {
519        let local_var_entity: Option<UnbanUserError> = serde_json::from_str(&local_var_content).ok();
520        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
521        Err(Error::ResponseError(local_var_error))
522    }
523}
524
525/// Update a user's attributes.  You can set the user's primary contact identifiers (email address and phone numbers) by updating the `primary_email_address_id` and `primary_phone_number_id` attributes respectively. Both IDs should correspond to verified identifications that belong to the user.  You can remove a user's username by setting the username attribute to null or the blank string \"\". This is a destructive action; the identification will be deleted forever. Usernames can be removed only if they are optional in your instance settings and there's at least one other identifier which can be used for authentication.
526pub async fn update_user(configuration: &configuration::Configuration, user_id: &str, update_user_request: crate::models::UpdateUserRequest) -> Result<crate::models::User, Error<UpdateUserError>> {
527    let local_var_configuration = configuration;
528
529    let local_var_client = &local_var_configuration.client;
530
531    let local_var_uri_str = format!("{}/users/{user_id}", local_var_configuration.base_path, user_id=crate::apis::urlencode(user_id));
532    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
533
534    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
535        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
536    }
537    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
538        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
539    };
540    local_var_req_builder = local_var_req_builder.json(&update_user_request);
541
542    let local_var_req = local_var_req_builder.build()?;
543    let local_var_resp = local_var_client.execute(local_var_req).await?;
544
545    let local_var_status = local_var_resp.status();
546    let local_var_content = local_var_resp.text().await?;
547
548    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
549        serde_json::from_str(&local_var_content).map_err(Error::from)
550    } else {
551        let local_var_entity: Option<UpdateUserError> = serde_json::from_str(&local_var_content).ok();
552        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
553        Err(Error::ResponseError(local_var_error))
554    }
555}
556
557/// Update a user's metadata attributes by merging existing values with the provided parameters.  This endpoint behaves differently than the *Update a user* endpoint. Metadata values will not be replaced entirely. Instead, a deep merge will be performed. Deep means that any nested JSON objects will be merged as well.  You can remove metadata keys at any level by setting their value to `null`.
558pub async fn update_user_metadata(configuration: &configuration::Configuration, user_id: &str, update_user_metadata_request: Option<crate::models::UpdateUserMetadataRequest>) -> Result<crate::models::User, Error<UpdateUserMetadataError>> {
559    let local_var_configuration = configuration;
560
561    let local_var_client = &local_var_configuration.client;
562
563    let local_var_uri_str = format!("{}/users/{user_id}/metadata", local_var_configuration.base_path, user_id=crate::apis::urlencode(user_id));
564    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
565
566    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
567        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
568    }
569    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
570        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
571    };
572    local_var_req_builder = local_var_req_builder.json(&update_user_metadata_request);
573
574    let local_var_req = local_var_req_builder.build()?;
575    let local_var_resp = local_var_client.execute(local_var_req).await?;
576
577    let local_var_status = local_var_resp.status();
578    let local_var_content = local_var_resp.text().await?;
579
580    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
581        serde_json::from_str(&local_var_content).map_err(Error::from)
582    } else {
583        let local_var_entity: Option<UpdateUserMetadataError> = serde_json::from_str(&local_var_content).ok();
584        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
585        Err(Error::ResponseError(local_var_error))
586    }
587}
588
589/// Retrieve a paginated list of the user's organization memberships
590pub async fn users_get_organization_memberships(configuration: &configuration::Configuration, user_id: &str, limit: Option<f32>, offset: Option<f32>) -> Result<crate::models::OrganizationMemberships, Error<UsersGetOrganizationMembershipsError>> {
591    let local_var_configuration = configuration;
592
593    let local_var_client = &local_var_configuration.client;
594
595    let local_var_uri_str = format!("{}/users/{user_id}/organization_memberships", local_var_configuration.base_path, user_id=crate::apis::urlencode(user_id));
596    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
597
598    if let Some(ref local_var_str) = limit {
599        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
600    }
601    if let Some(ref local_var_str) = offset {
602        local_var_req_builder = local_var_req_builder.query(&[("offset", &local_var_str.to_string())]);
603    }
604    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
605        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
606    }
607    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
608        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
609    };
610
611    let local_var_req = local_var_req_builder.build()?;
612    let local_var_resp = local_var_client.execute(local_var_req).await?;
613
614    let local_var_status = local_var_resp.status();
615    let local_var_content = local_var_resp.text().await?;
616
617    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
618        serde_json::from_str(&local_var_content).map_err(Error::from)
619    } else {
620        let local_var_entity: Option<UsersGetOrganizationMembershipsError> = serde_json::from_str(&local_var_content).ok();
621        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
622        Err(Error::ResponseError(local_var_error))
623    }
624}
625
626/// Check that the user's password matches the supplied input. Useful for custom auth flows and re-verification.
627pub async fn verify_password(configuration: &configuration::Configuration, user_id: &str, verify_password_request: Option<crate::models::VerifyPasswordRequest>) -> Result<crate::models::VerifyPassword200Response, Error<VerifyPasswordError>> {
628    let local_var_configuration = configuration;
629
630    let local_var_client = &local_var_configuration.client;
631
632    let local_var_uri_str = format!("{}/users/{user_id}/verify_password", local_var_configuration.base_path, user_id=crate::apis::urlencode(user_id));
633    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
634
635    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
636        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
637    }
638    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
639        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
640    };
641    local_var_req_builder = local_var_req_builder.json(&verify_password_request);
642
643    let local_var_req = local_var_req_builder.build()?;
644    let local_var_resp = local_var_client.execute(local_var_req).await?;
645
646    let local_var_status = local_var_resp.status();
647    let local_var_content = local_var_resp.text().await?;
648
649    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
650        serde_json::from_str(&local_var_content).map_err(Error::from)
651    } else {
652        let local_var_entity: Option<VerifyPasswordError> = serde_json::from_str(&local_var_content).ok();
653        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
654        Err(Error::ResponseError(local_var_error))
655    }
656}
657
658/// Verify that the provided TOTP or backup code is valid for the user. Verifying a backup code will result it in being consumed (i.e. it will become invalid). Useful for custom auth flows and re-verification.
659pub async fn verify_totp(configuration: &configuration::Configuration, user_id: &str, verify_totp_request: Option<crate::models::VerifyTotpRequest>) -> Result<crate::models::VerifyTotp200Response, Error<VerifyTotpError>> {
660    let local_var_configuration = configuration;
661
662    let local_var_client = &local_var_configuration.client;
663
664    let local_var_uri_str = format!("{}/users/{user_id}/verify_totp", local_var_configuration.base_path, user_id=crate::apis::urlencode(user_id));
665    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
666
667    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
668        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
669    }
670    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
671        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
672    };
673    local_var_req_builder = local_var_req_builder.json(&verify_totp_request);
674
675    let local_var_req = local_var_req_builder.build()?;
676    let local_var_resp = local_var_client.execute(local_var_req).await?;
677
678    let local_var_status = local_var_resp.status();
679    let local_var_content = local_var_resp.text().await?;
680
681    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
682        serde_json::from_str(&local_var_content).map_err(Error::from)
683    } else {
684        let local_var_entity: Option<VerifyTotpError> = serde_json::from_str(&local_var_content).ok();
685        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
686        Err(Error::ResponseError(local_var_error))
687    }
688}
689