clerk_fapi_rs/apis/
invitations_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 [`bulk_create_organization_invitations`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum BulkCreateOrganizationInvitationsError {
20    Status400(models::ClerkErrors),
21    Status401(models::ClerkErrors),
22    Status403(models::ClerkErrors),
23    Status404(models::ClerkErrors),
24    Status422(models::ClerkErrors),
25    UnknownValue(serde_json::Value),
26}
27
28/// struct for typed errors of method [`create_organization_invitations`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum CreateOrganizationInvitationsError {
32    Status400(models::ClerkErrors),
33    Status401(models::ClerkErrors),
34    Status403(models::ClerkErrors),
35    Status404(models::ClerkErrors),
36    Status422(models::ClerkErrors),
37    UnknownValue(serde_json::Value),
38}
39
40/// struct for typed errors of method [`get_all_pending_organization_invitations`]
41#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum GetAllPendingOrganizationInvitationsError {
44    Status401(models::ClerkErrors),
45    Status403(models::ClerkErrors),
46    Status422(models::ClerkErrors),
47    UnknownValue(serde_json::Value),
48}
49
50/// struct for typed errors of method [`get_organization_invitations`]
51#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum GetOrganizationInvitationsError {
54    Status400(models::ClerkErrors),
55    Status401(models::ClerkErrors),
56    Status403(models::ClerkErrors),
57    Status404(models::ClerkErrors),
58    Status422(models::ClerkErrors),
59    UnknownValue(serde_json::Value),
60}
61
62/// struct for typed errors of method [`revoke_pending_organization_invitation`]
63#[derive(Debug, Clone, Serialize, Deserialize)]
64#[serde(untagged)]
65pub enum RevokePendingOrganizationInvitationError {
66    Status401(models::ClerkErrors),
67    Status403(models::ClerkErrors),
68    Status404(models::ClerkErrors),
69    UnknownValue(serde_json::Value),
70}
71
72/// Create an invitation for a user to join an organization.  The current user must have permissions to manage the members of the organization.
73pub async fn bulk_create_organization_invitations(
74    configuration: &configuration::Configuration,
75    organization_id: &str,
76    email_address: Vec<String>,
77    role: &str,
78) -> Result<
79    models::ClientClientWrappedOrganizationInvitations,
80    Error<BulkCreateOrganizationInvitationsError>,
81> {
82    // add a prefix to parameters to efficiently prevent name collisions
83    let p_path_organization_id = organization_id;
84    let p_form_email_address = email_address;
85    let p_form_role = role;
86
87    let uri_str = format!(
88        "{}/v1/organizations/{organization_id}/invitations/bulk",
89        configuration.base_path,
90        organization_id = crate::apis::urlencode(p_path_organization_id)
91    );
92    let mut req_builder = configuration
93        .client
94        .request(reqwest::Method::POST, &uri_str);
95
96    if let Some(ref apikey) = configuration.api_key {
97        let key = apikey.key.clone();
98        let value = match apikey.prefix {
99            Some(ref prefix) => format!("{prefix} {key}"),
100            None => key,
101        };
102        req_builder = req_builder.query(&[("__dev_session", value)]);
103    }
104    if let Some(ref user_agent) = configuration.user_agent {
105        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
106    }
107    if let Some(ref apikey) = configuration.api_key {
108        let key = apikey.key.clone();
109        let value = match apikey.prefix {
110            Some(ref prefix) => format!("{prefix} {key}"),
111            None => key,
112        };
113        req_builder = req_builder.header("__session", value);
114    };
115    let mut multipart_form_params = std::collections::HashMap::new();
116    multipart_form_params.insert(
117        "email_address",
118        p_form_email_address
119            .into_iter()
120            .map(|p| p.to_string())
121            .collect::<Vec<String>>()
122            .join(",")
123            .to_string(),
124    );
125    multipart_form_params.insert("role", p_form_role.to_string());
126    req_builder = req_builder.form(&multipart_form_params);
127
128    let req = req_builder.build()?;
129    let resp = configuration.client.execute(req).await?;
130
131    let status = resp.status();
132    let content_type = resp
133        .headers()
134        .get("content-type")
135        .and_then(|v| v.to_str().ok())
136        .unwrap_or("application/octet-stream");
137    let content_type = super::ContentType::from(content_type);
138
139    if !status.is_client_error() && !status.is_server_error() {
140        let content = resp.text().await?;
141        match content_type {
142            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
143            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClientClientWrappedOrganizationInvitations`"))),
144            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClientClientWrappedOrganizationInvitations`")))),
145        }
146    } else {
147        let content = resp.text().await?;
148        let entity: Option<BulkCreateOrganizationInvitationsError> =
149            serde_json::from_str(&content).ok();
150        Err(Error::ResponseError(ResponseContent {
151            status,
152            content,
153            entity,
154        }))
155    }
156}
157
158/// Create an invitation for a user to join an organization.  The current user must have permissions to manage the members of the organization.
159pub async fn create_organization_invitations(
160    configuration: &configuration::Configuration,
161    organization_id: &str,
162    email_address: &str,
163    role: &str,
164) -> Result<
165    models::ClientClientWrappedOrganizationInvitation,
166    Error<CreateOrganizationInvitationsError>,
167> {
168    // add a prefix to parameters to efficiently prevent name collisions
169    let p_path_organization_id = organization_id;
170    let p_form_email_address = email_address;
171    let p_form_role = role;
172
173    let uri_str = format!(
174        "{}/v1/organizations/{organization_id}/invitations",
175        configuration.base_path,
176        organization_id = crate::apis::urlencode(p_path_organization_id)
177    );
178    let mut req_builder = configuration
179        .client
180        .request(reqwest::Method::POST, &uri_str);
181
182    if let Some(ref apikey) = configuration.api_key {
183        let key = apikey.key.clone();
184        let value = match apikey.prefix {
185            Some(ref prefix) => format!("{prefix} {key}"),
186            None => key,
187        };
188        req_builder = req_builder.query(&[("__dev_session", value)]);
189    }
190    if let Some(ref user_agent) = configuration.user_agent {
191        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
192    }
193    if let Some(ref apikey) = configuration.api_key {
194        let key = apikey.key.clone();
195        let value = match apikey.prefix {
196            Some(ref prefix) => format!("{prefix} {key}"),
197            None => key,
198        };
199        req_builder = req_builder.header("__session", value);
200    };
201    let mut multipart_form_params = std::collections::HashMap::new();
202    multipart_form_params.insert("email_address", p_form_email_address.to_string());
203    multipart_form_params.insert("role", p_form_role.to_string());
204    req_builder = req_builder.form(&multipart_form_params);
205
206    let req = req_builder.build()?;
207    let resp = configuration.client.execute(req).await?;
208
209    let status = resp.status();
210    let content_type = resp
211        .headers()
212        .get("content-type")
213        .and_then(|v| v.to_str().ok())
214        .unwrap_or("application/octet-stream");
215    let content_type = super::ContentType::from(content_type);
216
217    if !status.is_client_error() && !status.is_server_error() {
218        let content = resp.text().await?;
219        match content_type {
220            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
221            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClientClientWrappedOrganizationInvitation`"))),
222            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClientClientWrappedOrganizationInvitation`")))),
223        }
224    } else {
225        let content = resp.text().await?;
226        let entity: Option<CreateOrganizationInvitationsError> =
227            serde_json::from_str(&content).ok();
228        Err(Error::ResponseError(ResponseContent {
229            status,
230            content,
231            entity,
232        }))
233    }
234}
235
236/// Get a list of pending invitations for an organization.  This endpoint is deprecated. Instead use the `/v1/organizations/{organization_id}/invitations` with a query parameter of `status=pending`.
237pub async fn get_all_pending_organization_invitations(
238    configuration: &configuration::Configuration,
239    organization_id: &str,
240) -> Result<
241    models::ClientClientWrappedOrganizationInvitations,
242    Error<GetAllPendingOrganizationInvitationsError>,
243> {
244    // add a prefix to parameters to efficiently prevent name collisions
245    let p_path_organization_id = organization_id;
246
247    let uri_str = format!(
248        "{}/v1/organizations/{organization_id}/invitations/pending",
249        configuration.base_path,
250        organization_id = crate::apis::urlencode(p_path_organization_id)
251    );
252    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
253
254    if let Some(ref apikey) = configuration.api_key {
255        let key = apikey.key.clone();
256        let value = match apikey.prefix {
257            Some(ref prefix) => format!("{prefix} {key}"),
258            None => key,
259        };
260        req_builder = req_builder.query(&[("__dev_session", value)]);
261    }
262    if let Some(ref user_agent) = configuration.user_agent {
263        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
264    }
265    if let Some(ref apikey) = configuration.api_key {
266        let key = apikey.key.clone();
267        let value = match apikey.prefix {
268            Some(ref prefix) => format!("{prefix} {key}"),
269            None => key,
270        };
271        req_builder = req_builder.header("__session", value);
272    };
273
274    let req = req_builder.build()?;
275    let resp = configuration.client.execute(req).await?;
276
277    let status = resp.status();
278    let content_type = resp
279        .headers()
280        .get("content-type")
281        .and_then(|v| v.to_str().ok())
282        .unwrap_or("application/octet-stream");
283    let content_type = super::ContentType::from(content_type);
284
285    if !status.is_client_error() && !status.is_server_error() {
286        let content = resp.text().await?;
287        match content_type {
288            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
289            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClientClientWrappedOrganizationInvitations`"))),
290            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClientClientWrappedOrganizationInvitations`")))),
291        }
292    } else {
293        let content = resp.text().await?;
294        let entity: Option<GetAllPendingOrganizationInvitationsError> =
295            serde_json::from_str(&content).ok();
296        Err(Error::ResponseError(ResponseContent {
297            status,
298            content,
299            entity,
300        }))
301    }
302}
303
304/// Retrieve all invitations for an organization.  The current user must have permissions to manage the members of the organization.
305pub async fn get_organization_invitations(
306    configuration: &configuration::Configuration,
307    organization_id: &str,
308    limit: Option<i64>,
309    offset: Option<i64>,
310    status: Option<&str>,
311) -> Result<
312    models::ClientClientWrappedOrganizationInvitations,
313    Error<GetOrganizationInvitationsError>,
314> {
315    // add a prefix to parameters to efficiently prevent name collisions
316    let p_path_organization_id = organization_id;
317    let p_query_limit = limit;
318    let p_query_offset = offset;
319    let p_query_status = status;
320
321    let uri_str = format!(
322        "{}/v1/organizations/{organization_id}/invitations",
323        configuration.base_path,
324        organization_id = crate::apis::urlencode(p_path_organization_id)
325    );
326    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
327
328    if let Some(ref param_value) = p_query_limit {
329        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
330    }
331    if let Some(ref param_value) = p_query_offset {
332        req_builder = req_builder.query(&[("offset", &param_value.to_string())]);
333    }
334    if let Some(ref param_value) = p_query_status {
335        req_builder = req_builder.query(&[("status", &param_value.to_string())]);
336    }
337    if let Some(ref apikey) = configuration.api_key {
338        let key = apikey.key.clone();
339        let value = match apikey.prefix {
340            Some(ref prefix) => format!("{prefix} {key}"),
341            None => key,
342        };
343        req_builder = req_builder.query(&[("__dev_session", value)]);
344    }
345    if let Some(ref user_agent) = configuration.user_agent {
346        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
347    }
348    if let Some(ref apikey) = configuration.api_key {
349        let key = apikey.key.clone();
350        let value = match apikey.prefix {
351            Some(ref prefix) => format!("{prefix} {key}"),
352            None => key,
353        };
354        req_builder = req_builder.header("__session", value);
355    };
356
357    let req = req_builder.build()?;
358    let resp = configuration.client.execute(req).await?;
359
360    let status = resp.status();
361    let content_type = resp
362        .headers()
363        .get("content-type")
364        .and_then(|v| v.to_str().ok())
365        .unwrap_or("application/octet-stream");
366    let content_type = super::ContentType::from(content_type);
367
368    if !status.is_client_error() && !status.is_server_error() {
369        let content = resp.text().await?;
370        match content_type {
371            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
372            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClientClientWrappedOrganizationInvitations`"))),
373            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClientClientWrappedOrganizationInvitations`")))),
374        }
375    } else {
376        let content = resp.text().await?;
377        let entity: Option<GetOrganizationInvitationsError> = serde_json::from_str(&content).ok();
378        Err(Error::ResponseError(ResponseContent {
379            status,
380            content,
381            entity,
382        }))
383    }
384}
385
386/// Revoke a pending organization invitation.  The current user must have permissions to manage the members of the organization.
387pub async fn revoke_pending_organization_invitation(
388    configuration: &configuration::Configuration,
389    organization_id: &str,
390    invitation_id: &str,
391) -> Result<
392    models::ClientClientWrappedOrganizationInvitation,
393    Error<RevokePendingOrganizationInvitationError>,
394> {
395    // add a prefix to parameters to efficiently prevent name collisions
396    let p_path_organization_id = organization_id;
397    let p_path_invitation_id = invitation_id;
398
399    let uri_str = format!(
400        "{}/v1/organizations/{organization_id}/invitations/{invitation_id}/revoke",
401        configuration.base_path,
402        organization_id = crate::apis::urlencode(p_path_organization_id),
403        invitation_id = crate::apis::urlencode(p_path_invitation_id)
404    );
405    let mut req_builder = configuration
406        .client
407        .request(reqwest::Method::POST, &uri_str);
408
409    if let Some(ref apikey) = configuration.api_key {
410        let key = apikey.key.clone();
411        let value = match apikey.prefix {
412            Some(ref prefix) => format!("{prefix} {key}"),
413            None => key,
414        };
415        req_builder = req_builder.query(&[("__dev_session", value)]);
416    }
417    if let Some(ref user_agent) = configuration.user_agent {
418        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
419    }
420    if let Some(ref apikey) = configuration.api_key {
421        let key = apikey.key.clone();
422        let value = match apikey.prefix {
423            Some(ref prefix) => format!("{prefix} {key}"),
424            None => key,
425        };
426        req_builder = req_builder.header("__session", value);
427    };
428
429    let req = req_builder.build()?;
430    let resp = configuration.client.execute(req).await?;
431
432    let status = resp.status();
433    let content_type = resp
434        .headers()
435        .get("content-type")
436        .and_then(|v| v.to_str().ok())
437        .unwrap_or("application/octet-stream");
438    let content_type = super::ContentType::from(content_type);
439
440    if !status.is_client_error() && !status.is_server_error() {
441        let content = resp.text().await?;
442        match content_type {
443            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
444            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClientClientWrappedOrganizationInvitation`"))),
445            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClientClientWrappedOrganizationInvitation`")))),
446        }
447    } else {
448        let content = resp.text().await?;
449        let entity: Option<RevokePendingOrganizationInvitationError> =
450            serde_json::from_str(&content).ok();
451        Err(Error::ResponseError(ResponseContent {
452            status,
453            content,
454            entity,
455        }))
456    }
457}