trieve_client/apis/
invitation_api.rs

1/*
2 * Trieve API
3 *
4 * Trieve OpenAPI Specification. This document describes all of the operations available through the Trieve API.
5 *
6 * The version of the OpenAPI document: 0.11.7
7 * Contact: developers@trieve.ai
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`post_invitation`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum PostInvitationError {
22    Status400(models::ErrorResponseBody),
23    UnknownValue(serde_json::Value),
24}
25
26
27/// Invitations act as a way to invite users to join an organization. After a user is invited, they will automatically be added to the organization with the role specified in the invitation once they set their. Auth'ed user or api key must have an admin or owner role for the specified dataset's organization.
28pub async fn post_invitation(configuration: &configuration::Configuration, tr_organization: &str, invitation_data: models::InvitationData) -> Result<(), Error<PostInvitationError>> {
29    let local_var_configuration = configuration;
30
31    let local_var_client = &local_var_configuration.client;
32
33    let local_var_uri_str = format!("{}/api/invitation", local_var_configuration.base_path);
34    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
35
36    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
37        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
38    }
39    local_var_req_builder = local_var_req_builder.header("TR-Organization", tr_organization.to_string());
40    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
41        let local_var_key = local_var_apikey.key.clone();
42        let local_var_value = match local_var_apikey.prefix {
43            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
44            None => local_var_key,
45        };
46        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
47    };
48    local_var_req_builder = local_var_req_builder.json(&invitation_data);
49
50    let local_var_req = local_var_req_builder.build()?;
51    let local_var_resp = local_var_client.execute(local_var_req).await?;
52
53    let local_var_status = local_var_resp.status();
54    let local_var_content = local_var_resp.text().await?;
55
56    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
57        Ok(())
58    } else {
59        let local_var_entity: Option<PostInvitationError> = serde_json::from_str(&local_var_content).ok();
60        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
61        Err(Error::ResponseError(local_var_error))
62    }
63}
64