Skip to main content

agentmail/client/
api_keys.rs

1use crate::client::NoBody;
2use crate::{Client, Error, Page, types::*, util::urlish};
3
4impl Client {
5    /// POST /v0/api-keys, mint a new API key. The full secret is in
6    /// [`CreatedApiKey::api_key`] and is shown only here; store it now.
7    pub async fn create_api_key(&self, key: CreateApiKey) -> Result<CreatedApiKey, Error> {
8        self.request(reqwest::Method::POST, "/v0/api-keys", &[], Some(&key))
9            .await
10    }
11
12    /// GET /v0/api-keys (first page; see [`Client::list_api_keys_page`]).
13    pub async fn list_api_keys(&self) -> Result<ApiKeyList, Error> {
14        self.list_api_keys_page(Page::default()).await
15    }
16
17    /// GET /v0/api-keys with pagination. Feed [`ApiKeyList::next_page_token`]
18    /// back in as [`Page::page_token`] until it comes back `None`.
19    pub async fn list_api_keys_page(&self, page: Page) -> Result<ApiKeyList, Error> {
20        self.request(
21            reqwest::Method::GET,
22            "/v0/api-keys",
23            &page.query(),
24            None::<&NoBody>,
25        )
26        .await
27    }
28
29    /// DELETE /v0/api-keys/{api_key_id}
30    pub async fn delete_api_key(&self, api_key_id: &str) -> Result<(), Error> {
31        self.request(
32            reqwest::Method::DELETE,
33            &format!("/v0/api-keys/{}", urlish(api_key_id)),
34            &[],
35            None::<&NoBody>,
36        )
37        .await
38    }
39}