Skip to main content

hubspot_tickets/
basic.rs

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 `{ticketId}`. `{ticketId}` refers to the internal object ID by default, or optionally any unique property value as specified by the `idProperty` query param.  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- `id_property: Option<String>`: The name of a property whose values are unique for this object type\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- `ticket_id: &'astr` (required)\n\n```rust,no_run\nasync fn example_basic_get_crm_v_3_objects_tickets_ticket_id_get_by_id() -> anyhow::Result<()> {\n    let client = hubspot_tickets::Client::new_from_env();\n    let result: hubspot_tickets::types::SimplePublicObjectWithAssociations = client\n        .basic()\n        .get_crm_v_3_objects_tickets_ticket_id_get_by_id(\n            Some(true),\n            Some(vec![\"some-string\".to_string()]),\n            Some(\"some-string\".to_string()),\n            Some(vec![\"some-string\".to_string()]),\n            Some(vec![\"some-string\".to_string()]),\n            \"some-string\",\n        )\n        .await?;\n    println!(\"{:?}\", result);\n    Ok(())\n}\n```"]
16    #[tracing::instrument]
17    pub async fn get_crm_v_3_objects_tickets_ticket_id_get_by_id<'a>(
18        &'a self,
19        archived: Option<bool>,
20        associations: Option<Vec<String>>,
21        id_property: Option<String>,
22        properties: Option<Vec<String>>,
23        properties_with_history: Option<Vec<String>>,
24        ticket_id: &'a str,
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/tickets/{ticketId}".replace("{ticketId}", ticket_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 `{ticketId}` to the recycling \
77             bin.\n\n**Parameters:**\n\n- `ticket_id: &'astr` (required)\n\n```rust,no_run\nasync \
78             fn example_basic_delete_crm_v_3_objects_tickets_ticket_id_archive() -> \
79             anyhow::Result<()> {\n    let client = hubspot_tickets::Client::new_from_env();\n    \
80             client\n        .basic()\n        \
81             .delete_crm_v_3_objects_tickets_ticket_id_archive(\"some-string\")\n        \
82             .await?;\n    Ok(())\n}\n```"]
83    #[tracing::instrument]
84    pub async fn delete_crm_v_3_objects_tickets_ticket_id_archive<'a>(
85        &'a self,
86        ticket_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/tickets/{ticketId}".replace("{ticketId}", ticket_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 `{ticketId}`. `{ticketId}` refers to the internal object ID by default, or optionally any unique property value as specified by the `idProperty` query param. 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- `id_property: Option<String>`: The name of a property whose values are unique for this object type\n- `ticket_id: &'astr` (required)\n\n```rust,no_run\nasync fn example_basic_patch_crm_v_3_objects_tickets_ticket_id_update() -> anyhow::Result<()> {\n    let client = hubspot_tickets::Client::new_from_env();\n    let result: hubspot_tickets::types::SimplePublicObject = client\n        .basic()\n        .patch_crm_v_3_objects_tickets_ticket_id_update(\n            Some(\"some-string\".to_string()),\n            \"some-string\",\n            &hubspot_tickets::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_tickets_ticket_id_update<'a>(
113        &'a self,
114        id_property: Option<String>,
115        ticket_id: &'a str,
116        body: &crate::types::SimplePublicObjectInput,
117    ) -> Result<crate::types::SimplePublicObject, crate::types::error::Error> {
118        let mut req = self.client.client.request(
119            http::Method::PATCH,
120            format!(
121                "{}/{}",
122                self.client.base_url,
123                "crm/v3/objects/tickets/{ticketId}".replace("{ticketId}", ticket_id)
124            ),
125        );
126        req = req.bearer_auth(&self.client.token);
127        let mut query_params = vec![];
128        if let Some(p) = id_property {
129            query_params.push(("idProperty", p));
130        }
131
132        req = req.query(&query_params);
133        req = req.json(body);
134        let resp = req.send().await?;
135        let status = resp.status();
136        if status.is_success() {
137            let text = resp.text().await.unwrap_or_default();
138            serde_json::from_str(&text).map_err(|err| {
139                crate::types::error::Error::from_serde_error(
140                    format_serde_error::SerdeError::new(text.to_string(), err),
141                    status,
142                )
143            })
144        } else {
145            let text = resp.text().await.unwrap_or_default();
146            Err(crate::types::error::Error::Server {
147                body: text.to_string(),
148                status,
149            })
150        }
151    }
152
153    #[doc = "List\n\nRead a page of tickets. 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_tickets_get_page() -> anyhow::Result<()> {\n    let client = hubspot_tickets::Client::new_from_env();\n    let result: hubspot_tickets::types::CollectionResponseSimplePublicObjectWithAssociationsForwardPaging =\n        client\n            .basic()\n            .get_crm_v_3_objects_tickets_get_page(\n                Some(\"some-string\".to_string()),\n                Some(true),\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```"]
154    #[tracing::instrument]
155    pub async fn get_crm_v_3_objects_tickets_get_page<'a>(
156        &'a self,
157        after: Option<String>,
158        archived: Option<bool>,
159        associations: Option<Vec<String>>,
160        limit: Option<i32>,
161        properties: Option<Vec<String>>,
162        properties_with_history: Option<Vec<String>>,
163    ) -> Result<
164        crate::types::CollectionResponseSimplePublicObjectWithAssociationsForwardPaging,
165        crate::types::error::Error,
166    > {
167        let mut req = self.client.client.request(
168            http::Method::GET,
169            format!("{}/{}", self.client.base_url, "crm/v3/objects/tickets"),
170        );
171        req = req.bearer_auth(&self.client.token);
172        let mut query_params = vec![];
173        if let Some(p) = after {
174            query_params.push(("after", p));
175        }
176
177        if let Some(p) = archived {
178            query_params.push(("archived", format!("{}", p)));
179        }
180
181        if let Some(p) = associations {
182            query_params.push(("associations", itertools::join(p, ",")));
183        }
184
185        if let Some(p) = limit {
186            query_params.push(("limit", format!("{}", p)));
187        }
188
189        if let Some(p) = properties {
190            query_params.push(("properties", itertools::join(p, ",")));
191        }
192
193        if let Some(p) = properties_with_history {
194            query_params.push(("propertiesWithHistory", itertools::join(p, ",")));
195        }
196
197        req = req.query(&query_params);
198        let resp = req.send().await?;
199        let status = resp.status();
200        if status.is_success() {
201            let text = resp.text().await.unwrap_or_default();
202            serde_json::from_str(&text).map_err(|err| {
203                crate::types::error::Error::from_serde_error(
204                    format_serde_error::SerdeError::new(text.to_string(), err),
205                    status,
206                )
207            })
208        } else {
209            let text = resp.text().await.unwrap_or_default();
210            Err(crate::types::error::Error::Server {
211                body: text.to_string(),
212                status,
213            })
214        }
215    }
216
217    #[doc = "Create\n\nCreate a ticket with the given properties and return a copy of the object, including the ID. Documentation and examples for creating standard tickets is provided.\n\n```rust,no_run\nasync fn example_basic_post_crm_v_3_objects_tickets_create() -> anyhow::Result<()> {\n    let client = hubspot_tickets::Client::new_from_env();\n    let result: hubspot_tickets::types::SimplePublicObject = client\n        .basic()\n        .post_crm_v_3_objects_tickets_create(&hubspot_tickets::types::SimplePublicObjectInputForCreate {\n            associations: vec![hubspot_tickets::types::PublicAssociationsForObject {\n                types: vec![hubspot_tickets::types::AssociationSpec {\n                    association_category: hubspot_tickets::types::AssociationCategory::UserDefined,\n                    association_type_id: 4 as i32,\n                }],\n                to: hubspot_tickets::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```"]
218    #[tracing::instrument]
219    pub async fn post_crm_v_3_objects_tickets_create<'a>(
220        &'a self,
221        body: &crate::types::SimplePublicObjectInputForCreate,
222    ) -> Result<crate::types::SimplePublicObject, crate::types::error::Error> {
223        let mut req = self.client.client.request(
224            http::Method::POST,
225            format!("{}/{}", self.client.base_url, "crm/v3/objects/tickets"),
226        );
227        req = req.bearer_auth(&self.client.token);
228        req = req.json(body);
229        let resp = req.send().await?;
230        let status = resp.status();
231        if status.is_success() {
232            let text = resp.text().await.unwrap_or_default();
233            serde_json::from_str(&text).map_err(|err| {
234                crate::types::error::Error::from_serde_error(
235                    format_serde_error::SerdeError::new(text.to_string(), err),
236                    status,
237                )
238            })
239        } else {
240            let text = resp.text().await.unwrap_or_default();
241            Err(crate::types::error::Error::Server {
242                body: text.to_string(),
243                status,
244            })
245        }
246    }
247}