Skip to main content

highlevel_api/apis/custom_fields/
client.rs

1use std::sync::Arc;
2use crate::{error::Result, http::HttpClient};
3use super::types::*;
4
5pub struct CustomFieldsApi {
6    http: Arc<HttpClient>,
7}
8
9impl CustomFieldsApi {
10    pub fn new(http: Arc<HttpClient>) -> Self {
11        Self { http }
12    }
13
14    pub async fn list(&self, location_id: &str) -> Result<GetCustomFieldsResponse> {
15        #[derive(serde::Serialize)]
16        struct Q<'a> {
17            #[serde(rename = "locationId")]
18            location_id: &'a str,
19        }
20        self.http
21            .get_with_query("/custom-fields", &Q { location_id })
22            .await
23    }
24
25    pub async fn get(&self, field_id: &str) -> Result<GetCustomFieldResponse> {
26        self.http.get(&format!("/custom-fields/{field_id}")).await
27    }
28
29    pub async fn create(
30        &self,
31        params: &CreateCustomFieldParams,
32    ) -> Result<GetCustomFieldResponse> {
33        self.http.post("/custom-fields", params).await
34    }
35
36    pub async fn update(
37        &self,
38        field_id: &str,
39        params: &CreateCustomFieldParams,
40    ) -> Result<GetCustomFieldResponse> {
41        self.http.put(&format!("/custom-fields/{field_id}"), params).await
42    }
43
44    pub async fn delete(&self, field_id: &str) -> Result<DeleteCustomFieldResponse> {
45        self.http.delete(&format!("/custom-fields/{field_id}")).await
46    }
47}