Skip to main content

highlevel_api/apis/associations/
client.rs

1use super::types::*;
2use crate::{error::Result, http::HttpClient};
3use std::sync::Arc;
4
5pub struct AssociationsApi {
6    http: Arc<HttpClient>,
7}
8
9impl AssociationsApi {
10    pub fn new(http: Arc<HttpClient>) -> Self {
11        Self { http }
12    }
13
14    // ── Associations ─────────────────────────────────────────────────────────
15
16    pub async fn list(&self) -> Result<ListAssociationsResponse> {
17        self.http.get("/associations/").await
18    }
19
20    pub async fn get(&self, association_id: &str) -> Result<GetAssociationResponse> {
21        self.http
22            .get(&format!("/associations/{association_id}"))
23            .await
24    }
25
26    pub async fn create(&self, params: &CreateAssociationParams) -> Result<GetAssociationResponse> {
27        self.http.post("/associations/", params).await
28    }
29
30    pub async fn delete(&self, association_id: &str) -> Result<serde_json::Value> {
31        self.http
32            .delete(&format!("/associations/{association_id}"))
33            .await
34    }
35
36    // ── Relations ────────────────────────────────────────────────────────────
37
38    /// Create a relation between two records using an existing association type.
39    /// No batching — call this per record pair.
40    pub async fn create_relation(
41        &self,
42        params: &CreateRelationParams,
43    ) -> Result<GetRelationResponse> {
44        self.http.post("/associations/relations", params).await
45    }
46
47    pub async fn list_relations(&self, association_id: &str) -> Result<ListRelationsResponse> {
48        self.http
49            .get(&format!("/associations/{association_id}/relations"))
50            .await
51    }
52
53    pub async fn delete_relation(&self, relation_id: &str) -> Result<serde_json::Value> {
54        self.http
55            .delete(&format!("/associations/relations/{relation_id}"))
56            .await
57    }
58}