clerk_fapi_rs/apis/
organization_api.rs

1/*
2 * Clerk Frontend API
3 *
4 * The Clerk REST Frontend API, meant to be accessed from a browser or native environment.  This is a Form Based API and all the data must be sent and formatted according to the `application/x-www-form-urlencoded` content type.  ### Versions  When the API changes in a way that isn't compatible with older versions, a new version is released. Each version is identified by its release date, e.g. `2021-02-05`. For more information, please see [Clerk API Versions](https://clerk.com/docs/backend-requests/versioning/overview).  ### Using the Try It Console  The `Try It` feature of the docs only works for **Development Instances** when using the `DevBrowser` security scheme. To use it, first generate a dev instance token from the `/v1/dev_browser` endpoint.  Please see https://clerk.com/docs for more information.
5 *
6 * The version of the OpenAPI document: v1
7 * Contact: support@clerk.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16/// struct for typed errors of method [`create_organization`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum CreateOrganizationError {
20    Status401(models::ClerkErrors),
21    Status403(models::ClerkErrors),
22    Status422(models::ClerkErrors),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`delete_organization`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum DeleteOrganizationError {
30    Status403(models::ClerkErrors),
31    Status404(models::ClerkErrors),
32    Status422(models::ClerkErrors),
33    UnknownValue(serde_json::Value),
34}
35
36/// struct for typed errors of method [`delete_organization_logo`]
37#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum DeleteOrganizationLogoError {
40    Status401(models::ClerkErrors),
41    Status403(models::ClerkErrors),
42    Status404(models::ClerkErrors),
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`get_organization`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum GetOrganizationError {
50    Status401(models::ClerkErrors),
51    Status403(models::ClerkErrors),
52    Status404(models::ClerkErrors),
53    UnknownValue(serde_json::Value),
54}
55
56/// struct for typed errors of method [`update_organization`]
57#[derive(Debug, Clone, Serialize, Deserialize)]
58#[serde(untagged)]
59pub enum UpdateOrganizationError {
60    Status400(models::ClerkErrors),
61    Status401(models::ClerkErrors),
62    Status403(models::ClerkErrors),
63    Status404(models::ClerkErrors),
64    Status422(models::ClerkErrors),
65    UnknownValue(serde_json::Value),
66}
67
68/// struct for typed errors of method [`update_organization_logo`]
69#[derive(Debug, Clone, Serialize, Deserialize)]
70#[serde(untagged)]
71pub enum UpdateOrganizationLogoError {
72    Status400(models::ClerkErrors),
73    Status401(models::ClerkErrors),
74    Status403(models::ClerkErrors),
75    Status404(models::ClerkErrors),
76    Status413(models::ClerkErrors),
77    Status422(models::ClerkErrors),
78    UnknownValue(serde_json::Value),
79}
80
81/// Create an organization and add the current user as admin.
82pub async fn create_organization(
83    configuration: &configuration::Configuration,
84    name: Option<&str>,
85) -> Result<models::ClientClientWrappedOrganization, Error<CreateOrganizationError>> {
86    // add a prefix to parameters to efficiently prevent name collisions
87    let p_form_name = name;
88
89    let uri_str = format!("{}/v1/organizations", configuration.base_path);
90    let mut req_builder = configuration
91        .client
92        .request(reqwest::Method::POST, &uri_str);
93
94    if let Some(ref apikey) = configuration.api_key {
95        let key = apikey.key.clone();
96        let value = match apikey.prefix {
97            Some(ref prefix) => format!("{prefix} {key}"),
98            None => key,
99        };
100        req_builder = req_builder.query(&[("__dev_session", value)]);
101    }
102    if let Some(ref user_agent) = configuration.user_agent {
103        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
104    }
105    if let Some(ref apikey) = configuration.api_key {
106        let key = apikey.key.clone();
107        let value = match apikey.prefix {
108            Some(ref prefix) => format!("{prefix} {key}"),
109            None => key,
110        };
111        req_builder = req_builder.header("__session", value);
112    };
113    let mut multipart_form_params = std::collections::HashMap::new();
114    if let Some(param_value) = p_form_name {
115        multipart_form_params.insert("name", param_value.to_string());
116    }
117    req_builder = req_builder.form(&multipart_form_params);
118
119    let req = req_builder.build()?;
120    let resp = configuration.client.execute(req).await?;
121
122    let status = resp.status();
123    let content_type = resp
124        .headers()
125        .get("content-type")
126        .and_then(|v| v.to_str().ok())
127        .unwrap_or("application/octet-stream");
128    let content_type = super::ContentType::from(content_type);
129
130    if !status.is_client_error() && !status.is_server_error() {
131        let content = resp.text().await?;
132        match content_type {
133            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
134            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClientClientWrappedOrganization`"))),
135            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClientClientWrappedOrganization`")))),
136        }
137    } else {
138        let content = resp.text().await?;
139        let entity: Option<CreateOrganizationError> = serde_json::from_str(&content).ok();
140        Err(Error::ResponseError(ResponseContent {
141            status,
142            content,
143            entity,
144        }))
145    }
146}
147
148/// Delete the given organization.  The current user must be an admin in the organization.
149pub async fn delete_organization(
150    configuration: &configuration::Configuration,
151    organization_id: &str,
152) -> Result<models::ClientClientWrappedDeletedObject, Error<DeleteOrganizationError>> {
153    // add a prefix to parameters to efficiently prevent name collisions
154    let p_path_organization_id = organization_id;
155
156    let uri_str = format!(
157        "{}/v1/organizations/{organization_id}",
158        configuration.base_path,
159        organization_id = crate::apis::urlencode(p_path_organization_id)
160    );
161    let mut req_builder = configuration
162        .client
163        .request(reqwest::Method::DELETE, &uri_str);
164
165    if let Some(ref apikey) = configuration.api_key {
166        let key = apikey.key.clone();
167        let value = match apikey.prefix {
168            Some(ref prefix) => format!("{prefix} {key}"),
169            None => key,
170        };
171        req_builder = req_builder.query(&[("__dev_session", value)]);
172    }
173    if let Some(ref user_agent) = configuration.user_agent {
174        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
175    }
176    if let Some(ref apikey) = configuration.api_key {
177        let key = apikey.key.clone();
178        let value = match apikey.prefix {
179            Some(ref prefix) => format!("{prefix} {key}"),
180            None => key,
181        };
182        req_builder = req_builder.header("__session", value);
183    };
184
185    let req = req_builder.build()?;
186    let resp = configuration.client.execute(req).await?;
187
188    let status = resp.status();
189    let content_type = resp
190        .headers()
191        .get("content-type")
192        .and_then(|v| v.to_str().ok())
193        .unwrap_or("application/octet-stream");
194    let content_type = super::ContentType::from(content_type);
195
196    if !status.is_client_error() && !status.is_server_error() {
197        let content = resp.text().await?;
198        match content_type {
199            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
200            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClientClientWrappedDeletedObject`"))),
201            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClientClientWrappedDeletedObject`")))),
202        }
203    } else {
204        let content = resp.text().await?;
205        let entity: Option<DeleteOrganizationError> = serde_json::from_str(&content).ok();
206        Err(Error::ResponseError(ResponseContent {
207            status,
208            content,
209            entity,
210        }))
211    }
212}
213
214/// Delete the organization logo.  The current user must be an admin in the organization.
215pub async fn delete_organization_logo(
216    configuration: &configuration::Configuration,
217    organization_id: &str,
218) -> Result<models::ClientClientWrappedDeletedObject, Error<DeleteOrganizationLogoError>> {
219    // add a prefix to parameters to efficiently prevent name collisions
220    let p_path_organization_id = organization_id;
221
222    let uri_str = format!(
223        "{}/v1/organizations/{organization_id}/logo",
224        configuration.base_path,
225        organization_id = crate::apis::urlencode(p_path_organization_id)
226    );
227    let mut req_builder = configuration
228        .client
229        .request(reqwest::Method::DELETE, &uri_str);
230
231    if let Some(ref apikey) = configuration.api_key {
232        let key = apikey.key.clone();
233        let value = match apikey.prefix {
234            Some(ref prefix) => format!("{prefix} {key}"),
235            None => key,
236        };
237        req_builder = req_builder.query(&[("__dev_session", value)]);
238    }
239    if let Some(ref user_agent) = configuration.user_agent {
240        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
241    }
242    if let Some(ref apikey) = configuration.api_key {
243        let key = apikey.key.clone();
244        let value = match apikey.prefix {
245            Some(ref prefix) => format!("{prefix} {key}"),
246            None => key,
247        };
248        req_builder = req_builder.header("__session", value);
249    };
250
251    let req = req_builder.build()?;
252    let resp = configuration.client.execute(req).await?;
253
254    let status = resp.status();
255    let content_type = resp
256        .headers()
257        .get("content-type")
258        .and_then(|v| v.to_str().ok())
259        .unwrap_or("application/octet-stream");
260    let content_type = super::ContentType::from(content_type);
261
262    if !status.is_client_error() && !status.is_server_error() {
263        let content = resp.text().await?;
264        match content_type {
265            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
266            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClientClientWrappedDeletedObject`"))),
267            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClientClientWrappedDeletedObject`")))),
268        }
269    } else {
270        let content = resp.text().await?;
271        let entity: Option<DeleteOrganizationLogoError> = serde_json::from_str(&content).ok();
272        Err(Error::ResponseError(ResponseContent {
273            status,
274            content,
275            entity,
276        }))
277    }
278}
279
280/// Retrieve all properties of an organization that the current user is member of.
281pub async fn get_organization(
282    configuration: &configuration::Configuration,
283    organization_id: &str,
284) -> Result<models::ClientClientWrappedOrganization, Error<GetOrganizationError>> {
285    // add a prefix to parameters to efficiently prevent name collisions
286    let p_path_organization_id = organization_id;
287
288    let uri_str = format!(
289        "{}/v1/organizations/{organization_id}",
290        configuration.base_path,
291        organization_id = crate::apis::urlencode(p_path_organization_id)
292    );
293    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
294
295    if let Some(ref apikey) = configuration.api_key {
296        let key = apikey.key.clone();
297        let value = match apikey.prefix {
298            Some(ref prefix) => format!("{prefix} {key}"),
299            None => key,
300        };
301        req_builder = req_builder.query(&[("__dev_session", value)]);
302    }
303    if let Some(ref user_agent) = configuration.user_agent {
304        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
305    }
306    if let Some(ref apikey) = configuration.api_key {
307        let key = apikey.key.clone();
308        let value = match apikey.prefix {
309            Some(ref prefix) => format!("{prefix} {key}"),
310            None => key,
311        };
312        req_builder = req_builder.header("__session", value);
313    };
314
315    let req = req_builder.build()?;
316    let resp = configuration.client.execute(req).await?;
317
318    let status = resp.status();
319    let content_type = resp
320        .headers()
321        .get("content-type")
322        .and_then(|v| v.to_str().ok())
323        .unwrap_or("application/octet-stream");
324    let content_type = super::ContentType::from(content_type);
325
326    if !status.is_client_error() && !status.is_server_error() {
327        let content = resp.text().await?;
328        match content_type {
329            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
330            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClientClientWrappedOrganization`"))),
331            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClientClientWrappedOrganization`")))),
332        }
333    } else {
334        let content = resp.text().await?;
335        let entity: Option<GetOrganizationError> = serde_json::from_str(&content).ok();
336        Err(Error::ResponseError(ResponseContent {
337            status,
338            content,
339            entity,
340        }))
341    }
342}
343
344/// Update the given properties of an organization.  The current user must be an admin in the organization.
345pub async fn update_organization(
346    configuration: &configuration::Configuration,
347    organization_id: &str,
348    name: Option<&str>,
349    slug: Option<&str>,
350) -> Result<models::ClientClientWrappedOrganization, Error<UpdateOrganizationError>> {
351    // add a prefix to parameters to efficiently prevent name collisions
352    let p_path_organization_id = organization_id;
353    let p_form_name = name;
354    let p_form_slug = slug;
355
356    let uri_str = format!(
357        "{}/v1/organizations/{organization_id}",
358        configuration.base_path,
359        organization_id = crate::apis::urlencode(p_path_organization_id)
360    );
361    let mut req_builder = configuration
362        .client
363        .request(reqwest::Method::PATCH, &uri_str);
364
365    if let Some(ref apikey) = configuration.api_key {
366        let key = apikey.key.clone();
367        let value = match apikey.prefix {
368            Some(ref prefix) => format!("{prefix} {key}"),
369            None => key,
370        };
371        req_builder = req_builder.query(&[("__dev_session", value)]);
372    }
373    if let Some(ref user_agent) = configuration.user_agent {
374        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
375    }
376    if let Some(ref apikey) = configuration.api_key {
377        let key = apikey.key.clone();
378        let value = match apikey.prefix {
379            Some(ref prefix) => format!("{prefix} {key}"),
380            None => key,
381        };
382        req_builder = req_builder.header("__session", value);
383    };
384    let mut multipart_form_params = std::collections::HashMap::new();
385    if let Some(param_value) = p_form_name {
386        multipart_form_params.insert("name", param_value.to_string());
387    }
388    if let Some(param_value) = p_form_slug {
389        multipart_form_params.insert("slug", param_value.to_string());
390    }
391    req_builder = req_builder.form(&multipart_form_params);
392
393    let req = req_builder.build()?;
394    let resp = configuration.client.execute(req).await?;
395
396    let status = resp.status();
397    let content_type = resp
398        .headers()
399        .get("content-type")
400        .and_then(|v| v.to_str().ok())
401        .unwrap_or("application/octet-stream");
402    let content_type = super::ContentType::from(content_type);
403
404    if !status.is_client_error() && !status.is_server_error() {
405        let content = resp.text().await?;
406        match content_type {
407            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
408            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClientClientWrappedOrganization`"))),
409            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClientClientWrappedOrganization`")))),
410        }
411    } else {
412        let content = resp.text().await?;
413        let entity: Option<UpdateOrganizationError> = serde_json::from_str(&content).ok();
414        Err(Error::ResponseError(ResponseContent {
415            status,
416            content,
417            entity,
418        }))
419    }
420}
421
422/// Update the organization logo.  The current user must be an admin in the organization.
423pub async fn update_organization_logo(
424    configuration: &configuration::Configuration,
425    organization_id: &str,
426    file: super::FileData,
427) -> Result<models::SchemasClientClientWrappedOrganization, Error<UpdateOrganizationLogoError>> {
428    // add a prefix to parameters to efficiently prevent name collisions
429    let p_path_organization_id = organization_id;
430    let p_form_file = file;
431
432    let uri_str = format!(
433        "{}/v1/organizations/{organization_id}/logo",
434        configuration.base_path,
435        organization_id = crate::apis::urlencode(p_path_organization_id)
436    );
437    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
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.query(&[("__dev_session", value)]);
446    }
447    if let Some(ref user_agent) = configuration.user_agent {
448        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
449    }
450    if let Some(ref apikey) = configuration.api_key {
451        let key = apikey.key.clone();
452        let value = match apikey.prefix {
453            Some(ref prefix) => format!("{prefix} {key}"),
454            None => key,
455        };
456        req_builder = req_builder.header("__session", value);
457    };
458
459    let multipart_form = reqwest::multipart::Form::new().part(
460        "file",
461        reqwest::multipart::Part::bytes(p_form_file.data)
462            .file_name(p_form_file.name)
463            .mime_str(&p_form_file.mime_type)?,
464    );
465    req_builder = req_builder.multipart(multipart_form);
466
467    let req = req_builder.build()?;
468    let resp = configuration.client.execute(req).await?;
469
470    let status = resp.status();
471    let content_type = resp
472        .headers()
473        .get("content-type")
474        .and_then(|v| v.to_str().ok())
475        .unwrap_or("application/octet-stream");
476    let content_type = super::ContentType::from(content_type);
477
478    if !status.is_client_error() && !status.is_server_error() {
479        let content = resp.text().await?;
480        match content_type {
481            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
482            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SchemasClientClientWrappedOrganization`"))),
483            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::SchemasClientClientWrappedOrganization`")))),
484        }
485    } else {
486        let content = resp.text().await?;
487        let entity: Option<UpdateOrganizationLogoError> = serde_json::from_str(&content).ok();
488        Err(Error::ResponseError(ResponseContent {
489            status,
490            content,
491            entity,
492        }))
493    }
494}