Skip to main content

brevo_rust/api/resources/notes/
notes.rs

1use crate::api::*;
2use crate::{ApiError, ClientConfig, HttpClient, QueryBuilder, RequestOptions};
3use reqwest::Method;
4
5pub struct NotesClient {
6    pub http_client: HttpClient,
7}
8
9impl NotesClient {
10    pub fn new(config: ClientConfig) -> Result<Self, ApiError> {
11        Ok(Self {
12            http_client: HttpClient::new(config.clone())?,
13        })
14    }
15
16    /// Retrieve a paginated list of CRM notes with optional filtering by entity type, entity IDs, and date range. Results are sorted by creation date in descending order by default, with a default limit of 50 notes per page.
17    ///
18    /// # Arguments
19    ///
20    /// * `entity` - Filter by note entity type
21    /// * `entity_ids` - Filter by note entity IDs
22    /// * `date_from` - dateFrom to date range filter type (timestamp in milliseconds)
23    /// * `date_to` - dateTo to date range filter type (timestamp in milliseconds)
24    /// * `offset` - Index of the first document of the page
25    /// * `limit` - Number of documents per page
26    /// * `sort` - Sort the results in the ascending/descending order. Default order is **descending** by creation if `sort` is not passed
27    /// * `options` - Additional request options such as headers, timeout, etc.
28    ///
29    /// # Returns
30    ///
31    /// JSON response from the API
32    ///
33    /// # Examples
34    ///
35    /// ```no_run
36    /// use brevo_rust::prelude::*;
37    ///
38    /// #[tokio::main]
39    /// async fn main() {
40    ///     let config = ClientConfig {
41    ///         api_key: Some("<value>".to_string()),
42    ///         ..Default::default()
43    ///     };
44    ///     let client = BrevoClient::new(config).expect("Failed to build client");
45    ///     client
46    ///         .notes
47    ///         .get_all_notes(
48    ///             &GetAllNotesQueryRequest {
49    ///                 ..Default::default()
50    ///             },
51    ///             None,
52    ///         )
53    ///         .await;
54    /// }
55    /// ```
56    pub async fn get_all_notes(
57        &self,
58        request: &GetAllNotesQueryRequest,
59        options: Option<RequestOptions>,
60    ) -> Result<Vec<Note>, ApiError> {
61        self.http_client
62            .execute_request(
63                Method::GET,
64                "crm/notes",
65                None,
66                QueryBuilder::new()
67                    .serialize("entity", request.entity.clone())
68                    .string("entityIds", request.entity_ids.clone())
69                    .int("dateFrom", request.date_from.clone())
70                    .int("dateTo", request.date_to.clone())
71                    .int("offset", request.offset.clone())
72                    .int("limit", request.limit.clone())
73                    .serialize("sort", request.sort.clone())
74                    .build(),
75                options,
76            )
77            .await
78    }
79
80    /// Create a new CRM note and optionally associate it with contacts, companies, or deals. The note text content is required, and you can link the note to multiple entities simultaneously during creation.
81    ///
82    /// # Arguments
83    ///
84    /// * `options` - Additional request options such as headers, timeout, etc.
85    ///
86    /// # Returns
87    ///
88    /// JSON response from the API
89    ///
90    /// # Examples
91    ///
92    /// ```no_run
93    /// use brevo_rust::prelude::*;
94    ///
95    /// #[tokio::main]
96    /// async fn main() {
97    ///     let config = ClientConfig {
98    ///         api_key: Some("<value>".to_string()),
99    ///         ..Default::default()
100    ///     };
101    ///     let client = BrevoClient::new(config).expect("Failed to build client");
102    ///     client.notes.create_a_note(&NoteData {
103    ///         text: "<p>Meeting notes: <b>Action item</b> - visit <a href=\"https://www.brevo.com/\">Brevo</a> for details.</p>".to_string(),
104    ///         ..Default::default()
105    ///     }, None).await;
106    /// }
107    /// ```
108    pub async fn create_a_note(
109        &self,
110        request: &NoteData,
111        options: Option<RequestOptions>,
112    ) -> Result<PostCrmNotesResponse, ApiError> {
113        self.http_client
114            .execute_request(
115                Method::POST,
116                "crm/notes",
117                Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
118                None,
119                options,
120            )
121            .await
122    }
123
124    /// Retrieve the full details of a single CRM note by its identifier. The response includes the note''s text content, creation date, author, and any associated contacts, companies, or deals.
125    ///
126    /// # Arguments
127    ///
128    /// * `id` - Note ID to get
129    /// * `options` - Additional request options such as headers, timeout, etc.
130    ///
131    /// # Returns
132    ///
133    /// JSON response from the API
134    ///
135    /// # Examples
136    ///
137    /// ```no_run
138    /// use brevo_rust::prelude::*;
139    ///
140    /// #[tokio::main]
141    /// async fn main() {
142    ///     let config = ClientConfig {
143    ///         api_key: Some("<value>".to_string()),
144    ///         ..Default::default()
145    ///     };
146    ///     let client = BrevoClient::new(config).expect("Failed to build client");
147    ///     client.notes.get_a_note(&"id".to_string(), None).await;
148    /// }
149    /// ```
150    pub async fn get_a_note(
151        &self,
152        id: &str,
153        options: Option<RequestOptions>,
154    ) -> Result<Note, ApiError> {
155        self.http_client
156            .execute_request(
157                Method::GET,
158                &format!("crm/notes/{}", id),
159                None,
160                None,
161                options,
162            )
163            .await
164    }
165
166    /// Permanently delete a CRM note by its identifier. This removes the note and unlinks it from any associated contacts, companies, or deals.
167    ///
168    /// # Arguments
169    ///
170    /// * `id` - Note ID to delete
171    /// * `options` - Additional request options such as headers, timeout, etc.
172    ///
173    /// # Returns
174    ///
175    /// Empty response
176    ///
177    /// # Examples
178    ///
179    /// ```no_run
180    /// use brevo_rust::prelude::*;
181    ///
182    /// #[tokio::main]
183    /// async fn main() {
184    ///     let config = ClientConfig {
185    ///         api_key: Some("<value>".to_string()),
186    ///         ..Default::default()
187    ///     };
188    ///     let client = BrevoClient::new(config).expect("Failed to build client");
189    ///     client.notes.delete_a_note(&"id".to_string(), None).await;
190    /// }
191    /// ```
192    pub async fn delete_a_note(
193        &self,
194        id: &str,
195        options: Option<RequestOptions>,
196    ) -> Result<(), ApiError> {
197        self.http_client
198            .execute_request(
199                Method::DELETE,
200                &format!("crm/notes/{}", id),
201                None,
202                None,
203                options,
204            )
205            .await
206    }
207
208    /// Update an existing CRM note''s text content and its associations with contacts, companies, or deals. You can modify the note text, change the pinned status, or update the linked entities.
209    ///
210    /// # Arguments
211    ///
212    /// * `id` - Note ID to update
213    /// * `options` - Additional request options such as headers, timeout, etc.
214    ///
215    /// # Returns
216    ///
217    /// Empty response
218    ///
219    /// # Examples
220    ///
221    /// ```no_run
222    /// use brevo_rust::prelude::*;
223    ///
224    /// #[tokio::main]
225    /// async fn main() {
226    ///     let config = ClientConfig {
227    ///         api_key: Some("<value>".to_string()),
228    ///         ..Default::default()
229    ///     };
230    ///     let client = BrevoClient::new(config).expect("Failed to build client");
231    ///     client.notes.update_a_note(&"id".to_string(), &NoteData {
232    ///         text: "<p>Meeting notes: <b>Action item</b> - visit <a href=\"https://www.brevo.com/\">Brevo</a> for details.</p>".to_string(),
233    ///         ..Default::default()
234    ///     }, None).await;
235    /// }
236    /// ```
237    pub async fn update_a_note(
238        &self,
239        id: &str,
240        request: &NoteData,
241        options: Option<RequestOptions>,
242    ) -> Result<(), ApiError> {
243        self.http_client
244            .execute_request(
245                Method::PATCH,
246                &format!("crm/notes/{}", id),
247                Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
248                None,
249                options,
250            )
251            .await
252    }
253}