ghl-sdk 0.5.1

Unofficial async Rust SDK for the GoHighLevel (HighLevel) API 2.0 — OAuth 2.0, Private Integration Tokens, rate-limit-aware retries, paginated streams
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
// @generated by xtask/generate_services.py — do not edit by hand.
//! `associations` — typed methods for all 10 API v2 operations
//! in this module.
//!
//! Access via [`Ghl::associations`](crate::Ghl::associations).
//!
//! Request and response types come from [`ghl_models::v2::associations`](https://docs.rs/ghl-models/latest/ghl_models/v2/associations/); every endpoint is also documented in the
//! [`associations` API reference](https://github.com/Shahroz/ghl-rs/blob/main/docs/api/associations.md).
//!
//! Enable with `features = ["associations"]`.

#![allow(clippy::too_many_arguments)]

use crate::client::Ghl;
use crate::error::Result;
use ghl_models::v2::associations as models;

/// Typed access to the `associations` API v2 surface (10 operations). Obtained via
/// [`Ghl::associations`](crate::Ghl::associations).
#[derive(Debug, Clone)]
pub struct AssociationsService {
    pub(crate) client: Ghl,
}

impl AssociationsService {
    pub(crate) fn new(client: Ghl) -> Self {
        Self { client }
    }
}

/// Query parameters for
/// [`AssociationsService::get_all_associations_for_a_sub_account_location`].
#[derive(Debug, Clone, Default)]
pub struct GetAllAssociationsForASubAccountLocationParams {
    /// `locationId` query parameter.
    /// Required by the API.
    pub location_id: String,
    /// `skip` query parameter.
    /// Required by the API.
    pub skip: f64,
    /// `limit` query parameter.
    /// Required by the API.
    pub limit: f64,
}

impl GetAllAssociationsForASubAccountLocationParams {
    /// Start from the parameters the API requires.
    pub fn new(location_id: impl Into<String>, skip: f64, limit: f64) -> Self {
        Self {
            location_id: location_id.into(),
            skip,
            limit,
        }
    }

    fn to_query(&self) -> Vec<(String, String)> {
        let q: Vec<(String, String)> = vec![
            ("locationId".into(), self.location_id.clone()),
            ("skip".into(), self.skip.to_string()),
            ("limit".into(), self.limit.to_string()),
        ];
        q
    }
}

/// Query parameters for [`AssociationsService::get_association_key_by_key_name`].
#[derive(Debug, Clone, Default)]
pub struct GetAssociationKeyByKeyNameParams {
    /// `locationId` query parameter.
    /// Required by the API.
    pub location_id: String,
}

impl GetAssociationKeyByKeyNameParams {
    /// Start from the parameters the API requires.
    pub fn new(location_id: impl Into<String>) -> Self {
        Self {
            location_id: location_id.into(),
        }
    }

    fn to_query(&self) -> Vec<(String, String)> {
        let q: Vec<(String, String)> = vec![("locationId".into(), self.location_id.clone())];
        q
    }
}

/// Query parameters for [`AssociationsService::get_association_by_object_keys`].
#[derive(Debug, Clone, Default)]
pub struct GetAssociationByObjectKeysParams {
    /// `locationId` query parameter.
    pub location_id: Option<String>,
}

impl GetAssociationByObjectKeysParams {
    /// Start from the parameters the API requires.
    pub fn new() -> Self {
        Self {
            ..Default::default()
        }
    }

    /// Set the `locationId` query parameter.
    pub fn location_id(mut self, v: impl Into<String>) -> Self {
        self.location_id = Some(v.into());
        self
    }

    fn to_query(&self) -> Vec<(String, String)> {
        let mut q: Vec<(String, String)> = Vec::new();
        if let Some(v) = &self.location_id {
            q.push(("locationId".into(), v.to_string()));
        }
        q
    }
}

/// Query parameters for [`AssociationsService::get_all_relations_by_record_id`].
#[derive(Debug, Clone, Default)]
pub struct GetAllRelationsByRecordIdParams {
    /// Your Sub Account's ID
    /// Required by the API.
    pub location_id: String,
    /// `skip` query parameter.
    /// Required by the API.
    pub skip: f64,
    /// `limit` query parameter.
    /// Required by the API.
    pub limit: f64,
    /// Association Ids
    pub association_ids: Option<String>,
}

