workos 3.1.0

Official Rust SDK for the WorkOS API
Documentation
// This file is auto-generated by oagen. Do not edit.

use crate::client::Client;
#[allow(unused_imports)]
use crate::enums::*;
use crate::error::Error;
#[allow(unused_imports)]
use crate::models::*;
use serde::Serialize;

pub struct AgentsApi<'a> {
    pub(crate) client: &'a Client,
}

#[derive(Debug, Clone, Serialize)]
pub struct UpdateAttemptsParams {
    /// Request body sent with this call.
    ///
    /// Required.
    #[serde(skip)]
    pub body: AgentAdminLinkClaimAttemptToExternalUserRequest,
}

impl UpdateAttemptsParams {
    /// Construct a new `UpdateAttemptsParams` with the required fields set.
    #[allow(deprecated)]
    pub fn new(body: AgentAdminLinkClaimAttemptToExternalUserRequest) -> Self {
        Self { body }
    }
}

#[derive(Debug, Clone, Serialize)]
pub struct CreateValidateParams {
    /// Request body sent with this call.
    ///
    /// Required.
    #[serde(skip)]
    pub body: AgentAdminValidateCredentialRequest,
}

impl CreateValidateParams {
    /// Construct a new `CreateValidateParams` with the required fields set.
    #[allow(deprecated)]
    pub fn new(body: AgentAdminValidateCredentialRequest) -> Self {
        Self { body }
    }
}

impl<'a> AgentsApi<'a> {
    /// Link a claim attempt to an external user
    ///
    /// Link an external user to a claim attempt and retrieve the code needed for the agent to complete the claim. The user is looked up by external ID; if no user exists, one is created. When the user belongs to multiple organizations, an explicit organization must be provided.
    pub async fn update_attempts(
        &self,
        params: UpdateAttemptsParams,
    ) -> Result<ClaimViewResponse, Error> {
        self.update_attempts_with_options(params, None).await
    }

    /// Variant of [`Self::update_attempts`] that accepts per-request [`crate::RequestOptions`].
    pub async fn update_attempts_with_options(
        &self,
        params: UpdateAttemptsParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<ClaimViewResponse, Error> {
        let path = "/agents/claims/attempts".to_string();
        let method = http::Method::PATCH;
        self.client
            .request_with_body_opts(method, &path, &params, Some(&params.body), options)
            .await
    }

    /// Validate an agent credential
    ///
    /// Validate an agent credential — an API key or access token — against the environment of the API key used to authenticate the request. This is a read-only check: it never consumes or mutates the credential.
    pub async fn create_validate(
        &self,
        params: CreateValidateParams,
    ) -> Result<AgentCredentialValidation, Error> {
        self.create_validate_with_options(params, None).await
    }

    /// Variant of [`Self::create_validate`] that accepts per-request [`crate::RequestOptions`].
    pub async fn create_validate_with_options(
        &self,
        params: CreateValidateParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<AgentCredentialValidation, Error> {
        let path = "/agents/credentials/validate".to_string();
        let method = http::Method::POST;
        self.client
            .request_with_body_opts(method, &path, &params, Some(&params.body), options)
            .await
    }

    /// Get an agent registration
    ///
    /// Retrieve the details of an agent registration by ID. The registration is scoped to the environment of the API key used to authenticate the request.
    pub async fn get_registration(&self, id: &str) -> Result<AgentRegistration, Error> {
        self.get_registration_with_options(id, None).await
    }

    /// Variant of [`Self::get_registration`] that accepts per-request [`crate::RequestOptions`].
    pub async fn get_registration_with_options(
        &self,
        id: &str,
        options: Option<&crate::RequestOptions>,
    ) -> Result<AgentRegistration, Error> {
        let id = crate::client::path_segment(id);
        let path = format!("/agents/registrations/{id}");
        let method = http::Method::GET;
        self.client
            .request_with_query_opts(method, &path, &(), options)
            .await
    }
}