Skip to main content

ory_kratos_client/apis/
identity_api.rs

1/*
2 * Ory Identities API
3 *
4 * This is the API specification for Ory Identities with features such as registration, login, recovery, account verification, profile settings, password reset, identity management, session management, email and sms delivery, and more. 
5 *
6 * The version of the OpenAPI document: v26.2.0
7 * Contact: office@ory.sh
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`batch_patch_identities`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum BatchPatchIdentitiesError {
22    Status400(models::ErrorGeneric),
23    Status409(models::ErrorGeneric),
24    DefaultResponse(models::ErrorGeneric),
25    UnknownValue(serde_json::Value),
26}
27
28/// struct for typed errors of method [`create_identity`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum CreateIdentityError {
32    Status400(models::ErrorGeneric),
33    Status409(models::ErrorGeneric),
34    DefaultResponse(models::ErrorGeneric),
35    UnknownValue(serde_json::Value),
36}
37
38/// struct for typed errors of method [`create_recovery_code_for_identity`]
39#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum CreateRecoveryCodeForIdentityError {
42    Status400(models::ErrorGeneric),
43    Status404(models::ErrorGeneric),
44    DefaultResponse(models::ErrorGeneric),
45    UnknownValue(serde_json::Value),
46}
47
48/// struct for typed errors of method [`create_recovery_link_for_identity`]
49#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(untagged)]
51pub enum CreateRecoveryLinkForIdentityError {
52    Status400(models::ErrorGeneric),
53    Status404(models::ErrorGeneric),
54    DefaultResponse(models::ErrorGeneric),
55    UnknownValue(serde_json::Value),
56}
57
58/// struct for typed errors of method [`delete_identity`]
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum DeleteIdentityError {
62    Status404(models::ErrorGeneric),
63    DefaultResponse(models::ErrorGeneric),
64    UnknownValue(serde_json::Value),
65}
66
67/// struct for typed errors of method [`delete_identity_credentials`]
68#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum DeleteIdentityCredentialsError {
71    Status404(models::ErrorGeneric),
72    DefaultResponse(models::ErrorGeneric),
73    UnknownValue(serde_json::Value),
74}
75
76/// struct for typed errors of method [`delete_identity_sessions`]
77#[derive(Debug, Clone, Serialize, Deserialize)]
78#[serde(untagged)]
79pub enum DeleteIdentitySessionsError {
80    Status400(models::ErrorGeneric),
81    Status401(models::ErrorGeneric),
82    Status404(models::ErrorGeneric),
83    DefaultResponse(models::ErrorGeneric),
84    UnknownValue(serde_json::Value),
85}
86
87/// struct for typed errors of method [`disable_session`]
88#[derive(Debug, Clone, Serialize, Deserialize)]
89#[serde(untagged)]
90pub enum DisableSessionError {
91    Status400(models::ErrorGeneric),
92    Status401(models::ErrorGeneric),
93    DefaultResponse(models::ErrorGeneric),
94    UnknownValue(serde_json::Value),
95}
96
97/// struct for typed errors of method [`extend_session`]
98#[derive(Debug, Clone, Serialize, Deserialize)]
99#[serde(untagged)]
100pub enum ExtendSessionError {
101    Status400(models::ErrorGeneric),
102    Status404(models::ErrorGeneric),
103    DefaultResponse(models::ErrorGeneric),
104    UnknownValue(serde_json::Value),
105}
106
107/// struct for typed errors of method [`get_identity`]
108#[derive(Debug, Clone, Serialize, Deserialize)]
109#[serde(untagged)]
110pub enum GetIdentityError {
111    Status404(models::ErrorGeneric),
112    DefaultResponse(models::ErrorGeneric),
113    UnknownValue(serde_json::Value),
114}
115
116/// struct for typed errors of method [`get_identity_by_external_id`]
117#[derive(Debug, Clone, Serialize, Deserialize)]
118#[serde(untagged)]
119pub enum GetIdentityByExternalIdError {
120    Status404(models::ErrorGeneric),
121    DefaultResponse(models::ErrorGeneric),
122    UnknownValue(serde_json::Value),
123}
124
125/// struct for typed errors of method [`get_identity_schema`]
126#[derive(Debug, Clone, Serialize, Deserialize)]
127#[serde(untagged)]
128pub enum GetIdentitySchemaError {
129    Status404(models::ErrorGeneric),
130    DefaultResponse(models::ErrorGeneric),
131    UnknownValue(serde_json::Value),
132}
133
134/// struct for typed errors of method [`get_session`]
135#[derive(Debug, Clone, Serialize, Deserialize)]
136#[serde(untagged)]
137pub enum GetSessionError {
138    Status400(models::ErrorGeneric),
139    DefaultResponse(models::ErrorGeneric),
140    UnknownValue(serde_json::Value),
141}
142
143/// struct for typed errors of method [`list_identities`]
144#[derive(Debug, Clone, Serialize, Deserialize)]
145#[serde(untagged)]
146pub enum ListIdentitiesError {
147    DefaultResponse(models::ErrorGeneric),
148    UnknownValue(serde_json::Value),
149}
150
151/// struct for typed errors of method [`list_identity_schemas`]
152#[derive(Debug, Clone, Serialize, Deserialize)]
153#[serde(untagged)]
154pub enum ListIdentitySchemasError {
155    DefaultResponse(models::ErrorGeneric),
156    UnknownValue(serde_json::Value),
157}
158
159/// struct for typed errors of method [`list_identity_sessions`]
160#[derive(Debug, Clone, Serialize, Deserialize)]
161#[serde(untagged)]
162pub enum ListIdentitySessionsError {
163    Status400(models::ErrorGeneric),
164    Status404(models::ErrorGeneric),
165    DefaultResponse(models::ErrorGeneric),
166    UnknownValue(serde_json::Value),
167}
168
169/// struct for typed errors of method [`list_sessions`]
170#[derive(Debug, Clone, Serialize, Deserialize)]
171#[serde(untagged)]
172pub enum ListSessionsError {
173    Status400(models::ErrorGeneric),
174    DefaultResponse(models::ErrorGeneric),
175    UnknownValue(serde_json::Value),
176}
177
178/// struct for typed errors of method [`patch_identity`]
179#[derive(Debug, Clone, Serialize, Deserialize)]
180#[serde(untagged)]
181pub enum PatchIdentityError {
182    Status400(models::ErrorGeneric),
183    Status404(models::ErrorGeneric),
184    Status409(models::ErrorGeneric),
185    DefaultResponse(models::ErrorGeneric),
186    UnknownValue(serde_json::Value),
187}
188
189/// struct for typed errors of method [`update_identity`]
190#[derive(Debug, Clone, Serialize, Deserialize)]
191#[serde(untagged)]
192pub enum UpdateIdentityError {
193    Status400(models::ErrorGeneric),
194    Status404(models::ErrorGeneric),
195    Status409(models::ErrorGeneric),
196    DefaultResponse(models::ErrorGeneric),
197    UnknownValue(serde_json::Value),
198}
199
200
201/// Creates multiple [identities](https://www.ory.com/docs/kratos/concepts/identity-user-model).  You can also use this endpoint to [import credentials](https://www.ory.com/docs/kratos/manage-identities/import-user-accounts-identities), including passwords, social sign-in settings, and multi-factor authentication methods.  If the patch includes hashed passwords you can import up to 1,000 identities per request.  If the patch includes at least one plaintext password you can import up to 200 identities per request.  Avoid importing large batches with plaintext passwords. They can cause timeouts as the passwords need to be hashed before they are stored.  If at least one identity is imported successfully, the response status is 200 OK. If all imports fail, the response is one of the following 4xx errors: 400 Bad Request: The request payload is invalid or improperly formatted. 409 Conflict: Duplicate identities or conflicting data were detected.  If you get a 504 Gateway Timeout: Reduce the batch size Avoid duplicate identities Pre-hash passwords with BCrypt  If the issue persists, contact support.
202pub async fn batch_patch_identities(configuration: &configuration::Configuration, patch_identities_body: Option<models::PatchIdentitiesBody>) -> Result<models::BatchPatchIdentitiesResponse, Error<BatchPatchIdentitiesError>> {
203    // add a prefix to parameters to efficiently prevent name collisions
204    let p_body_patch_identities_body = patch_identities_body;
205
206    let uri_str = format!("{}/admin/identities", configuration.base_path);
207    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
208
209    if let Some(ref user_agent) = configuration.user_agent {
210        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
211    }
212    if let Some(ref apikey) = configuration.api_key {
213        let key = apikey.key.clone();
214        let value = match apikey.prefix {
215            Some(ref prefix) => format!("{} {}", prefix, key),
216            None => key,
217        };
218        req_builder = req_builder.header("Authorization", value);
219    };
220    req_builder = req_builder.json(&p_body_patch_identities_body);
221
222    let req = req_builder.build()?;
223    let resp = configuration.client.execute(req).await?;
224
225    let status = resp.status();
226    let content_type = resp
227        .headers()
228        .get("content-type")
229        .and_then(|v| v.to_str().ok())
230        .unwrap_or("application/octet-stream");
231    let content_type = super::ContentType::from(content_type);
232
233    if !status.is_client_error() && !status.is_server_error() {
234        let content = resp.text().await?;
235        match content_type {
236            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
237            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BatchPatchIdentitiesResponse`"))),
238            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::BatchPatchIdentitiesResponse`")))),
239        }
240    } else {
241        let content = resp.text().await?;
242        let entity: Option<BatchPatchIdentitiesError> = serde_json::from_str(&content).ok();
243        Err(Error::ResponseError(ResponseContent { status, content, entity }))
244    }
245}
246
247/// Create an [identity](https://www.ory.sh/docs/kratos/concepts/identity-user-model).  This endpoint can also be used to [import credentials](https://www.ory.sh/docs/kratos/manage-identities/import-user-accounts-identities) for instance passwords, social sign in configurations or multifactor methods.
248pub async fn create_identity(configuration: &configuration::Configuration, create_identity_body: Option<models::CreateIdentityBody>) -> Result<models::Identity, Error<CreateIdentityError>> {
249    // add a prefix to parameters to efficiently prevent name collisions
250    let p_body_create_identity_body = create_identity_body;
251
252    let uri_str = format!("{}/admin/identities", configuration.base_path);
253    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
254
255    if let Some(ref user_agent) = configuration.user_agent {
256        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
257    }
258    if let Some(ref apikey) = configuration.api_key {
259        let key = apikey.key.clone();
260        let value = match apikey.prefix {
261            Some(ref prefix) => format!("{} {}", prefix, key),
262            None => key,
263        };
264        req_builder = req_builder.header("Authorization", value);
265    };
266    req_builder = req_builder.json(&p_body_create_identity_body);
267
268    let req = req_builder.build()?;
269    let resp = configuration.client.execute(req).await?;
270
271    let status = resp.status();
272    let content_type = resp
273        .headers()
274        .get("content-type")
275        .and_then(|v| v.to_str().ok())
276        .unwrap_or("application/octet-stream");
277    let content_type = super::ContentType::from(content_type);
278
279    if !status.is_client_error() && !status.is_server_error() {
280        let content = resp.text().await?;
281        match content_type {
282            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
283            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Identity`"))),
284            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Identity`")))),
285        }
286    } else {
287        let content = resp.text().await?;
288        let entity: Option<CreateIdentityError> = serde_json::from_str(&content).ok();
289        Err(Error::ResponseError(ResponseContent { status, content, entity }))
290    }
291}
292
293/// This endpoint creates a recovery code which should be given to the user in order for them to recover (or activate) their account.
294pub async fn create_recovery_code_for_identity(configuration: &configuration::Configuration, create_recovery_code_for_identity_body: Option<models::CreateRecoveryCodeForIdentityBody>) -> Result<models::RecoveryCodeForIdentity, Error<CreateRecoveryCodeForIdentityError>> {
295    // add a prefix to parameters to efficiently prevent name collisions
296    let p_body_create_recovery_code_for_identity_body = create_recovery_code_for_identity_body;
297
298    let uri_str = format!("{}/admin/recovery/code", configuration.base_path);
299    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
300
301    if let Some(ref user_agent) = configuration.user_agent {
302        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
303    }
304    if let Some(ref apikey) = configuration.api_key {
305        let key = apikey.key.clone();
306        let value = match apikey.prefix {
307            Some(ref prefix) => format!("{} {}", prefix, key),
308            None => key,
309        };
310        req_builder = req_builder.header("Authorization", value);
311    };
312    req_builder = req_builder.json(&p_body_create_recovery_code_for_identity_body);
313
314    let req = req_builder.build()?;
315    let resp = configuration.client.execute(req).await?;
316
317    let status = resp.status();
318    let content_type = resp
319        .headers()
320        .get("content-type")
321        .and_then(|v| v.to_str().ok())
322        .unwrap_or("application/octet-stream");
323    let content_type = super::ContentType::from(content_type);
324
325    if !status.is_client_error() && !status.is_server_error() {
326        let content = resp.text().await?;
327        match content_type {
328            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
329            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RecoveryCodeForIdentity`"))),
330            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RecoveryCodeForIdentity`")))),
331        }
332    } else {
333        let content = resp.text().await?;
334        let entity: Option<CreateRecoveryCodeForIdentityError> = serde_json::from_str(&content).ok();
335        Err(Error::ResponseError(ResponseContent { status, content, entity }))
336    }
337}
338
339/// This endpoint creates a recovery link which should be given to the user in order for them to recover (or activate) their account.
340pub async fn create_recovery_link_for_identity(configuration: &configuration::Configuration, return_to: Option<&str>, create_recovery_link_for_identity_body: Option<models::CreateRecoveryLinkForIdentityBody>) -> Result<models::RecoveryLinkForIdentity, Error<CreateRecoveryLinkForIdentityError>> {
341    // add a prefix to parameters to efficiently prevent name collisions
342    let p_query_return_to = return_to;
343    let p_body_create_recovery_link_for_identity_body = create_recovery_link_for_identity_body;
344
345    let uri_str = format!("{}/admin/recovery/link", configuration.base_path);
346    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
347
348    if let Some(ref param_value) = p_query_return_to {
349        req_builder = req_builder.query(&[("return_to", &param_value.to_string())]);
350    }
351    if let Some(ref user_agent) = configuration.user_agent {
352        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
353    }
354    if let Some(ref apikey) = configuration.api_key {
355        let key = apikey.key.clone();
356        let value = match apikey.prefix {
357            Some(ref prefix) => format!("{} {}", prefix, key),
358            None => key,
359        };
360        req_builder = req_builder.header("Authorization", value);
361    };
362    req_builder = req_builder.json(&p_body_create_recovery_link_for_identity_body);
363
364    let req = req_builder.build()?;
365    let resp = configuration.client.execute(req).await?;
366
367    let status = resp.status();
368    let content_type = resp
369        .headers()
370        .get("content-type")
371        .and_then(|v| v.to_str().ok())
372        .unwrap_or("application/octet-stream");
373    let content_type = super::ContentType::from(content_type);
374
375    if !status.is_client_error() && !status.is_server_error() {
376        let content = resp.text().await?;
377        match content_type {
378            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
379            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RecoveryLinkForIdentity`"))),
380            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RecoveryLinkForIdentity`")))),
381        }
382    } else {
383        let content = resp.text().await?;
384        let entity: Option<CreateRecoveryLinkForIdentityError> = serde_json::from_str(&content).ok();
385        Err(Error::ResponseError(ResponseContent { status, content, entity }))
386    }
387}
388
389/// Calling this endpoint irrecoverably and permanently deletes the [identity](https://www.ory.sh/docs/kratos/concepts/identity-user-model) given its ID. This action can not be undone. This endpoint returns 204 when the identity was deleted or 404 if the identity was not found.
390pub async fn delete_identity(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteIdentityError>> {
391    // add a prefix to parameters to efficiently prevent name collisions
392    let p_path_id = id;
393
394    let uri_str = format!("{}/admin/identities/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
395    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
396
397    if let Some(ref user_agent) = configuration.user_agent {
398        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
399    }
400    if let Some(ref apikey) = configuration.api_key {
401        let key = apikey.key.clone();
402        let value = match apikey.prefix {
403            Some(ref prefix) => format!("{} {}", prefix, key),
404            None => key,
405        };
406        req_builder = req_builder.header("Authorization", value);
407    };
408
409    let req = req_builder.build()?;
410    let resp = configuration.client.execute(req).await?;
411
412    let status = resp.status();
413
414    if !status.is_client_error() && !status.is_server_error() {
415        Ok(())
416    } else {
417        let content = resp.text().await?;
418        let entity: Option<DeleteIdentityError> = serde_json::from_str(&content).ok();
419        Err(Error::ResponseError(ResponseContent { status, content, entity }))
420    }
421}
422
423/// Delete an [identity](https://www.ory.sh/docs/kratos/concepts/identity-user-model) credential by its type. You cannot delete passkeys or code auth credentials through this API.
424pub async fn delete_identity_credentials(configuration: &configuration::Configuration, id: &str, r#type: &str, identifier: Option<&str>) -> Result<(), Error<DeleteIdentityCredentialsError>> {
425    // add a prefix to parameters to efficiently prevent name collisions
426    let p_path_id = id;
427    let p_path_type = r#type;
428    let p_query_identifier = identifier;
429
430    let uri_str = format!("{}/admin/identities/{id}/credentials/{type}", configuration.base_path, id=crate::apis::urlencode(p_path_id), type=crate::apis::urlencode(p_path_type));
431    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
432
433    if let Some(ref param_value) = p_query_identifier {
434        req_builder = req_builder.query(&[("identifier", &param_value.to_string())]);
435    }
436    if let Some(ref user_agent) = configuration.user_agent {
437        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
438    }
439    if let Some(ref apikey) = configuration.api_key {
440        let key = apikey.key.clone();
441        let value = match apikey.prefix {
442            Some(ref prefix) => format!("{} {}", prefix, key),
443            None => key,
444        };
445        req_builder = req_builder.header("Authorization", value);
446    };
447
448    let req = req_builder.build()?;
449    let resp = configuration.client.execute(req).await?;
450
451    let status = resp.status();
452
453    if !status.is_client_error() && !status.is_server_error() {
454        Ok(())
455    } else {
456        let content = resp.text().await?;
457        let entity: Option<DeleteIdentityCredentialsError> = serde_json::from_str(&content).ok();
458        Err(Error::ResponseError(ResponseContent { status, content, entity }))
459    }
460}
461
462/// Calling this endpoint irrecoverably and permanently deletes and invalidates all sessions that belong to the given Identity.
463pub async fn delete_identity_sessions(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteIdentitySessionsError>> {
464    // add a prefix to parameters to efficiently prevent name collisions
465    let p_path_id = id;
466
467    let uri_str = format!("{}/admin/identities/{id}/sessions", configuration.base_path, id=crate::apis::urlencode(p_path_id));
468    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
469
470    if let Some(ref user_agent) = configuration.user_agent {
471        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
472    }
473    if let Some(ref apikey) = configuration.api_key {
474        let key = apikey.key.clone();
475        let value = match apikey.prefix {
476            Some(ref prefix) => format!("{} {}", prefix, key),
477            None => key,
478        };
479        req_builder = req_builder.header("Authorization", value);
480    };
481
482    let req = req_builder.build()?;
483    let resp = configuration.client.execute(req).await?;
484
485    let status = resp.status();
486
487    if !status.is_client_error() && !status.is_server_error() {
488        Ok(())
489    } else {
490        let content = resp.text().await?;
491        let entity: Option<DeleteIdentitySessionsError> = serde_json::from_str(&content).ok();
492        Err(Error::ResponseError(ResponseContent { status, content, entity }))
493    }
494}
495
496/// Calling this endpoint deactivates the specified session. Session data is not deleted.
497pub async fn disable_session(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DisableSessionError>> {
498    // add a prefix to parameters to efficiently prevent name collisions
499    let p_path_id = id;
500
501    let uri_str = format!("{}/admin/sessions/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
502    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
503
504    if let Some(ref user_agent) = configuration.user_agent {
505        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
506    }
507    if let Some(ref apikey) = configuration.api_key {
508        let key = apikey.key.clone();
509        let value = match apikey.prefix {
510            Some(ref prefix) => format!("{} {}", prefix, key),
511            None => key,
512        };
513        req_builder = req_builder.header("Authorization", value);
514    };
515
516    let req = req_builder.build()?;
517    let resp = configuration.client.execute(req).await?;
518
519    let status = resp.status();
520
521    if !status.is_client_error() && !status.is_server_error() {
522        Ok(())
523    } else {
524        let content = resp.text().await?;
525        let entity: Option<DisableSessionError> = serde_json::from_str(&content).ok();
526        Err(Error::ResponseError(ResponseContent { status, content, entity }))
527    }
528}
529
530/// Calling this endpoint extends the given session ID. If `session.earliest_possible_extend` is set it will only extend the session after the specified time has passed.  This endpoint returns per default a 204 No Content response on success. Older Ory Network projects may return a 200 OK response with the session in the body. Returning the session as part of the response will be deprecated in the future and should not be relied upon.  This endpoint ignores consecutive requests to extend the same session and returns a 404 error in those scenarios. This endpoint also returns 404 errors if the session does not exist.  Retrieve the session ID from the `/sessions/whoami` endpoint / `toSession` SDK method.
531pub async fn extend_session(configuration: &configuration::Configuration, id: &str) -> Result<models::Session, Error<ExtendSessionError>> {
532    // add a prefix to parameters to efficiently prevent name collisions
533    let p_path_id = id;
534
535    let uri_str = format!("{}/admin/sessions/{id}/extend", configuration.base_path, id=crate::apis::urlencode(p_path_id));
536    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
537
538    if let Some(ref user_agent) = configuration.user_agent {
539        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
540    }
541    if let Some(ref apikey) = configuration.api_key {
542        let key = apikey.key.clone();
543        let value = match apikey.prefix {
544            Some(ref prefix) => format!("{} {}", prefix, key),
545            None => key,
546        };
547        req_builder = req_builder.header("Authorization", value);
548    };
549
550    let req = req_builder.build()?;
551    let resp = configuration.client.execute(req).await?;
552
553    let status = resp.status();
554    let content_type = resp
555        .headers()
556        .get("content-type")
557        .and_then(|v| v.to_str().ok())
558        .unwrap_or("application/octet-stream");
559    let content_type = super::ContentType::from(content_type);
560
561    if !status.is_client_error() && !status.is_server_error() {
562        let content = resp.text().await?;
563        match content_type {
564            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
565            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Session`"))),
566            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Session`")))),
567        }
568    } else {
569        let content = resp.text().await?;
570        let entity: Option<ExtendSessionError> = serde_json::from_str(&content).ok();
571        Err(Error::ResponseError(ResponseContent { status, content, entity }))
572    }
573}
574
575/// Return an [identity](https://www.ory.sh/docs/kratos/concepts/identity-user-model) by its ID. You can optionally include credentials (e.g. social sign in connections) in the response by using the `include_credential` query parameter.
576pub async fn get_identity(configuration: &configuration::Configuration, id: &str, include_credential: Option<Vec<String>>) -> Result<models::Identity, Error<GetIdentityError>> {
577    // add a prefix to parameters to efficiently prevent name collisions
578    let p_path_id = id;
579    let p_query_include_credential = include_credential;
580
581    let uri_str = format!("{}/admin/identities/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
582    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
583
584    if let Some(ref param_value) = p_query_include_credential {
585        req_builder = match "multi" {
586            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("include_credential".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
587            _ => req_builder.query(&[("include_credential", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
588        };
589    }
590    if let Some(ref user_agent) = configuration.user_agent {
591        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
592    }
593    if let Some(ref apikey) = configuration.api_key {
594        let key = apikey.key.clone();
595        let value = match apikey.prefix {
596            Some(ref prefix) => format!("{} {}", prefix, key),
597            None => key,
598        };
599        req_builder = req_builder.header("Authorization", value);
600    };
601
602    let req = req_builder.build()?;
603    let resp = configuration.client.execute(req).await?;
604
605    let status = resp.status();
606    let content_type = resp
607        .headers()
608        .get("content-type")
609        .and_then(|v| v.to_str().ok())
610        .unwrap_or("application/octet-stream");
611    let content_type = super::ContentType::from(content_type);
612
613    if !status.is_client_error() && !status.is_server_error() {
614        let content = resp.text().await?;
615        match content_type {
616            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
617            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Identity`"))),
618            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Identity`")))),
619        }
620    } else {
621        let content = resp.text().await?;
622        let entity: Option<GetIdentityError> = serde_json::from_str(&content).ok();
623        Err(Error::ResponseError(ResponseContent { status, content, entity }))
624    }
625}
626
627/// Return an [identity](https://www.ory.sh/docs/kratos/concepts/identity-user-model) by its external ID. You can optionally include credentials (e.g. social sign in connections) in the response by using the `include_credential` query parameter.
628pub async fn get_identity_by_external_id(configuration: &configuration::Configuration, external_id: &str, include_credential: Option<Vec<String>>) -> Result<models::Identity, Error<GetIdentityByExternalIdError>> {
629    // add a prefix to parameters to efficiently prevent name collisions
630    let p_path_external_id = external_id;
631    let p_query_include_credential = include_credential;
632
633    let uri_str = format!("{}/admin/identities/by/external/{externalID}", configuration.base_path, externalID=crate::apis::urlencode(p_path_external_id));
634    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
635
636    if let Some(ref param_value) = p_query_include_credential {
637        req_builder = match "multi" {
638            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("include_credential".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
639            _ => req_builder.query(&[("include_credential", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
640        };
641    }
642    if let Some(ref user_agent) = configuration.user_agent {
643        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
644    }
645    if let Some(ref apikey) = configuration.api_key {
646        let key = apikey.key.clone();
647        let value = match apikey.prefix {
648            Some(ref prefix) => format!("{} {}", prefix, key),
649            None => key,
650        };
651        req_builder = req_builder.header("Authorization", value);
652    };
653
654    let req = req_builder.build()?;
655    let resp = configuration.client.execute(req).await?;
656
657    let status = resp.status();
658    let content_type = resp
659        .headers()
660        .get("content-type")
661        .and_then(|v| v.to_str().ok())
662        .unwrap_or("application/octet-stream");
663    let content_type = super::ContentType::from(content_type);
664
665    if !status.is_client_error() && !status.is_server_error() {
666        let content = resp.text().await?;
667        match content_type {
668            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
669            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Identity`"))),
670            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Identity`")))),
671        }
672    } else {
673        let content = resp.text().await?;
674        let entity: Option<GetIdentityByExternalIdError> = serde_json::from_str(&content).ok();
675        Err(Error::ResponseError(ResponseContent { status, content, entity }))
676    }
677}
678
679/// Return a specific identity schema.
680pub async fn get_identity_schema(configuration: &configuration::Configuration, id: &str) -> Result<serde_json::Value, Error<GetIdentitySchemaError>> {
681    // add a prefix to parameters to efficiently prevent name collisions
682    let p_path_id = id;
683
684    let uri_str = format!("{}/schemas/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
685    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
686
687    if let Some(ref user_agent) = configuration.user_agent {
688        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
689    }
690
691    let req = req_builder.build()?;
692    let resp = configuration.client.execute(req).await?;
693
694    let status = resp.status();
695    let content_type = resp
696        .headers()
697        .get("content-type")
698        .and_then(|v| v.to_str().ok())
699        .unwrap_or("application/octet-stream");
700    let content_type = super::ContentType::from(content_type);
701
702    if !status.is_client_error() && !status.is_server_error() {
703        let content = resp.text().await?;
704        match content_type {
705            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
706            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `serde_json::Value`"))),
707            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `serde_json::Value`")))),
708        }
709    } else {
710        let content = resp.text().await?;
711        let entity: Option<GetIdentitySchemaError> = serde_json::from_str(&content).ok();
712        Err(Error::ResponseError(ResponseContent { status, content, entity }))
713    }
714}
715
716/// This endpoint is useful for:  Getting a session object with all specified expandables that exist in an administrative context.
717pub async fn get_session(configuration: &configuration::Configuration, id: &str, expand: Option<Vec<String>>) -> Result<models::Session, Error<GetSessionError>> {
718    // add a prefix to parameters to efficiently prevent name collisions
719    let p_path_id = id;
720    let p_query_expand = expand;
721
722    let uri_str = format!("{}/admin/sessions/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
723    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
724
725    if let Some(ref param_value) = p_query_expand {
726        req_builder = match "multi" {
727            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("expand".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
728            _ => req_builder.query(&[("expand", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
729        };
730    }
731    if let Some(ref user_agent) = configuration.user_agent {
732        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
733    }
734    if let Some(ref apikey) = configuration.api_key {
735        let key = apikey.key.clone();
736        let value = match apikey.prefix {
737            Some(ref prefix) => format!("{} {}", prefix, key),
738            None => key,
739        };
740        req_builder = req_builder.header("Authorization", value);
741    };
742
743    let req = req_builder.build()?;
744    let resp = configuration.client.execute(req).await?;
745
746    let status = resp.status();
747    let content_type = resp
748        .headers()
749        .get("content-type")
750        .and_then(|v| v.to_str().ok())
751        .unwrap_or("application/octet-stream");
752    let content_type = super::ContentType::from(content_type);
753
754    if !status.is_client_error() && !status.is_server_error() {
755        let content = resp.text().await?;
756        match content_type {
757            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
758            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Session`"))),
759            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Session`")))),
760        }
761    } else {
762        let content = resp.text().await?;
763        let entity: Option<GetSessionError> = serde_json::from_str(&content).ok();
764        Err(Error::ResponseError(ResponseContent { status, content, entity }))
765    }
766}
767
768/// Lists all [identities](https://www.ory.sh/docs/kratos/concepts/identity-user-model) in the system. Note: filters cannot be combined.
769pub async fn list_identities(configuration: &configuration::Configuration, per_page: Option<i64>, page: Option<i64>, page_size: Option<i64>, page_token: Option<&str>, consistency: Option<&str>, ids: Option<Vec<String>>, credentials_identifier: Option<&str>, preview_credentials_identifier_similar: Option<&str>, include_credential: Option<Vec<String>>, organization_id: Option<&str>) -> Result<Vec<models::Identity>, Error<ListIdentitiesError>> {
770    // add a prefix to parameters to efficiently prevent name collisions
771    let p_query_per_page = per_page;
772    let p_query_page = page;
773    let p_query_page_size = page_size;
774    let p_query_page_token = page_token;
775    let p_query_consistency = consistency;
776    let p_query_ids = ids;
777    let p_query_credentials_identifier = credentials_identifier;
778    let p_query_preview_credentials_identifier_similar = preview_credentials_identifier_similar;
779    let p_query_include_credential = include_credential;
780    let p_query_organization_id = organization_id;
781
782    let uri_str = format!("{}/admin/identities", configuration.base_path);
783    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
784
785    if let Some(ref param_value) = p_query_per_page {
786        req_builder = req_builder.query(&[("per_page", &param_value.to_string())]);
787    }
788    if let Some(ref param_value) = p_query_page {
789        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
790    }
791    if let Some(ref param_value) = p_query_page_size {
792        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
793    }
794    if let Some(ref param_value) = p_query_page_token {
795        req_builder = req_builder.query(&[("page_token", &param_value.to_string())]);
796    }
797    if let Some(ref param_value) = p_query_consistency {
798        req_builder = req_builder.query(&[("consistency", &param_value.to_string())]);
799    }
800    if let Some(ref param_value) = p_query_ids {
801        req_builder = match "multi" {
802            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("ids".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
803            _ => req_builder.query(&[("ids", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
804        };
805    }
806    if let Some(ref param_value) = p_query_credentials_identifier {
807        req_builder = req_builder.query(&[("credentials_identifier", &param_value.to_string())]);
808    }
809    if let Some(ref param_value) = p_query_preview_credentials_identifier_similar {
810        req_builder = req_builder.query(&[("preview_credentials_identifier_similar", &param_value.to_string())]);
811    }
812    if let Some(ref param_value) = p_query_include_credential {
813        req_builder = match "multi" {
814            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("include_credential".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
815            _ => req_builder.query(&[("include_credential", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
816        };
817    }
818    if let Some(ref param_value) = p_query_organization_id {
819        req_builder = req_builder.query(&[("organization_id", &param_value.to_string())]);
820    }
821    if let Some(ref user_agent) = configuration.user_agent {
822        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
823    }
824    if let Some(ref apikey) = configuration.api_key {
825        let key = apikey.key.clone();
826        let value = match apikey.prefix {
827            Some(ref prefix) => format!("{} {}", prefix, key),
828            None => key,
829        };
830        req_builder = req_builder.header("Authorization", value);
831    };
832
833    let req = req_builder.build()?;
834    let resp = configuration.client.execute(req).await?;
835
836    let status = resp.status();
837    let content_type = resp
838        .headers()
839        .get("content-type")
840        .and_then(|v| v.to_str().ok())
841        .unwrap_or("application/octet-stream");
842    let content_type = super::ContentType::from(content_type);
843
844    if !status.is_client_error() && !status.is_server_error() {
845        let content = resp.text().await?;
846        match content_type {
847            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
848            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::Identity&gt;`"))),
849            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::Identity&gt;`")))),
850        }
851    } else {
852        let content = resp.text().await?;
853        let entity: Option<ListIdentitiesError> = serde_json::from_str(&content).ok();
854        Err(Error::ResponseError(ResponseContent { status, content, entity }))
855    }
856}
857
858/// Returns a list of all identity schemas currently in use.
859pub async fn list_identity_schemas(configuration: &configuration::Configuration, per_page: Option<i64>, page: Option<i64>, page_size: Option<i64>, page_token: Option<&str>) -> Result<Vec<models::IdentitySchemaContainer>, Error<ListIdentitySchemasError>> {
860    // add a prefix to parameters to efficiently prevent name collisions
861    let p_query_per_page = per_page;
862    let p_query_page = page;
863    let p_query_page_size = page_size;
864    let p_query_page_token = page_token;
865
866    let uri_str = format!("{}/schemas", configuration.base_path);
867    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
868
869    if let Some(ref param_value) = p_query_per_page {
870        req_builder = req_builder.query(&[("per_page", &param_value.to_string())]);
871    }
872    if let Some(ref param_value) = p_query_page {
873        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
874    }
875    if let Some(ref param_value) = p_query_page_size {
876        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
877    }
878    if let Some(ref param_value) = p_query_page_token {
879        req_builder = req_builder.query(&[("page_token", &param_value.to_string())]);
880    }
881    if let Some(ref user_agent) = configuration.user_agent {
882        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
883    }
884
885    let req = req_builder.build()?;
886    let resp = configuration.client.execute(req).await?;
887
888    let status = resp.status();
889    let content_type = resp
890        .headers()
891        .get("content-type")
892        .and_then(|v| v.to_str().ok())
893        .unwrap_or("application/octet-stream");
894    let content_type = super::ContentType::from(content_type);
895
896    if !status.is_client_error() && !status.is_server_error() {
897        let content = resp.text().await?;
898        match content_type {
899            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
900            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::IdentitySchemaContainer&gt;`"))),
901            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::IdentitySchemaContainer&gt;`")))),
902        }
903    } else {
904        let content = resp.text().await?;
905        let entity: Option<ListIdentitySchemasError> = serde_json::from_str(&content).ok();
906        Err(Error::ResponseError(ResponseContent { status, content, entity }))
907    }
908}
909
910/// This endpoint returns all sessions that belong to the given Identity.
911pub async fn list_identity_sessions(configuration: &configuration::Configuration, id: &str, per_page: Option<i64>, page: Option<i64>, page_size: Option<i64>, page_token: Option<&str>, active: Option<bool>) -> Result<Vec<models::Session>, Error<ListIdentitySessionsError>> {
912    // add a prefix to parameters to efficiently prevent name collisions
913    let p_path_id = id;
914    let p_query_per_page = per_page;
915    let p_query_page = page;
916    let p_query_page_size = page_size;
917    let p_query_page_token = page_token;
918    let p_query_active = active;
919
920    let uri_str = format!("{}/admin/identities/{id}/sessions", configuration.base_path, id=crate::apis::urlencode(p_path_id));
921    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
922
923    if let Some(ref param_value) = p_query_per_page {
924        req_builder = req_builder.query(&[("per_page", &param_value.to_string())]);
925    }
926    if let Some(ref param_value) = p_query_page {
927        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
928    }
929    if let Some(ref param_value) = p_query_page_size {
930        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
931    }
932    if let Some(ref param_value) = p_query_page_token {
933        req_builder = req_builder.query(&[("page_token", &param_value.to_string())]);
934    }
935    if let Some(ref param_value) = p_query_active {
936        req_builder = req_builder.query(&[("active", &param_value.to_string())]);
937    }
938    if let Some(ref user_agent) = configuration.user_agent {
939        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
940    }
941    if let Some(ref apikey) = configuration.api_key {
942        let key = apikey.key.clone();
943        let value = match apikey.prefix {
944            Some(ref prefix) => format!("{} {}", prefix, key),
945            None => key,
946        };
947        req_builder = req_builder.header("Authorization", value);
948    };
949
950    let req = req_builder.build()?;
951    let resp = configuration.client.execute(req).await?;
952
953    let status = resp.status();
954    let content_type = resp
955        .headers()
956        .get("content-type")
957        .and_then(|v| v.to_str().ok())
958        .unwrap_or("application/octet-stream");
959    let content_type = super::ContentType::from(content_type);
960
961    if !status.is_client_error() && !status.is_server_error() {
962        let content = resp.text().await?;
963        match content_type {
964            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
965            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::Session&gt;`"))),
966            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::Session&gt;`")))),
967        }
968    } else {
969        let content = resp.text().await?;
970        let entity: Option<ListIdentitySessionsError> = serde_json::from_str(&content).ok();
971        Err(Error::ResponseError(ResponseContent { status, content, entity }))
972    }
973}
974
975/// Listing all sessions that exist.
976pub async fn list_sessions(configuration: &configuration::Configuration, page_size: Option<i64>, page_token: Option<&str>, active: Option<bool>, expand: Option<Vec<String>>) -> Result<Vec<models::Session>, Error<ListSessionsError>> {
977    // add a prefix to parameters to efficiently prevent name collisions
978    let p_query_page_size = page_size;
979    let p_query_page_token = page_token;
980    let p_query_active = active;
981    let p_query_expand = expand;
982
983    let uri_str = format!("{}/admin/sessions", configuration.base_path);
984    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
985
986    if let Some(ref param_value) = p_query_page_size {
987        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
988    }
989    if let Some(ref param_value) = p_query_page_token {
990        req_builder = req_builder.query(&[("page_token", &param_value.to_string())]);
991    }
992    if let Some(ref param_value) = p_query_active {
993        req_builder = req_builder.query(&[("active", &param_value.to_string())]);
994    }
995    if let Some(ref param_value) = p_query_expand {
996        req_builder = match "multi" {
997            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("expand".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
998            _ => req_builder.query(&[("expand", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
999        };
1000    }
1001    if let Some(ref user_agent) = configuration.user_agent {
1002        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1003    }
1004    if let Some(ref apikey) = configuration.api_key {
1005        let key = apikey.key.clone();
1006        let value = match apikey.prefix {
1007            Some(ref prefix) => format!("{} {}", prefix, key),
1008            None => key,
1009        };
1010        req_builder = req_builder.header("Authorization", value);
1011    };
1012
1013    let req = req_builder.build()?;
1014    let resp = configuration.client.execute(req).await?;
1015
1016    let status = resp.status();
1017    let content_type = resp
1018        .headers()
1019        .get("content-type")
1020        .and_then(|v| v.to_str().ok())
1021        .unwrap_or("application/octet-stream");
1022    let content_type = super::ContentType::from(content_type);
1023
1024    if !status.is_client_error() && !status.is_server_error() {
1025        let content = resp.text().await?;
1026        match content_type {
1027            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1028            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::Session&gt;`"))),
1029            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::Session&gt;`")))),
1030        }
1031    } else {
1032        let content = resp.text().await?;
1033        let entity: Option<ListSessionsError> = serde_json::from_str(&content).ok();
1034        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1035    }
1036}
1037
1038/// Partially updates an [identity's](https://www.ory.sh/docs/kratos/concepts/identity-user-model) field using [JSON Patch](https://jsonpatch.com/). The fields `id`, `stateChangedAt` and `credentials` can not be updated using this method.
1039pub async fn patch_identity(configuration: &configuration::Configuration, id: &str, json_patch: Option<Vec<models::JsonPatch>>) -> Result<models::Identity, Error<PatchIdentityError>> {
1040    // add a prefix to parameters to efficiently prevent name collisions
1041    let p_path_id = id;
1042    let p_body_json_patch = json_patch;
1043
1044    let uri_str = format!("{}/admin/identities/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
1045    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
1046
1047    if let Some(ref user_agent) = configuration.user_agent {
1048        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1049    }
1050    if let Some(ref apikey) = configuration.api_key {
1051        let key = apikey.key.clone();
1052        let value = match apikey.prefix {
1053            Some(ref prefix) => format!("{} {}", prefix, key),
1054            None => key,
1055        };
1056        req_builder = req_builder.header("Authorization", value);
1057    };
1058    req_builder = req_builder.json(&p_body_json_patch);
1059
1060    let req = req_builder.build()?;
1061    let resp = configuration.client.execute(req).await?;
1062
1063    let status = resp.status();
1064    let content_type = resp
1065        .headers()
1066        .get("content-type")
1067        .and_then(|v| v.to_str().ok())
1068        .unwrap_or("application/octet-stream");
1069    let content_type = super::ContentType::from(content_type);
1070
1071    if !status.is_client_error() && !status.is_server_error() {
1072        let content = resp.text().await?;
1073        match content_type {
1074            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1075            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Identity`"))),
1076            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Identity`")))),
1077        }
1078    } else {
1079        let content = resp.text().await?;
1080        let entity: Option<PatchIdentityError> = serde_json::from_str(&content).ok();
1081        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1082    }
1083}
1084
1085/// This endpoint updates an [identity](https://www.ory.sh/docs/kratos/concepts/identity-user-model). The full identity payload, except credentials, is expected. For partial updates, use the [patchIdentity](https://www.ory.sh/docs/reference/api#tag/identity/operation/patchIdentity) operation.  A credential can be provided via the `credentials` field in the request body. If provided, the credentials will be imported and added to the existing credentials of the identity.
1086pub async fn update_identity(configuration: &configuration::Configuration, id: &str, update_identity_body: Option<models::UpdateIdentityBody>) -> Result<models::Identity, Error<UpdateIdentityError>> {
1087    // add a prefix to parameters to efficiently prevent name collisions
1088    let p_path_id = id;
1089    let p_body_update_identity_body = update_identity_body;
1090
1091    let uri_str = format!("{}/admin/identities/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
1092    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
1093
1094    if let Some(ref user_agent) = configuration.user_agent {
1095        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1096    }
1097    if let Some(ref apikey) = configuration.api_key {
1098        let key = apikey.key.clone();
1099        let value = match apikey.prefix {
1100            Some(ref prefix) => format!("{} {}", prefix, key),
1101            None => key,
1102        };
1103        req_builder = req_builder.header("Authorization", value);
1104    };
1105    req_builder = req_builder.json(&p_body_update_identity_body);
1106
1107    let req = req_builder.build()?;
1108    let resp = configuration.client.execute(req).await?;
1109
1110    let status = resp.status();
1111    let content_type = resp
1112        .headers()
1113        .get("content-type")
1114        .and_then(|v| v.to_str().ok())
1115        .unwrap_or("application/octet-stream");
1116    let content_type = super::ContentType::from(content_type);
1117
1118    if !status.is_client_error() && !status.is_server_error() {
1119        let content = resp.text().await?;
1120        match content_type {
1121            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1122            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Identity`"))),
1123            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Identity`")))),
1124        }
1125    } else {
1126        let content = resp.text().await?;
1127        let entity: Option<UpdateIdentityError> = serde_json::from_str(&content).ok();
1128        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1129    }
1130}
1131