langfuse_client_base/apis/
organizations_api.rs

1/*
2 * langfuse
3 *
4 * ## Authentication  Authenticate with the API using [Basic Auth](https://en.wikipedia.org/wiki/Basic_access_authentication), get API keys in the project settings:  - username: Langfuse Public Key - password: Langfuse Secret Key  ## Exports  - OpenAPI spec: https://cloud.langfuse.com/generated/api/openapi.yml - Postman collection: https://cloud.langfuse.com/generated/postman/collection.json
5 *
6 * The version of the OpenAPI document:
7 *
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 [`organizations_delete_organization_membership`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum OrganizationsDeleteOrganizationMembershipError {
20    Status400(serde_json::Value),
21    Status401(serde_json::Value),
22    Status403(serde_json::Value),
23    Status404(serde_json::Value),
24    Status405(serde_json::Value),
25    UnknownValue(serde_json::Value),
26}
27
28/// struct for typed errors of method [`organizations_delete_project_membership`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum OrganizationsDeleteProjectMembershipError {
32    Status400(serde_json::Value),
33    Status401(serde_json::Value),
34    Status403(serde_json::Value),
35    Status404(serde_json::Value),
36    Status405(serde_json::Value),
37    UnknownValue(serde_json::Value),
38}
39
40/// struct for typed errors of method [`organizations_get_organization_memberships`]
41#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum OrganizationsGetOrganizationMembershipsError {
44    Status400(serde_json::Value),
45    Status401(serde_json::Value),
46    Status403(serde_json::Value),
47    Status404(serde_json::Value),
48    Status405(serde_json::Value),
49    UnknownValue(serde_json::Value),
50}
51
52/// struct for typed errors of method [`organizations_get_organization_projects`]
53#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum OrganizationsGetOrganizationProjectsError {
56    Status400(serde_json::Value),
57    Status401(serde_json::Value),
58    Status403(serde_json::Value),
59    Status404(serde_json::Value),
60    Status405(serde_json::Value),
61    UnknownValue(serde_json::Value),
62}
63
64/// struct for typed errors of method [`organizations_get_project_memberships`]
65#[derive(Debug, Clone, Serialize, Deserialize)]
66#[serde(untagged)]
67pub enum OrganizationsGetProjectMembershipsError {
68    Status400(serde_json::Value),
69    Status401(serde_json::Value),
70    Status403(serde_json::Value),
71    Status404(serde_json::Value),
72    Status405(serde_json::Value),
73    UnknownValue(serde_json::Value),
74}
75
76/// struct for typed errors of method [`organizations_update_organization_membership`]
77#[derive(Debug, Clone, Serialize, Deserialize)]
78#[serde(untagged)]
79pub enum OrganizationsUpdateOrganizationMembershipError {
80    Status400(serde_json::Value),
81    Status401(serde_json::Value),
82    Status403(serde_json::Value),
83    Status404(serde_json::Value),
84    Status405(serde_json::Value),
85    UnknownValue(serde_json::Value),
86}
87
88/// struct for typed errors of method [`organizations_update_project_membership`]
89#[derive(Debug, Clone, Serialize, Deserialize)]
90#[serde(untagged)]
91pub enum OrganizationsUpdateProjectMembershipError {
92    Status400(serde_json::Value),
93    Status401(serde_json::Value),
94    Status403(serde_json::Value),
95    Status404(serde_json::Value),
96    Status405(serde_json::Value),
97    UnknownValue(serde_json::Value),
98}
99
100/// Delete a membership from the organization associated with the API key (requires organization-scoped API key)
101pub async fn organizations_delete_organization_membership(
102    configuration: &configuration::Configuration,
103    delete_membership_request: models::DeleteMembershipRequest,
104) -> Result<models::MembershipDeletionResponse, Error<OrganizationsDeleteOrganizationMembershipError>>
105{
106    // add a prefix to parameters to efficiently prevent name collisions
107    let p_body_delete_membership_request = delete_membership_request;
108
109    let uri_str = format!(
110        "{}/api/public/organizations/memberships",
111        configuration.base_path
112    );
113    let mut req_builder = configuration
114        .client
115        .request(reqwest::Method::DELETE, &uri_str);
116
117    if let Some(ref user_agent) = configuration.user_agent {
118        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
119    }
120    if let Some(ref auth_conf) = configuration.basic_auth {
121        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
122    };
123    req_builder = req_builder.json(&p_body_delete_membership_request);
124
125    let req = req_builder.build()?;
126    let resp = configuration.client.execute(req).await?;
127
128    let status = resp.status();
129    let content_type = resp
130        .headers()
131        .get("content-type")
132        .and_then(|v| v.to_str().ok())
133        .unwrap_or("application/octet-stream");
134    let content_type = super::ContentType::from(content_type);
135
136    if !status.is_client_error() && !status.is_server_error() {
137        let content = resp.text().await?;
138        match content_type {
139            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
140            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MembershipDeletionResponse`"))),
141            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::MembershipDeletionResponse`")))),
142        }
143    } else {
144        let content = resp.text().await?;
145        let entity: Option<OrganizationsDeleteOrganizationMembershipError> =
146            serde_json::from_str(&content).ok();
147        Err(Error::ResponseError(ResponseContent {
148            status,
149            content,
150            entity,
151        }))
152    }
153}
154
155/// Delete a membership from a specific project (requires organization-scoped API key). The user must be a member of the organization.
156pub async fn organizations_delete_project_membership(
157    configuration: &configuration::Configuration,
158    project_id: &str,
159    delete_membership_request: models::DeleteMembershipRequest,
160) -> Result<models::MembershipDeletionResponse, Error<OrganizationsDeleteProjectMembershipError>> {
161    // add a prefix to parameters to efficiently prevent name collisions
162    let p_path_project_id = project_id;
163    let p_body_delete_membership_request = delete_membership_request;
164
165    let uri_str = format!(
166        "{}/api/public/projects/{projectId}/memberships",
167        configuration.base_path,
168        projectId = crate::apis::urlencode(p_path_project_id)
169    );
170    let mut req_builder = configuration
171        .client
172        .request(reqwest::Method::DELETE, &uri_str);
173
174    if let Some(ref user_agent) = configuration.user_agent {
175        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
176    }
177    if let Some(ref auth_conf) = configuration.basic_auth {
178        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
179    };
180    req_builder = req_builder.json(&p_body_delete_membership_request);
181
182    let req = req_builder.build()?;
183    let resp = configuration.client.execute(req).await?;
184
185    let status = resp.status();
186    let content_type = resp
187        .headers()
188        .get("content-type")
189        .and_then(|v| v.to_str().ok())
190        .unwrap_or("application/octet-stream");
191    let content_type = super::ContentType::from(content_type);
192
193    if !status.is_client_error() && !status.is_server_error() {
194        let content = resp.text().await?;
195        match content_type {
196            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
197            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MembershipDeletionResponse`"))),
198            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::MembershipDeletionResponse`")))),
199        }
200    } else {
201        let content = resp.text().await?;
202        let entity: Option<OrganizationsDeleteProjectMembershipError> =
203            serde_json::from_str(&content).ok();
204        Err(Error::ResponseError(ResponseContent {
205            status,
206            content,
207            entity,
208        }))
209    }
210}
211
212/// Get all memberships for the organization associated with the API key (requires organization-scoped API key)
213pub async fn organizations_get_organization_memberships(
214    configuration: &configuration::Configuration,
215) -> Result<models::MembershipsResponse, Error<OrganizationsGetOrganizationMembershipsError>> {
216    let uri_str = format!(
217        "{}/api/public/organizations/memberships",
218        configuration.base_path
219    );
220    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
221
222    if let Some(ref user_agent) = configuration.user_agent {
223        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
224    }
225    if let Some(ref auth_conf) = configuration.basic_auth {
226        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
227    };
228
229    let req = req_builder.build()?;
230    let resp = configuration.client.execute(req).await?;
231
232    let status = resp.status();
233    let content_type = resp
234        .headers()
235        .get("content-type")
236        .and_then(|v| v.to_str().ok())
237        .unwrap_or("application/octet-stream");
238    let content_type = super::ContentType::from(content_type);
239
240    if !status.is_client_error() && !status.is_server_error() {
241        let content = resp.text().await?;
242        match content_type {
243            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
244            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MembershipsResponse`"))),
245            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::MembershipsResponse`")))),
246        }
247    } else {
248        let content = resp.text().await?;
249        let entity: Option<OrganizationsGetOrganizationMembershipsError> =
250            serde_json::from_str(&content).ok();
251        Err(Error::ResponseError(ResponseContent {
252            status,
253            content,
254            entity,
255        }))
256    }
257}
258
259/// Get all projects for the organization associated with the API key (requires organization-scoped API key)
260pub async fn organizations_get_organization_projects(
261    configuration: &configuration::Configuration,
262) -> Result<models::OrganizationProjectsResponse, Error<OrganizationsGetOrganizationProjectsError>>
263{
264    let uri_str = format!(
265        "{}/api/public/organizations/projects",
266        configuration.base_path
267    );
268    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
269
270    if let Some(ref user_agent) = configuration.user_agent {
271        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
272    }
273    if let Some(ref auth_conf) = configuration.basic_auth {
274        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
275    };
276
277    let req = req_builder.build()?;
278    let resp = configuration.client.execute(req).await?;
279
280    let status = resp.status();
281    let content_type = resp
282        .headers()
283        .get("content-type")
284        .and_then(|v| v.to_str().ok())
285        .unwrap_or("application/octet-stream");
286    let content_type = super::ContentType::from(content_type);
287
288    if !status.is_client_error() && !status.is_server_error() {
289        let content = resp.text().await?;
290        match content_type {
291            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
292            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OrganizationProjectsResponse`"))),
293            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::OrganizationProjectsResponse`")))),
294        }
295    } else {
296        let content = resp.text().await?;
297        let entity: Option<OrganizationsGetOrganizationProjectsError> =
298            serde_json::from_str(&content).ok();
299        Err(Error::ResponseError(ResponseContent {
300            status,
301            content,
302            entity,
303        }))
304    }
305}
306
307/// Get all memberships for a specific project (requires organization-scoped API key)
308pub async fn organizations_get_project_memberships(
309    configuration: &configuration::Configuration,
310    project_id: &str,
311) -> Result<models::MembershipsResponse, Error<OrganizationsGetProjectMembershipsError>> {
312    // add a prefix to parameters to efficiently prevent name collisions
313    let p_path_project_id = project_id;
314
315    let uri_str = format!(
316        "{}/api/public/projects/{projectId}/memberships",
317        configuration.base_path,
318        projectId = crate::apis::urlencode(p_path_project_id)
319    );
320    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
321
322    if let Some(ref user_agent) = configuration.user_agent {
323        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
324    }
325    if let Some(ref auth_conf) = configuration.basic_auth {
326        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
327    };
328
329    let req = req_builder.build()?;
330    let resp = configuration.client.execute(req).await?;
331
332    let status = resp.status();
333    let content_type = resp
334        .headers()
335        .get("content-type")
336        .and_then(|v| v.to_str().ok())
337        .unwrap_or("application/octet-stream");
338    let content_type = super::ContentType::from(content_type);
339
340    if !status.is_client_error() && !status.is_server_error() {
341        let content = resp.text().await?;
342        match content_type {
343            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
344            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MembershipsResponse`"))),
345            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::MembershipsResponse`")))),
346        }
347    } else {
348        let content = resp.text().await?;
349        let entity: Option<OrganizationsGetProjectMembershipsError> =
350            serde_json::from_str(&content).ok();
351        Err(Error::ResponseError(ResponseContent {
352            status,
353            content,
354            entity,
355        }))
356    }
357}
358
359/// Create or update a membership for the organization associated with the API key (requires organization-scoped API key)
360pub async fn organizations_update_organization_membership(
361    configuration: &configuration::Configuration,
362    membership_request: models::MembershipRequest,
363) -> Result<models::MembershipResponse, Error<OrganizationsUpdateOrganizationMembershipError>> {
364    // add a prefix to parameters to efficiently prevent name collisions
365    let p_body_membership_request = membership_request;
366
367    let uri_str = format!(
368        "{}/api/public/organizations/memberships",
369        configuration.base_path
370    );
371    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
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 auth_conf) = configuration.basic_auth {
377        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
378    };
379    req_builder = req_builder.json(&p_body_membership_request);
380
381    let req = req_builder.build()?;
382    let resp = configuration.client.execute(req).await?;
383
384    let status = resp.status();
385    let content_type = resp
386        .headers()
387        .get("content-type")
388        .and_then(|v| v.to_str().ok())
389        .unwrap_or("application/octet-stream");
390    let content_type = super::ContentType::from(content_type);
391
392    if !status.is_client_error() && !status.is_server_error() {
393        let content = resp.text().await?;
394        match content_type {
395            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
396            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MembershipResponse`"))),
397            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::MembershipResponse`")))),
398        }
399    } else {
400        let content = resp.text().await?;
401        let entity: Option<OrganizationsUpdateOrganizationMembershipError> =
402            serde_json::from_str(&content).ok();
403        Err(Error::ResponseError(ResponseContent {
404            status,
405            content,
406            entity,
407        }))
408    }
409}
410
411/// Create or update a membership for a specific project (requires organization-scoped API key). The user must already be a member of the organization.
412pub async fn organizations_update_project_membership(
413    configuration: &configuration::Configuration,
414    project_id: &str,
415    membership_request: models::MembershipRequest,
416) -> Result<models::MembershipResponse, Error<OrganizationsUpdateProjectMembershipError>> {
417    // add a prefix to parameters to efficiently prevent name collisions
418    let p_path_project_id = project_id;
419    let p_body_membership_request = membership_request;
420
421    let uri_str = format!(
422        "{}/api/public/projects/{projectId}/memberships",
423        configuration.base_path,
424        projectId = crate::apis::urlencode(p_path_project_id)
425    );
426    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
427
428    if let Some(ref user_agent) = configuration.user_agent {
429        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
430    }
431    if let Some(ref auth_conf) = configuration.basic_auth {
432        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
433    };
434    req_builder = req_builder.json(&p_body_membership_request);
435
436    let req = req_builder.build()?;
437    let resp = configuration.client.execute(req).await?;
438
439    let status = resp.status();
440    let content_type = resp
441        .headers()
442        .get("content-type")
443        .and_then(|v| v.to_str().ok())
444        .unwrap_or("application/octet-stream");
445    let content_type = super::ContentType::from(content_type);
446
447    if !status.is_client_error() && !status.is_server_error() {
448        let content = resp.text().await?;
449        match content_type {
450            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
451            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MembershipResponse`"))),
452            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::MembershipResponse`")))),
453        }
454    } else {
455        let content = resp.text().await?;
456        let entity: Option<OrganizationsUpdateProjectMembershipError> =
457            serde_json::from_str(&content).ok();
458        Err(Error::ResponseError(ResponseContent {
459            status,
460            content,
461            entity,
462        }))
463    }
464}