impl GetAllRelationsByRecordIdParams {
    /// Start from the parameters the API requires.
    pub fn new(location_id: impl Into<String>, skip: f64, limit: f64) -> Self {
        Self {
            location_id: location_id.into(),
            skip,
            limit,
            ..Default::default()
        }
    }

    /// Association Ids
    pub fn association_ids(mut self, v: impl Into<String>) -> Self {
        self.association_ids = Some(v.into());
        self
    }

    fn to_query(&self) -> Vec<(String, String)> {
        let mut q: Vec<(String, String)> = vec![
            ("locationId".into(), self.location_id.clone()),
            ("skip".into(), self.skip.to_string()),
            ("limit".into(), self.limit.to_string()),
        ];
        if let Some(v) = &self.association_ids {
            q.push(("associationIds".into(), v.to_string()));
        }
        q
    }
}

/// Query parameters for [`AssociationsService::delete_relation`].
#[derive(Debug, Clone, Default)]
pub struct DeleteRelationParams {
    /// Your Sub Account's ID
    /// Required by the API.
    pub location_id: String,
}

impl DeleteRelationParams {
    /// Start from the parameters the API requires.
    pub fn new(location_id: impl Into<String>) -> Self {
        Self {
            location_id: location_id.into(),
        }
    }

    fn to_query(&self) -> Vec<(String, String)> {
        let q: Vec<(String, String)> = vec![("locationId".into(), self.location_id.clone())];
        q
    }
}

impl AssociationsService {
    /// Get all associations for a sub-account / location
    ///
    /// Get all Associations
    ///
    /// `GET /associations/`
    ///
    /// Requires scope: `associations.readonly`.
    pub async fn get_all_associations_for_a_sub_account_location(
        &self,
        params: &GetAllAssociationsForASubAccountLocationParams,
    ) -> Result<models::GetPostSuccessfulResponseDto> {
        let query = params.to_query();
        self.client
            .send_versioned(
                reqwest::Method::GET,
                "/associations/",
                &query,
                None::<&()>,
                Some("2021-07-28"),
            )
            .await
    }

