Skip to main content

asana_cli/api/
custom_fields.rs

1//! High level custom field operations built on the core API client.
2
3use crate::api::api_get;
4use crate::{
5    api::{ApiClient, ApiError},
6    models::CustomField,
7};
8use futures_util::{StreamExt, pin_mut};
9
10/// List custom fields in a workspace.
11///
12/// # Errors
13/// Returns [`ApiError`] if the API request fails or network errors occur.
14pub async fn list_custom_fields(
15    client: &ApiClient,
16    workspace_gid: &str,
17    limit: Option<usize>,
18) -> Result<Vec<CustomField>, ApiError> {
19    let endpoint = format!("/workspaces/{workspace_gid}/custom_fields");
20    let stream = client.paginate_with_limit::<CustomField>(&endpoint, vec![], limit);
21    pin_mut!(stream);
22
23    let mut fields = Vec::new();
24    while let Some(page) = stream.next().await {
25        let mut page = page?;
26        fields.append(&mut page);
27    }
28
29    Ok(fields)
30}
31
32/// Get a single custom field by GID.
33///
34/// # Errors
35/// Returns [`ApiError`] if the API request fails or network errors occur.
36pub async fn get_custom_field(
37    client: &ApiClient,
38    field_gid: &str,
39) -> Result<CustomField, ApiError> {
40    api_get(client, &format!("/custom_fields/{field_gid}")).await
41}