1use anyhow::Result;
2
3use crate::Client;
4#[derive(Clone, Debug)]
5pub struct Basic {
6 pub client: Client,
7}
8
9impl Basic {
10 #[doc(hidden)]
11 pub fn new(client: Client) -> Self {
12 Self { client }
13 }
14
15 #[doc = "Read\n\nRead an Object identified by `{contactId}`. `{contactId}` refers to the internal object ID. Control what is returned via the `properties` query param.\n\n**Parameters:**\n\n- `archived: Option<bool>`: Whether to return only results that have been archived.\n- `associations: Option<Vec<String>>`: A comma separated list of object types to retrieve associated IDs for. If any of the specified associations do not exist, they will be ignored.\n- `contact_id: &'astr` (required)\n- `id_property: Option<String>`: What id property to query, could be id or email\n- `properties: Option<Vec<String>>`: A comma separated list of the properties to be returned in the response. If any of the specified properties are not present on the requested object(s), they will be ignored.\n- `properties_with_history: Option<Vec<String>>`: A comma separated list of the properties to be returned along with their history of previous values. If any of the specified properties are not present on the requested object(s), they will be ignored.\n\n```rust,no_run\nasync fn example_basic_get_crm_v_3_objects_contacts_contact_id_get_by_id() -> anyhow::Result<()> {\n let client = hubspot_contacts::Client::new_from_env();\n let result: hubspot_contacts::types::SimplePublicObjectWithAssociations = client\n .basic()\n .get_crm_v_3_objects_contacts_contact_id_get_by_id(\n Some(false),\n Some(vec![\"some-string\".to_string()]),\n \"some-string\",\n Some(\"some-string\".to_string()),\n Some(vec![\"some-string\".to_string()]),\n Some(vec![\"some-string\".to_string()]),\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
16 #[tracing::instrument]
17 pub async fn get_crm_v_3_objects_contacts_contact_id_get_by_id<'a>(
18 &'a self,
19 archived: Option<bool>,
20 associations: Option<Vec<String>>,
21 contact_id: &'a str,
22 id_property: Option<String>,
23 properties: Option<Vec<String>>,
24 properties_with_history: Option<Vec<String>>,
25 ) -> Result<crate::types::SimplePublicObjectWithAssociations, crate::types::error::Error> {
26 let mut req = self.client.client.request(
27 http::Method::GET,
28 format!(
29 "{}/{}",
30 self.client.base_url,
31 "crm/v3/objects/contacts/{contactId}".replace("{contactId}", contact_id)
32 ),
33 );
34 req = req.bearer_auth(&self.client.token);
35 let mut query_params = vec![];
36 if let Some(p) = archived {
37 query_params.push(("archived", format!("{}", p)));
38 }
39
40 if let Some(p) = associations {
41 query_params.push(("associations", itertools::join(p, ",")));
42 }
43
44 if let Some(p) = id_property {
45 query_params.push(("idProperty", p));
46 }
47
48 if let Some(p) = properties {
49 query_params.push(("properties", itertools::join(p, ",")));
50 }
51
52 if let Some(p) = properties_with_history {
53 query_params.push(("propertiesWithHistory", itertools::join(p, ",")));
54 }
55
56 req = req.query(&query_params);
57 let resp = req.send().await?;
58 let status = resp.status();
59 if status.is_success() {
60 let text = resp.text().await.unwrap_or_default();
61 serde_json::from_str(&text).map_err(|err| {
62 crate::types::error::Error::from_serde_error(
63 format_serde_error::SerdeError::new(text.to_string(), err),
64 status,
65 )
66 })
67 } else {
68 let text = resp.text().await.unwrap_or_default();
69 Err(crate::types::error::Error::Server {
70 body: text.to_string(),
71 status,
72 })
73 }
74 }
75
76 #[doc = "Archive\n\nMove an Object identified by `{contactId}` to the recycling \
77 bin.\n\n**Parameters:**\n\n- `contact_id: &'astr` (required)\n\n```rust,no_run\nasync \
78 fn example_basic_delete_crm_v_3_objects_contacts_contact_id_archive() -> \
79 anyhow::Result<()> {\n let client = hubspot_contacts::Client::new_from_env();\n \
80 client\n .basic()\n \
81 .delete_crm_v_3_objects_contacts_contact_id_archive(\"some-string\")\n \
82 .await?;\n Ok(())\n}\n```"]
83 #[tracing::instrument]
84 pub async fn delete_crm_v_3_objects_contacts_contact_id_archive<'a>(
85 &'a self,
86 contact_id: &'a str,
87 ) -> Result<(), crate::types::error::Error> {
88 let mut req = self.client.client.request(
89 http::Method::DELETE,
90 format!(
91 "{}/{}",
92 self.client.base_url,
93 "crm/v3/objects/contacts/{contactId}".replace("{contactId}", contact_id)
94 ),
95 );
96 req = req.bearer_auth(&self.client.token);
97 let resp = req.send().await?;
98 let status = resp.status();
99 if status.is_success() {
100 Ok(())
101 } else {
102 let text = resp.text().await.unwrap_or_default();
103 Err(crate::types::error::Error::Server {
104 body: text.to_string(),
105 status,
106 })
107 }
108 }
109
110 #[doc = "Update\n\nPerform a partial update of an Object identified by `{contactId}`. `{contactId}` refers to the internal object ID. Provided property values will be overwritten. Read-only and non-existent properties will be ignored. Properties values can be cleared by passing an empty string.\n\n**Parameters:**\n\n- `contact_id: &'astr` (required)\n\n```rust,no_run\nasync fn example_basic_patch_crm_v_3_objects_contacts_contact_id_update() -> anyhow::Result<()> {\n let client = hubspot_contacts::Client::new_from_env();\n let result: hubspot_contacts::types::SimplePublicObject = client\n .basic()\n .patch_crm_v_3_objects_contacts_contact_id_update(\n \"some-string\",\n &hubspot_contacts::types::SimplePublicObjectInput {\n properties: std::collections::HashMap::from([(\n \"some-key\".to_string(),\n \"some-string\".to_string(),\n )]),\n },\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
111 #[tracing::instrument]
112 pub async fn patch_crm_v_3_objects_contacts_contact_id_update<'a>(
113 &'a self,
114 contact_id: &'a str,
115 body: &crate::types::SimplePublicObjectInput,
116 ) -> Result<crate::types::SimplePublicObject, crate::types::error::Error> {
117 let mut req = self.client.client.request(
118 http::Method::PATCH,
119 format!(
120 "{}/{}",
121 self.client.base_url,
122 "crm/v3/objects/contacts/{contactId}".replace("{contactId}", contact_id)
123 ),
124 );
125 req = req.bearer_auth(&self.client.token);
126 req = req.json(body);
127 let resp = req.send().await?;
128 let status = resp.status();
129 if status.is_success() {
130 let text = resp.text().await.unwrap_or_default();
131 serde_json::from_str(&text).map_err(|err| {
132 crate::types::error::Error::from_serde_error(
133 format_serde_error::SerdeError::new(text.to_string(), err),
134 status,
135 )
136 })
137 } else {
138 let text = resp.text().await.unwrap_or_default();
139 Err(crate::types::error::Error::Server {
140 body: text.to_string(),
141 status,
142 })
143 }
144 }
145
146 #[doc = "List\n\nRead a page of contacts. Control what is returned via the `properties` query param.\n\n**Parameters:**\n\n- `after: Option<String>`: The paging cursor token of the last successfully read resource will be returned as the `paging.next.after` JSON property of a paged response containing more results.\n- `archived: Option<bool>`: Whether to return only results that have been archived.\n- `associations: Option<Vec<String>>`: A comma separated list of object types to retrieve associated IDs for. If any of the specified associations do not exist, they will be ignored.\n- `limit: Option<i32>`: The maximum number of results to display per page.\n- `properties: Option<Vec<String>>`: A comma separated list of the properties to be returned in the response. If any of the specified properties are not present on the requested object(s), they will be ignored.\n- `properties_with_history: Option<Vec<String>>`: A comma separated list of the properties to be returned along with their history of previous values. If any of the specified properties are not present on the requested object(s), they will be ignored. Usage of this parameter will reduce the maximum number of objects that can be read by a single request.\n\n```rust,no_run\nasync fn example_basic_get_crm_v_3_objects_contacts_get_page() -> anyhow::Result<()> {\n let client = hubspot_contacts::Client::new_from_env();\n let result: hubspot_contacts::types::CollectionResponseSimplePublicObjectWithAssociationsForwardPaging =\n client\n .basic()\n .get_crm_v_3_objects_contacts_get_page(\n Some(\"some-string\".to_string()),\n Some(false),\n Some(vec![\"some-string\".to_string()]),\n Some(4 as i32),\n Some(vec![\"some-string\".to_string()]),\n Some(vec![\"some-string\".to_string()]),\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
147 #[tracing::instrument]
148 pub async fn get_crm_v_3_objects_contacts_get_page<'a>(
149 &'a self,
150 after: Option<String>,
151 archived: Option<bool>,
152 associations: Option<Vec<String>>,
153 limit: Option<i32>,
154 properties: Option<Vec<String>>,
155 properties_with_history: Option<Vec<String>>,
156 ) -> Result<
157 crate::types::CollectionResponseSimplePublicObjectWithAssociationsForwardPaging,
158 crate::types::error::Error,
159 > {
160 let mut req = self.client.client.request(
161 http::Method::GET,
162 format!("{}/{}", self.client.base_url, "crm/v3/objects/contacts"),
163 );
164 req = req.bearer_auth(&self.client.token);
165 let mut query_params = vec![];
166 if let Some(p) = after {
167 query_params.push(("after", p));
168 }
169
170 if let Some(p) = archived {
171 query_params.push(("archived", format!("{}", p)));
172 }
173
174 if let Some(p) = associations {
175 query_params.push(("associations", itertools::join(p, ",")));
176 }
177
178 if let Some(p) = limit {
179 query_params.push(("limit", format!("{}", p)));
180 }
181
182 if let Some(p) = properties {
183 query_params.push(("properties", itertools::join(p, ",")));
184 }
185
186 if let Some(p) = properties_with_history {
187 query_params.push(("propertiesWithHistory", itertools::join(p, ",")));
188 }
189
190 req = req.query(&query_params);
191 let resp = req.send().await?;
192 let status = resp.status();
193 if status.is_success() {
194 let text = resp.text().await.unwrap_or_default();
195 serde_json::from_str(&text).map_err(|err| {
196 crate::types::error::Error::from_serde_error(
197 format_serde_error::SerdeError::new(text.to_string(), err),
198 status,
199 )
200 })
201 } else {
202 let text = resp.text().await.unwrap_or_default();
203 Err(crate::types::error::Error::Server {
204 body: text.to_string(),
205 status,
206 })
207 }
208 }
209
210 #[doc = "Create\n\nCreate a contact with the given properties and return a copy of the object, including the ID. Documentation and examples for creating standard contacts is provided.\n\n```rust,no_run\nasync fn example_basic_post_crm_v_3_objects_contacts_create() -> anyhow::Result<()> {\n let client = hubspot_contacts::Client::new_from_env();\n let result: hubspot_contacts::types::SimplePublicObject = client\n .basic()\n .post_crm_v_3_objects_contacts_create(&hubspot_contacts::types::SimplePublicObjectInputForCreate {\n associations: vec![hubspot_contacts::types::PublicAssociationsForObject {\n types: vec![hubspot_contacts::types::AssociationSpec {\n association_category: hubspot_contacts::types::AssociationCategory::IntegratorDefined,\n association_type_id: 4 as i32,\n }],\n to: hubspot_contacts::types::PublicObjectId {\n id: \"some-string\".to_string(),\n },\n }],\n properties: std::collections::HashMap::from([(\n \"some-key\".to_string(),\n \"some-string\".to_string(),\n )]),\n })\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
211 #[tracing::instrument]
212 pub async fn post_crm_v_3_objects_contacts_create<'a>(
213 &'a self,
214 body: &crate::types::SimplePublicObjectInputForCreate,
215 ) -> Result<crate::types::SimplePublicObject, crate::types::error::Error> {
216 let mut req = self.client.client.request(
217 http::Method::POST,
218 format!("{}/{}", self.client.base_url, "crm/v3/objects/contacts"),
219 );
220 req = req.bearer_auth(&self.client.token);
221 req = req.json(body);
222 let resp = req.send().await?;
223 let status = resp.status();
224 if status.is_success() {
225 let text = resp.text().await.unwrap_or_default();
226 serde_json::from_str(&text).map_err(|err| {
227 crate::types::error::Error::from_serde_error(
228 format_serde_error::SerdeError::new(text.to_string(), err),
229 status,
230 )
231 })
232 } else {
233 let text = resp.text().await.unwrap_or_default();
234 Err(crate::types::error::Error::Server {
235 body: text.to_string(),
236 status,
237 })
238 }
239 }
240}