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
// @generated by xtask/generate_services.py — do not edit by hand.
//! `objects` — typed methods for all 9 API v2 operations
//! in this module.
//!
//! Access via [`Ghl::objects`](crate::Ghl::objects).
//!
//! Request and response types come from [`ghl_models::v2::objects`](https://docs.rs/ghl-models/latest/ghl_models/v2/objects/); every endpoint is also documented in the
//! [`objects` API reference](https://github.com/Shahroz/ghl-rs/blob/main/docs/api/objects.md).
//!
//! Enable with `features = ["objects"]`.
#![allow(clippy::too_many_arguments)]
use crate::client::Ghl;
use crate::error::Result;
use ghl_models::v2::objects as models;
/// Typed access to the `objects` API v2 surface (9 operations). Obtained via
/// [`Ghl::objects`](crate::Ghl::objects).
#[derive(Debug, Clone)]
pub struct ObjectsService {
pub(crate) client: Ghl,
}
impl ObjectsService {
pub(crate) fn new(client: Ghl) -> Self {
Self { client }
}
}
/// Query parameters for [`ObjectsService::get_all_objects_for_a_location`].
#[derive(Debug, Clone, Default)]
pub struct GetAllObjectsForALocationParams {
/// location id
/// Required by the API.
pub location_id: String,
}
impl GetAllObjectsForALocationParams {
/// 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 [`ObjectsService::get_object_schema_by_key_id`].
#[derive(Debug, Clone, Default)]
pub struct GetObjectSchemaByKeyIdParams {
/// location id of the sub account
/// Required by the API.
pub location_id: String,
/// Fetch Properties , Fetches all the standard / custom fields of the object when set
/// to true
pub fetch_properties: Option<String>,
}
impl GetObjectSchemaByKeyIdParams {
/// Start from the parameters the API requires.
pub fn new(location_id: impl Into<String>) -> Self {
Self {
location_id: location_id.into(),
..Default::default()
}
}
/// Fetch Properties , Fetches all the standard / custom fields of the object when set
/// to true
pub fn fetch_properties(mut self, v: impl Into<String>) -> Self {
self.fetch_properties = Some(v.into());
self
}
fn to_query(&self) -> Vec<(String, String)> {
let mut q: Vec<(String, String)> = vec![("locationId".into(), self.location_id.clone())];
if let Some(v) = &self.fetch_properties {
q.push(("fetchProperties".into(), v.to_string()));
}
q
}
}
/// Query parameters for [`ObjectsService::update_record`].
#[derive(Debug, Clone, Default)]
pub struct UpdateRecordParams {
/// `locationId` query parameter.
/// Required by the API.
pub location_id: String,
}
impl UpdateRecordParams {
/// 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 ObjectsService {
/// Get all objects for a location
///
/// Get all objects for a location. Supported Objects are contact, opportunity, business
/// and custom objects.To understand objects and records, please have a look at the
/// documentation here :
/// <https://doc.clickup.com/8631005/d/h/87cpx-277156/93bf0c2e23177b0>
///
/// `GET /objects/`
///
/// Requires scope: `objects/schema.readonly`.
pub async fn get_all_objects_for_a_location(
&self,
params: &GetAllObjectsForALocationParams,
) -> Result<models::CustomObjectListResponseDTO> {
let query = params.to_query();
self.client
.send_versioned(
reqwest::Method::GET,
"/objects/",
&query,
None::<&()>,
Some("2021-07-28"),
)
.await
}
/// Create Custom Object
///
/// Allows you to create a custom object schema. To understand objects and records,
/// please have a look at the documentation here :
/// <https://doc.clickup.com/8631005/d/h/87cpx-277156/93bf0c2e23177b0>
///
/// `POST /objects/`
///
/// Requires scope: `objects/schema.write`.
pub async fn create_custom_object(
&self,
body: &models::CreateCustomObjectSchemaDTO,
) -> Result<models::CustomObjectResponseDTO> {
let query = Vec::new();
self.client
.send_versioned(
reqwest::Method::POST,
"/objects/",
&query,
Some(body),
Some("2021-07-28"),
)
.await
}
/// Get Object Schema by key / id
///
/// Retrieve Object Schema by key or ID. This will return the schema of the custom
/// object, including all its fields and properties. Supported objects include contact,
/// opportunity, business and custom objects.To understand objects and records, please
/// have a look the documentation here :
/// <https://doc.clickup.com/8631005/d/h/87cpx-277156/93bf0c2e23177b0>
///
/// `GET /objects/{key}`
///
/// Requires scope: `objects/schema.readonly`.
pub async fn get_object_schema_by_key_id(
&self,
key: &str,
params: &GetObjectSchemaByKeyIdParams,
) -> Result<models::CustomObjectByIdResponseDTO> {
let path = format!("/objects/{}", crate::services::encode(key));
let query = params.to_query();
self.client
.send_versioned(
reqwest::Method::GET,
&path,
&query,
None::<&()>,
Some("2021-07-28"),
)
.await
}
/// Update Object Schema By Key / Id
///
/// Update Custom Object Schema or standard object's like contact, opportunity, business
/// searchable fields. To understand objects and records, please have a look at the
/// documentation here :
/// <https://doc.clickup.com/8631005/d/h/87cpx-277156/93bf0c2e23177b0>
///
/// `PUT /objects/{key}`
///
/// Requires scope: `objects/schema.write`.
pub async fn update_object_schema_by_key_id(
&self,
key: &str,
body: &models::UpdateCustomObjectSchemaDTO,
) -> Result<models::CustomObjectResponseDTO> {
let path = format!("/objects/{}", crate::services::encode(key));
let query = Vec::new();
self.client
.send_versioned(
reqwest::Method::PUT,
&path,
&query,
Some(body),
Some("2021-07-28"),
)
.await
}
/// Create Record
///
/// Create a Custom Object Record. Supported Objects business and custom objects.
/// Documentation Link -
/// <https://doc.clickup.com/8631005/d/h/87cpx-277156/93bf0c2e23177b0/87cpx-376296>
///
/// `POST /objects/{schemaKey}/records`
///
/// Requires scope: `objects/record.write`.
pub async fn create_record(
&self,
schema_key: &str,
body: &models::CreateCustomObjectRecordDto,
) -> Result<models::RecordByIdResponseDTO> {
let path = format!("/objects/{}/records", crate::services::encode(schema_key));
let query = Vec::new();
self.client
.send_versioned(
reqwest::Method::POST,
&path,
&query,
Some(body),
Some("2021-07-28"),
)
.await
}
/// Search Object Records
///
/// Supported Objects are custom objects and standard objects like "business".
/// Documentation Link -
/// <https://doc.clickup.com/8631005/d/h/87cpx-277156/93bf0c2e23177b0/87cpx-379336>
///
/// `POST /objects/{schemaKey}/records/search`
///
/// Requires scope: `objects/record.readonly`.
pub async fn search_object_records(
&self,
schema_key: &str,
body: &models::SearchRecordsBody,
) -> Result<models::SearchRecordResponseDTO> {
let path = format!(
"/objects/{}/records/search",
crate::services::encode(schema_key)
);
let query = Vec::new();
self.client
.send_versioned(
reqwest::Method::POST,
&path,
&query,
Some(body),
Some("2021-07-28"),
)
.await
}
/// Delete Record
///
/// Delete Record By Id . Supported Objects are business and custom objects.
///
/// `DELETE /objects/{schemaKey}/records/{id}`
pub async fn delete_record(
&self,
schema_key: &str,
id: &str,
) -> Result<models::ObjectRecordDeleteResponseDTO> {
let path = format!(
"/objects/{}/records/{}",
crate::services::encode(schema_key),
crate::services::encode(id)
);
let query = Vec::new();
self.client
.send_versioned(
reqwest::Method::DELETE,
&path,
&query,
None::<&()>,
Some("2021-07-28"),
)
.await
}
/// Get Record By Id
///
/// Allows you to get a Standard Object like business and custom object record by Id
///
/// `GET /objects/{schemaKey}/records/{id}`
pub async fn get_record_by_id(
&self,
schema_key: &str,
id: &str,
) -> Result<models::RecordByIdResponseDTO> {
let path = format!(
"/objects/{}/records/{}",
crate::services::encode(schema_key),
crate::services::encode(id)
);
let query = Vec::new();
self.client
.send_versioned(
reqwest::Method::GET,
&path,
&query,
None::<&()>,
Some("2021-07-28"),
)
.await
}
/// Update Record
///
/// Update a Custom Object Record by Id. Supported Objects are business and custom
/// objects. Documentation Link -
/// <https://doc.clickup.com/8631005/d/h/87cpx-277156/93bf0c2e23177b0/87cpx-376296>
///
/// `PUT /objects/{schemaKey}/records/{id}`
pub async fn update_record(
&self,
schema_key: &str,
id: &str,
params: &UpdateRecordParams,
body: &models::UpdateCustomObjectRecordDto,
) -> Result<models::RecordByIdResponseDTO> {
let path = format!(
"/objects/{}/records/{}",
crate::services::encode(schema_key),
crate::services::encode(id)
);
let query = params.to_query();
self.client
.send_versioned(
reqwest::Method::PUT,
&path,
&query,
Some(body),
Some("2021-07-28"),
)
.await
}
}