    /// Create Association
    ///
    /// Allow you to create contact - contact , contact - custom objects associations, will
    /// add more in the future.Documentation Link -
    /// <https://doc.clickup.com/8631005/d/h/87cpx-293776/cd0f4122abc04d3>
    ///
    /// `POST /associations/`
    ///
    /// Requires scope: `associations.write`.
    pub async fn create_association(
        &self,
        body: &models::CreateAssociationReqDto,
    ) -> Result<models::GetPostSuccessfulResponseDto> {
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::POST,
                "/associations/",
                &query,
                Some(body),
                Some("2021-07-28"),
            )
            .await
    }

    /// Get association key by key name
    ///
    /// Using this api you can get standard / user defined association by key
    ///
    /// `GET /associations/key/{key_name}`
    ///
    /// Requires scope: `associations.readonly`.
    pub async fn get_association_key_by_key_name(
        &self,
        key_name: &str,
        params: &GetAssociationKeyByKeyNameParams,
    ) -> Result<models::GetPostSuccessfulResponseDto> {
        let path = format!("/associations/key/{}", crate::services::encode(key_name));
        let query = params.to_query();
        self.client
            .send_versioned(
                reqwest::Method::GET,
                &path,
                &query,
                None::<&()>,
                Some("2021-07-28"),
            )
            .await
    }

    /// Get association by object keys
    ///
    /// Get association by object keys like contacts, custom objects and opportunities.
    /// Documentation Link -
    /// <https://doc.clickup.com/8631005/d/h/87cpx-293776/cd0f4122abc04d3>
    ///
    /// `GET /associations/objectKey/{objectKey}`
    ///
    /// Requires scope: `associations.readonly`.
    pub async fn get_association_by_object_keys(
        &self,
        object_key: &str,
        params: &GetAssociationByObjectKeysParams,
    ) -> Result<models::GetPostSuccessfulResponseDto> {
        let path = format!(
            "/associations/objectKey/{}",
            crate::services::encode(object_key)
        );
        let query = params.to_query();
        self.client
            .send_versioned(
                reqwest::Method::GET,
                &path,
                &query,
                None::<&()>,
                Some("2021-07-28"),
            )
            .await
    }

    /// Create Relation for you associated entities.
    ///
    /// Create Relation.Documentation Link -
    /// <https://doc.clickup.com/8631005/d/h/87cpx-293776/cd0f4122abc04d3>
    ///
    /// `POST /associations/relations`
    ///
    /// Requires scope: `associations/relation.write`.
    pub async fn create_relation_for_you_associated_entities(
        &self,
        body: &models::CreateRelationReqDto,
    ) -> Result<models::GetPostSuccessfulResponseDto> {
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::POST,
                "/associations/relations",
                &query,
                Some(body),
                Some("2021-07-28"),
            )
            .await
    }

    /// Get all relations By record Id
    ///
    /// Get all relations by record Id
    ///
    /// `GET /associations/relations/{recordId}`
    ///
    /// Requires scope: `associations/relation.readonly`.
    pub async fn get_all_relations_by_record_id(
        &self,
        record_id: &str,
        params: &GetAllRelationsByRecordIdParams,
    ) -> Result<models::GetPostSuccessfulResponseDto> {
        let path = format!(
            "/associations/relations/{}",
            crate::services::encode(record_id)
        );
        let query = params.to_query();
        self.client
            .send_versioned(
                reqwest::Method::GET,
                &path,
                &query,
                None::<&()>,
                Some("2021-07-28"),
            )
            .await
    }

    /// Delete Relation
    ///
    /// `DELETE /associations/relations/{relationId}`
    ///
    /// Requires scope: `associations/relation.write`.
    pub async fn delete_relation(
        &self,
        relation_id: &str,
        params: &DeleteRelationParams,
    ) -> Result<models::GetPostSuccessfulResponseDto> {
        let path = format!(
            "/associations/relations/{}",
            crate::services::encode(relation_id)
        );
        let query = params.to_query();
        self.client
            .send_versioned(
                reqwest::Method::DELETE,
                &path,
                &query,
                None::<&()>,
                Some("2021-07-28"),
            )
            .await
    }

    /// Delete Association
    ///
    /// Delete USER_DEFINED Association By Id, deleting an association will also all the
    /// relations for that association
    ///
    /// `DELETE /associations/{associationId}`
    ///
    /// Requires scope: `associations.write`.
    pub async fn delete_association(
        &self,
        association_id: &str,
    ) -> Result<models::DeleteAssociationsResponseDTO> {
        let path = format!("/associations/{}", crate::services::encode(association_id));
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::DELETE,
                &path,
                &query,
                None::<&()>,
                Some("2021-07-28"),
            )
            .await
    }

    /// Get association by ID
    ///
    /// Using this api you can get SYSTEM_DEFINED / USER_DEFINED association by id
    ///
    /// `GET /associations/{associationId}`
    ///
    /// Requires scope: `associations.readonly`.
    pub async fn get_association_by_id(
        &self,
        association_id: &str,
    ) -> Result<models::GetPostSuccessfulResponseDto> {
        let path = format!("/associations/{}", crate::services::encode(association_id));
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::GET,
                &path,
                &query,
                None::<&()>,
                Some("2021-07-28"),
            )
            .await
    }

    /// Update Association By Id
    ///
    /// Update Association , Allows you to update labels of an associations. Documentation
    /// Link - <https://doc.clickup.com/8631005/d/h/87cpx-293776/cd0f4122abc04d3>
    ///
    /// `PUT /associations/{associationId}`
    ///
    /// Requires scope: `associations.write`.
    pub async fn update_association_by_id(
        &self,
        association_id: &str,
        body: &models::UpdateAssociationReqDto,
    ) -> Result<models::GetPostSuccessfulResponseDto> {
        let path = format!("/associations/{}", crate::services::encode(association_id));
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::PUT,
                &path,
                &query,
                Some(body),
                Some("2021-07-28"),
            )
            .await
    }
}