datadog_api_client/datadogV2/api/
api_actions_datastores.rs

1// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2// This product includes software developed at Datadog (https://www.datadoghq.com/).
3// Copyright 2019-Present Datadog, Inc.
4use crate::datadog;
5use flate2::{
6    write::{GzEncoder, ZlibEncoder},
7    Compression,
8};
9use reqwest::header::{HeaderMap, HeaderValue};
10use serde::{Deserialize, Serialize};
11use std::io::Write;
12
13/// ListDatastoreItemsOptionalParams is a struct for passing parameters to the method [`ActionsDatastoresAPI::list_datastore_items`]
14#[non_exhaustive]
15#[derive(Clone, Default, Debug)]
16pub struct ListDatastoreItemsOptionalParams {
17    /// Optional query filter to search items using the [logs search syntax](<https://docs.datadoghq.com/logs/explorer/search_syntax/>).
18    pub filter: Option<String>,
19    /// Optional primary key value to retrieve a specific item. Cannot be used together with the filter parameter.
20    pub item_key: Option<String>,
21    /// Optional field to limit the number of items to return per page for pagination. Up to 100 items can be returned per page.
22    pub page_limit: Option<i64>,
23    /// Optional field to offset the number of items to skip from the beginning of the result set for pagination.
24    pub page_offset: Option<i64>,
25    /// Optional field to sort results by. Prefix with '-' for descending order (e.g., '-created_at').
26    pub sort: Option<String>,
27}
28
29impl ListDatastoreItemsOptionalParams {
30    /// Optional query filter to search items using the [logs search syntax](<https://docs.datadoghq.com/logs/explorer/search_syntax/>).
31    pub fn filter(mut self, value: String) -> Self {
32        self.filter = Some(value);
33        self
34    }
35    /// Optional primary key value to retrieve a specific item. Cannot be used together with the filter parameter.
36    pub fn item_key(mut self, value: String) -> Self {
37        self.item_key = Some(value);
38        self
39    }
40    /// Optional field to limit the number of items to return per page for pagination. Up to 100 items can be returned per page.
41    pub fn page_limit(mut self, value: i64) -> Self {
42        self.page_limit = Some(value);
43        self
44    }
45    /// Optional field to offset the number of items to skip from the beginning of the result set for pagination.
46    pub fn page_offset(mut self, value: i64) -> Self {
47        self.page_offset = Some(value);
48        self
49    }
50    /// Optional field to sort results by. Prefix with '-' for descending order (e.g., '-created_at').
51    pub fn sort(mut self, value: String) -> Self {
52        self.sort = Some(value);
53        self
54    }
55}
56
57/// BulkWriteDatastoreItemsError is a struct for typed errors of method [`ActionsDatastoresAPI::bulk_write_datastore_items`]
58#[derive(Debug, Clone, Serialize, Deserialize)]
59#[serde(untagged)]
60pub enum BulkWriteDatastoreItemsError {
61    JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
62    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
63    UnknownValue(serde_json::Value),
64}
65
66/// CreateDatastoreError is a struct for typed errors of method [`ActionsDatastoresAPI::create_datastore`]
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum CreateDatastoreError {
70    JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
71    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
72    UnknownValue(serde_json::Value),
73}
74
75/// DeleteDatastoreError is a struct for typed errors of method [`ActionsDatastoresAPI::delete_datastore`]
76#[derive(Debug, Clone, Serialize, Deserialize)]
77#[serde(untagged)]
78pub enum DeleteDatastoreError {
79    JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
80    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
81    UnknownValue(serde_json::Value),
82}
83
84/// DeleteDatastoreItemError is a struct for typed errors of method [`ActionsDatastoresAPI::delete_datastore_item`]
85#[derive(Debug, Clone, Serialize, Deserialize)]
86#[serde(untagged)]
87pub enum DeleteDatastoreItemError {
88    JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
89    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
90    UnknownValue(serde_json::Value),
91}
92
93/// GetDatastoreError is a struct for typed errors of method [`ActionsDatastoresAPI::get_datastore`]
94#[derive(Debug, Clone, Serialize, Deserialize)]
95#[serde(untagged)]
96pub enum GetDatastoreError {
97    JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
98    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
99    UnknownValue(serde_json::Value),
100}
101
102/// ListDatastoreItemsError is a struct for typed errors of method [`ActionsDatastoresAPI::list_datastore_items`]
103#[derive(Debug, Clone, Serialize, Deserialize)]
104#[serde(untagged)]
105pub enum ListDatastoreItemsError {
106    JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
107    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
108    UnknownValue(serde_json::Value),
109}
110
111/// ListDatastoresError is a struct for typed errors of method [`ActionsDatastoresAPI::list_datastores`]
112#[derive(Debug, Clone, Serialize, Deserialize)]
113#[serde(untagged)]
114pub enum ListDatastoresError {
115    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
116    UnknownValue(serde_json::Value),
117}
118
119/// UpdateDatastoreError is a struct for typed errors of method [`ActionsDatastoresAPI::update_datastore`]
120#[derive(Debug, Clone, Serialize, Deserialize)]
121#[serde(untagged)]
122pub enum UpdateDatastoreError {
123    JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
124    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
125    UnknownValue(serde_json::Value),
126}
127
128/// UpdateDatastoreItemError is a struct for typed errors of method [`ActionsDatastoresAPI::update_datastore_item`]
129#[derive(Debug, Clone, Serialize, Deserialize)]
130#[serde(untagged)]
131pub enum UpdateDatastoreItemError {
132    JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
133    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
134    UnknownValue(serde_json::Value),
135}
136
137/// Leverage the Actions Datastore API to create, modify, and delete
138/// items in datastores owned by your organization.
139#[derive(Debug, Clone)]
140pub struct ActionsDatastoresAPI {
141    config: datadog::Configuration,
142    client: reqwest_middleware::ClientWithMiddleware,
143}
144
145impl Default for ActionsDatastoresAPI {
146    fn default() -> Self {
147        Self::with_config(datadog::Configuration::default())
148    }
149}
150
151impl ActionsDatastoresAPI {
152    pub fn new() -> Self {
153        Self::default()
154    }
155    pub fn with_config(config: datadog::Configuration) -> Self {
156        let mut reqwest_client_builder = reqwest::Client::builder();
157
158        if let Some(proxy_url) = &config.proxy_url {
159            let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
160            reqwest_client_builder = reqwest_client_builder.proxy(proxy);
161        }
162
163        let mut middleware_client_builder =
164            reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
165
166        if config.enable_retry {
167            struct RetryableStatus;
168            impl reqwest_retry::RetryableStrategy for RetryableStatus {
169                fn handle(
170                    &self,
171                    res: &Result<reqwest::Response, reqwest_middleware::Error>,
172                ) -> Option<reqwest_retry::Retryable> {
173                    match res {
174                        Ok(success) => reqwest_retry::default_on_request_success(success),
175                        Err(_) => None,
176                    }
177                }
178            }
179            let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
180                .build_with_max_retries(config.max_retries);
181
182            let retry_middleware =
183                reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
184                    backoff_policy,
185                    RetryableStatus,
186                );
187
188            middleware_client_builder = middleware_client_builder.with(retry_middleware);
189        }
190
191        let client = middleware_client_builder.build();
192
193        Self { config, client }
194    }
195
196    pub fn with_client_and_config(
197        config: datadog::Configuration,
198        client: reqwest_middleware::ClientWithMiddleware,
199    ) -> Self {
200        Self { config, client }
201    }
202
203    /// Creates or replaces multiple items in a datastore by their keys in a single operation.
204    pub async fn bulk_write_datastore_items(
205        &self,
206        datastore_id: String,
207        body: crate::datadogV2::model::BulkPutAppsDatastoreItemsRequest,
208    ) -> Result<
209        crate::datadogV2::model::PutAppsDatastoreItemResponseArray,
210        datadog::Error<BulkWriteDatastoreItemsError>,
211    > {
212        match self
213            .bulk_write_datastore_items_with_http_info(datastore_id, body)
214            .await
215        {
216            Ok(response_content) => {
217                if let Some(e) = response_content.entity {
218                    Ok(e)
219                } else {
220                    Err(datadog::Error::Serde(serde::de::Error::custom(
221                        "response content was None",
222                    )))
223                }
224            }
225            Err(err) => Err(err),
226        }
227    }
228
229    /// Creates or replaces multiple items in a datastore by their keys in a single operation.
230    pub async fn bulk_write_datastore_items_with_http_info(
231        &self,
232        datastore_id: String,
233        body: crate::datadogV2::model::BulkPutAppsDatastoreItemsRequest,
234    ) -> Result<
235        datadog::ResponseContent<crate::datadogV2::model::PutAppsDatastoreItemResponseArray>,
236        datadog::Error<BulkWriteDatastoreItemsError>,
237    > {
238        let local_configuration = &self.config;
239        let operation_id = "v2.bulk_write_datastore_items";
240
241        let local_client = &self.client;
242
243        let local_uri_str = format!(
244            "{}/api/v2/actions-datastores/{datastore_id}/items/bulk",
245            local_configuration.get_operation_host(operation_id),
246            datastore_id = datadog::urlencode(datastore_id)
247        );
248        let mut local_req_builder =
249            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
250
251        // build headers
252        let mut headers = HeaderMap::new();
253        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
254        headers.insert("Accept", HeaderValue::from_static("application/json"));
255
256        // build user agent
257        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
258            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
259            Err(e) => {
260                log::warn!("Failed to parse user agent header: {e}, falling back to default");
261                headers.insert(
262                    reqwest::header::USER_AGENT,
263                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
264                )
265            }
266        };
267
268        // build auth
269        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
270            headers.insert(
271                "DD-API-KEY",
272                HeaderValue::from_str(local_key.key.as_str())
273                    .expect("failed to parse DD-API-KEY header"),
274            );
275        };
276        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
277            headers.insert(
278                "DD-APPLICATION-KEY",
279                HeaderValue::from_str(local_key.key.as_str())
280                    .expect("failed to parse DD-APPLICATION-KEY header"),
281            );
282        };
283
284        // build body parameters
285        let output = Vec::new();
286        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
287        if body.serialize(&mut ser).is_ok() {
288            if let Some(content_encoding) = headers.get("Content-Encoding") {
289                match content_encoding.to_str().unwrap_or_default() {
290                    "gzip" => {
291                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
292                        let _ = enc.write_all(ser.into_inner().as_slice());
293                        match enc.finish() {
294                            Ok(buf) => {
295                                local_req_builder = local_req_builder.body(buf);
296                            }
297                            Err(e) => return Err(datadog::Error::Io(e)),
298                        }
299                    }
300                    "deflate" => {
301                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
302                        let _ = enc.write_all(ser.into_inner().as_slice());
303                        match enc.finish() {
304                            Ok(buf) => {
305                                local_req_builder = local_req_builder.body(buf);
306                            }
307                            Err(e) => return Err(datadog::Error::Io(e)),
308                        }
309                    }
310                    "zstd1" => {
311                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
312                        let _ = enc.write_all(ser.into_inner().as_slice());
313                        match enc.finish() {
314                            Ok(buf) => {
315                                local_req_builder = local_req_builder.body(buf);
316                            }
317                            Err(e) => return Err(datadog::Error::Io(e)),
318                        }
319                    }
320                    _ => {
321                        local_req_builder = local_req_builder.body(ser.into_inner());
322                    }
323                }
324            } else {
325                local_req_builder = local_req_builder.body(ser.into_inner());
326            }
327        }
328
329        local_req_builder = local_req_builder.headers(headers);
330        let local_req = local_req_builder.build()?;
331        log::debug!("request content: {:?}", local_req.body());
332        let local_resp = local_client.execute(local_req).await?;
333
334        let local_status = local_resp.status();
335        let local_content = local_resp.text().await?;
336        log::debug!("response content: {}", local_content);
337
338        if !local_status.is_client_error() && !local_status.is_server_error() {
339            match serde_json::from_str::<crate::datadogV2::model::PutAppsDatastoreItemResponseArray>(
340                &local_content,
341            ) {
342                Ok(e) => {
343                    return Ok(datadog::ResponseContent {
344                        status: local_status,
345                        content: local_content,
346                        entity: Some(e),
347                    })
348                }
349                Err(e) => return Err(datadog::Error::Serde(e)),
350            };
351        } else {
352            let local_entity: Option<BulkWriteDatastoreItemsError> =
353                serde_json::from_str(&local_content).ok();
354            let local_error = datadog::ResponseContent {
355                status: local_status,
356                content: local_content,
357                entity: local_entity,
358            };
359            Err(datadog::Error::ResponseError(local_error))
360        }
361    }
362
363    /// Creates a new datastore.
364    pub async fn create_datastore(
365        &self,
366        body: crate::datadogV2::model::CreateAppsDatastoreRequest,
367    ) -> Result<
368        crate::datadogV2::model::CreateAppsDatastoreResponse,
369        datadog::Error<CreateDatastoreError>,
370    > {
371        match self.create_datastore_with_http_info(body).await {
372            Ok(response_content) => {
373                if let Some(e) = response_content.entity {
374                    Ok(e)
375                } else {
376                    Err(datadog::Error::Serde(serde::de::Error::custom(
377                        "response content was None",
378                    )))
379                }
380            }
381            Err(err) => Err(err),
382        }
383    }
384
385    /// Creates a new datastore.
386    pub async fn create_datastore_with_http_info(
387        &self,
388        body: crate::datadogV2::model::CreateAppsDatastoreRequest,
389    ) -> Result<
390        datadog::ResponseContent<crate::datadogV2::model::CreateAppsDatastoreResponse>,
391        datadog::Error<CreateDatastoreError>,
392    > {
393        let local_configuration = &self.config;
394        let operation_id = "v2.create_datastore";
395
396        let local_client = &self.client;
397
398        let local_uri_str = format!(
399            "{}/api/v2/actions-datastores",
400            local_configuration.get_operation_host(operation_id)
401        );
402        let mut local_req_builder =
403            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
404
405        // build headers
406        let mut headers = HeaderMap::new();
407        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
408        headers.insert("Accept", HeaderValue::from_static("application/json"));
409
410        // build user agent
411        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
412            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
413            Err(e) => {
414                log::warn!("Failed to parse user agent header: {e}, falling back to default");
415                headers.insert(
416                    reqwest::header::USER_AGENT,
417                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
418                )
419            }
420        };
421
422        // build auth
423        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
424            headers.insert(
425                "DD-API-KEY",
426                HeaderValue::from_str(local_key.key.as_str())
427                    .expect("failed to parse DD-API-KEY header"),
428            );
429        };
430        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
431            headers.insert(
432                "DD-APPLICATION-KEY",
433                HeaderValue::from_str(local_key.key.as_str())
434                    .expect("failed to parse DD-APPLICATION-KEY header"),
435            );
436        };
437
438        // build body parameters
439        let output = Vec::new();
440        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
441        if body.serialize(&mut ser).is_ok() {
442            if let Some(content_encoding) = headers.get("Content-Encoding") {
443                match content_encoding.to_str().unwrap_or_default() {
444                    "gzip" => {
445                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
446                        let _ = enc.write_all(ser.into_inner().as_slice());
447                        match enc.finish() {
448                            Ok(buf) => {
449                                local_req_builder = local_req_builder.body(buf);
450                            }
451                            Err(e) => return Err(datadog::Error::Io(e)),
452                        }
453                    }
454                    "deflate" => {
455                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
456                        let _ = enc.write_all(ser.into_inner().as_slice());
457                        match enc.finish() {
458                            Ok(buf) => {
459                                local_req_builder = local_req_builder.body(buf);
460                            }
461                            Err(e) => return Err(datadog::Error::Io(e)),
462                        }
463                    }
464                    "zstd1" => {
465                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
466                        let _ = enc.write_all(ser.into_inner().as_slice());
467                        match enc.finish() {
468                            Ok(buf) => {
469                                local_req_builder = local_req_builder.body(buf);
470                            }
471                            Err(e) => return Err(datadog::Error::Io(e)),
472                        }
473                    }
474                    _ => {
475                        local_req_builder = local_req_builder.body(ser.into_inner());
476                    }
477                }
478            } else {
479                local_req_builder = local_req_builder.body(ser.into_inner());
480            }
481        }
482
483        local_req_builder = local_req_builder.headers(headers);
484        let local_req = local_req_builder.build()?;
485        log::debug!("request content: {:?}", local_req.body());
486        let local_resp = local_client.execute(local_req).await?;
487
488        let local_status = local_resp.status();
489        let local_content = local_resp.text().await?;
490        log::debug!("response content: {}", local_content);
491
492        if !local_status.is_client_error() && !local_status.is_server_error() {
493            match serde_json::from_str::<crate::datadogV2::model::CreateAppsDatastoreResponse>(
494                &local_content,
495            ) {
496                Ok(e) => {
497                    return Ok(datadog::ResponseContent {
498                        status: local_status,
499                        content: local_content,
500                        entity: Some(e),
501                    })
502                }
503                Err(e) => return Err(datadog::Error::Serde(e)),
504            };
505        } else {
506            let local_entity: Option<CreateDatastoreError> =
507                serde_json::from_str(&local_content).ok();
508            let local_error = datadog::ResponseContent {
509                status: local_status,
510                content: local_content,
511                entity: local_entity,
512            };
513            Err(datadog::Error::ResponseError(local_error))
514        }
515    }
516
517    /// Deletes a datastore by its unique identifier.
518    pub async fn delete_datastore(
519        &self,
520        datastore_id: String,
521    ) -> Result<(), datadog::Error<DeleteDatastoreError>> {
522        match self.delete_datastore_with_http_info(datastore_id).await {
523            Ok(_) => Ok(()),
524            Err(err) => Err(err),
525        }
526    }
527
528    /// Deletes a datastore by its unique identifier.
529    pub async fn delete_datastore_with_http_info(
530        &self,
531        datastore_id: String,
532    ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteDatastoreError>> {
533        let local_configuration = &self.config;
534        let operation_id = "v2.delete_datastore";
535
536        let local_client = &self.client;
537
538        let local_uri_str = format!(
539            "{}/api/v2/actions-datastores/{datastore_id}",
540            local_configuration.get_operation_host(operation_id),
541            datastore_id = datadog::urlencode(datastore_id)
542        );
543        let mut local_req_builder =
544            local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
545
546        // build headers
547        let mut headers = HeaderMap::new();
548        headers.insert("Accept", HeaderValue::from_static("*/*"));
549
550        // build user agent
551        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
552            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
553            Err(e) => {
554                log::warn!("Failed to parse user agent header: {e}, falling back to default");
555                headers.insert(
556                    reqwest::header::USER_AGENT,
557                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
558                )
559            }
560        };
561
562        // build auth
563        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
564            headers.insert(
565                "DD-API-KEY",
566                HeaderValue::from_str(local_key.key.as_str())
567                    .expect("failed to parse DD-API-KEY header"),
568            );
569        };
570        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
571            headers.insert(
572                "DD-APPLICATION-KEY",
573                HeaderValue::from_str(local_key.key.as_str())
574                    .expect("failed to parse DD-APPLICATION-KEY header"),
575            );
576        };
577
578        local_req_builder = local_req_builder.headers(headers);
579        let local_req = local_req_builder.build()?;
580        log::debug!("request content: {:?}", local_req.body());
581        let local_resp = local_client.execute(local_req).await?;
582
583        let local_status = local_resp.status();
584        let local_content = local_resp.text().await?;
585        log::debug!("response content: {}", local_content);
586
587        if !local_status.is_client_error() && !local_status.is_server_error() {
588            Ok(datadog::ResponseContent {
589                status: local_status,
590                content: local_content,
591                entity: None,
592            })
593        } else {
594            let local_entity: Option<DeleteDatastoreError> =
595                serde_json::from_str(&local_content).ok();
596            let local_error = datadog::ResponseContent {
597                status: local_status,
598                content: local_content,
599                entity: local_entity,
600            };
601            Err(datadog::Error::ResponseError(local_error))
602        }
603    }
604
605    /// Deletes an item from a datastore by its key.
606    pub async fn delete_datastore_item(
607        &self,
608        datastore_id: String,
609        body: crate::datadogV2::model::DeleteAppsDatastoreItemRequest,
610    ) -> Result<
611        crate::datadogV2::model::DeleteAppsDatastoreItemResponse,
612        datadog::Error<DeleteDatastoreItemError>,
613    > {
614        match self
615            .delete_datastore_item_with_http_info(datastore_id, body)
616            .await
617        {
618            Ok(response_content) => {
619                if let Some(e) = response_content.entity {
620                    Ok(e)
621                } else {
622                    Err(datadog::Error::Serde(serde::de::Error::custom(
623                        "response content was None",
624                    )))
625                }
626            }
627            Err(err) => Err(err),
628        }
629    }
630
631    /// Deletes an item from a datastore by its key.
632    pub async fn delete_datastore_item_with_http_info(
633        &self,
634        datastore_id: String,
635        body: crate::datadogV2::model::DeleteAppsDatastoreItemRequest,
636    ) -> Result<
637        datadog::ResponseContent<crate::datadogV2::model::DeleteAppsDatastoreItemResponse>,
638        datadog::Error<DeleteDatastoreItemError>,
639    > {
640        let local_configuration = &self.config;
641        let operation_id = "v2.delete_datastore_item";
642
643        let local_client = &self.client;
644
645        let local_uri_str = format!(
646            "{}/api/v2/actions-datastores/{datastore_id}/items",
647            local_configuration.get_operation_host(operation_id),
648            datastore_id = datadog::urlencode(datastore_id)
649        );
650        let mut local_req_builder =
651            local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
652
653        // build headers
654        let mut headers = HeaderMap::new();
655        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
656        headers.insert("Accept", HeaderValue::from_static("application/json"));
657
658        // build user agent
659        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
660            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
661            Err(e) => {
662                log::warn!("Failed to parse user agent header: {e}, falling back to default");
663                headers.insert(
664                    reqwest::header::USER_AGENT,
665                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
666                )
667            }
668        };
669
670        // build auth
671        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
672            headers.insert(
673                "DD-API-KEY",
674                HeaderValue::from_str(local_key.key.as_str())
675                    .expect("failed to parse DD-API-KEY header"),
676            );
677        };
678        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
679            headers.insert(
680                "DD-APPLICATION-KEY",
681                HeaderValue::from_str(local_key.key.as_str())
682                    .expect("failed to parse DD-APPLICATION-KEY header"),
683            );
684        };
685
686        // build body parameters
687        let output = Vec::new();
688        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
689        if body.serialize(&mut ser).is_ok() {
690            if let Some(content_encoding) = headers.get("Content-Encoding") {
691                match content_encoding.to_str().unwrap_or_default() {
692                    "gzip" => {
693                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
694                        let _ = enc.write_all(ser.into_inner().as_slice());
695                        match enc.finish() {
696                            Ok(buf) => {
697                                local_req_builder = local_req_builder.body(buf);
698                            }
699                            Err(e) => return Err(datadog::Error::Io(e)),
700                        }
701                    }
702                    "deflate" => {
703                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
704                        let _ = enc.write_all(ser.into_inner().as_slice());
705                        match enc.finish() {
706                            Ok(buf) => {
707                                local_req_builder = local_req_builder.body(buf);
708                            }
709                            Err(e) => return Err(datadog::Error::Io(e)),
710                        }
711                    }
712                    "zstd1" => {
713                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
714                        let _ = enc.write_all(ser.into_inner().as_slice());
715                        match enc.finish() {
716                            Ok(buf) => {
717                                local_req_builder = local_req_builder.body(buf);
718                            }
719                            Err(e) => return Err(datadog::Error::Io(e)),
720                        }
721                    }
722                    _ => {
723                        local_req_builder = local_req_builder.body(ser.into_inner());
724                    }
725                }
726            } else {
727                local_req_builder = local_req_builder.body(ser.into_inner());
728            }
729        }
730
731        local_req_builder = local_req_builder.headers(headers);
732        let local_req = local_req_builder.build()?;
733        log::debug!("request content: {:?}", local_req.body());
734        let local_resp = local_client.execute(local_req).await?;
735
736        let local_status = local_resp.status();
737        let local_content = local_resp.text().await?;
738        log::debug!("response content: {}", local_content);
739
740        if !local_status.is_client_error() && !local_status.is_server_error() {
741            match serde_json::from_str::<crate::datadogV2::model::DeleteAppsDatastoreItemResponse>(
742                &local_content,
743            ) {
744                Ok(e) => {
745                    return Ok(datadog::ResponseContent {
746                        status: local_status,
747                        content: local_content,
748                        entity: Some(e),
749                    })
750                }
751                Err(e) => return Err(datadog::Error::Serde(e)),
752            };
753        } else {
754            let local_entity: Option<DeleteDatastoreItemError> =
755                serde_json::from_str(&local_content).ok();
756            let local_error = datadog::ResponseContent {
757                status: local_status,
758                content: local_content,
759                entity: local_entity,
760            };
761            Err(datadog::Error::ResponseError(local_error))
762        }
763    }
764
765    /// Retrieves a specific datastore by its ID.
766    pub async fn get_datastore(
767        &self,
768        datastore_id: String,
769    ) -> Result<crate::datadogV2::model::Datastore, datadog::Error<GetDatastoreError>> {
770        match self.get_datastore_with_http_info(datastore_id).await {
771            Ok(response_content) => {
772                if let Some(e) = response_content.entity {
773                    Ok(e)
774                } else {
775                    Err(datadog::Error::Serde(serde::de::Error::custom(
776                        "response content was None",
777                    )))
778                }
779            }
780            Err(err) => Err(err),
781        }
782    }
783
784    /// Retrieves a specific datastore by its ID.
785    pub async fn get_datastore_with_http_info(
786        &self,
787        datastore_id: String,
788    ) -> Result<
789        datadog::ResponseContent<crate::datadogV2::model::Datastore>,
790        datadog::Error<GetDatastoreError>,
791    > {
792        let local_configuration = &self.config;
793        let operation_id = "v2.get_datastore";
794
795        let local_client = &self.client;
796
797        let local_uri_str = format!(
798            "{}/api/v2/actions-datastores/{datastore_id}",
799            local_configuration.get_operation_host(operation_id),
800            datastore_id = datadog::urlencode(datastore_id)
801        );
802        let mut local_req_builder =
803            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
804
805        // build headers
806        let mut headers = HeaderMap::new();
807        headers.insert("Accept", HeaderValue::from_static("application/json"));
808
809        // build user agent
810        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
811            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
812            Err(e) => {
813                log::warn!("Failed to parse user agent header: {e}, falling back to default");
814                headers.insert(
815                    reqwest::header::USER_AGENT,
816                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
817                )
818            }
819        };
820
821        // build auth
822        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
823            headers.insert(
824                "DD-API-KEY",
825                HeaderValue::from_str(local_key.key.as_str())
826                    .expect("failed to parse DD-API-KEY header"),
827            );
828        };
829        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
830            headers.insert(
831                "DD-APPLICATION-KEY",
832                HeaderValue::from_str(local_key.key.as_str())
833                    .expect("failed to parse DD-APPLICATION-KEY header"),
834            );
835        };
836
837        local_req_builder = local_req_builder.headers(headers);
838        let local_req = local_req_builder.build()?;
839        log::debug!("request content: {:?}", local_req.body());
840        let local_resp = local_client.execute(local_req).await?;
841
842        let local_status = local_resp.status();
843        let local_content = local_resp.text().await?;
844        log::debug!("response content: {}", local_content);
845
846        if !local_status.is_client_error() && !local_status.is_server_error() {
847            match serde_json::from_str::<crate::datadogV2::model::Datastore>(&local_content) {
848                Ok(e) => {
849                    return Ok(datadog::ResponseContent {
850                        status: local_status,
851                        content: local_content,
852                        entity: Some(e),
853                    })
854                }
855                Err(e) => return Err(datadog::Error::Serde(e)),
856            };
857        } else {
858            let local_entity: Option<GetDatastoreError> = serde_json::from_str(&local_content).ok();
859            let local_error = datadog::ResponseContent {
860                status: local_status,
861                content: local_content,
862                entity: local_entity,
863            };
864            Err(datadog::Error::ResponseError(local_error))
865        }
866    }
867
868    /// Lists items from a datastore. You can filter the results by specifying either an item key or a filter query parameter, but not both at the same time. Supports server-side pagination for large datasets.
869    pub async fn list_datastore_items(
870        &self,
871        datastore_id: String,
872        params: ListDatastoreItemsOptionalParams,
873    ) -> Result<crate::datadogV2::model::ItemApiPayloadArray, datadog::Error<ListDatastoreItemsError>>
874    {
875        match self
876            .list_datastore_items_with_http_info(datastore_id, params)
877            .await
878        {
879            Ok(response_content) => {
880                if let Some(e) = response_content.entity {
881                    Ok(e)
882                } else {
883                    Err(datadog::Error::Serde(serde::de::Error::custom(
884                        "response content was None",
885                    )))
886                }
887            }
888            Err(err) => Err(err),
889        }
890    }
891
892    /// Lists items from a datastore. You can filter the results by specifying either an item key or a filter query parameter, but not both at the same time. Supports server-side pagination for large datasets.
893    pub async fn list_datastore_items_with_http_info(
894        &self,
895        datastore_id: String,
896        params: ListDatastoreItemsOptionalParams,
897    ) -> Result<
898        datadog::ResponseContent<crate::datadogV2::model::ItemApiPayloadArray>,
899        datadog::Error<ListDatastoreItemsError>,
900    > {
901        let local_configuration = &self.config;
902        let operation_id = "v2.list_datastore_items";
903
904        // unbox and build optional parameters
905        let filter = params.filter;
906        let item_key = params.item_key;
907        let page_limit = params.page_limit;
908        let page_offset = params.page_offset;
909        let sort = params.sort;
910
911        let local_client = &self.client;
912
913        let local_uri_str = format!(
914            "{}/api/v2/actions-datastores/{datastore_id}/items",
915            local_configuration.get_operation_host(operation_id),
916            datastore_id = datadog::urlencode(datastore_id)
917        );
918        let mut local_req_builder =
919            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
920
921        if let Some(ref local_query_param) = filter {
922            local_req_builder =
923                local_req_builder.query(&[("filter", &local_query_param.to_string())]);
924        };
925        if let Some(ref local_query_param) = item_key {
926            local_req_builder =
927                local_req_builder.query(&[("item_key", &local_query_param.to_string())]);
928        };
929        if let Some(ref local_query_param) = page_limit {
930            local_req_builder =
931                local_req_builder.query(&[("page[limit]", &local_query_param.to_string())]);
932        };
933        if let Some(ref local_query_param) = page_offset {
934            local_req_builder =
935                local_req_builder.query(&[("page[offset]", &local_query_param.to_string())]);
936        };
937        if let Some(ref local_query_param) = sort {
938            local_req_builder =
939                local_req_builder.query(&[("sort", &local_query_param.to_string())]);
940        };
941
942        // build headers
943        let mut headers = HeaderMap::new();
944        headers.insert("Accept", HeaderValue::from_static("application/json"));
945
946        // build user agent
947        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
948            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
949            Err(e) => {
950                log::warn!("Failed to parse user agent header: {e}, falling back to default");
951                headers.insert(
952                    reqwest::header::USER_AGENT,
953                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
954                )
955            }
956        };
957
958        // build auth
959        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
960            headers.insert(
961                "DD-API-KEY",
962                HeaderValue::from_str(local_key.key.as_str())
963                    .expect("failed to parse DD-API-KEY header"),
964            );
965        };
966        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
967            headers.insert(
968                "DD-APPLICATION-KEY",
969                HeaderValue::from_str(local_key.key.as_str())
970                    .expect("failed to parse DD-APPLICATION-KEY header"),
971            );
972        };
973
974        local_req_builder = local_req_builder.headers(headers);
975        let local_req = local_req_builder.build()?;
976        log::debug!("request content: {:?}", local_req.body());
977        let local_resp = local_client.execute(local_req).await?;
978
979        let local_status = local_resp.status();
980        let local_content = local_resp.text().await?;
981        log::debug!("response content: {}", local_content);
982
983        if !local_status.is_client_error() && !local_status.is_server_error() {
984            match serde_json::from_str::<crate::datadogV2::model::ItemApiPayloadArray>(
985                &local_content,
986            ) {
987                Ok(e) => {
988                    return Ok(datadog::ResponseContent {
989                        status: local_status,
990                        content: local_content,
991                        entity: Some(e),
992                    })
993                }
994                Err(e) => return Err(datadog::Error::Serde(e)),
995            };
996        } else {
997            let local_entity: Option<ListDatastoreItemsError> =
998                serde_json::from_str(&local_content).ok();
999            let local_error = datadog::ResponseContent {
1000                status: local_status,
1001                content: local_content,
1002                entity: local_entity,
1003            };
1004            Err(datadog::Error::ResponseError(local_error))
1005        }
1006    }
1007
1008    /// Lists all datastores for the organization.
1009    pub async fn list_datastores(
1010        &self,
1011    ) -> Result<crate::datadogV2::model::DatastoreArray, datadog::Error<ListDatastoresError>> {
1012        match self.list_datastores_with_http_info().await {
1013            Ok(response_content) => {
1014                if let Some(e) = response_content.entity {
1015                    Ok(e)
1016                } else {
1017                    Err(datadog::Error::Serde(serde::de::Error::custom(
1018                        "response content was None",
1019                    )))
1020                }
1021            }
1022            Err(err) => Err(err),
1023        }
1024    }
1025
1026    /// Lists all datastores for the organization.
1027    pub async fn list_datastores_with_http_info(
1028        &self,
1029    ) -> Result<
1030        datadog::ResponseContent<crate::datadogV2::model::DatastoreArray>,
1031        datadog::Error<ListDatastoresError>,
1032    > {
1033        let local_configuration = &self.config;
1034        let operation_id = "v2.list_datastores";
1035
1036        let local_client = &self.client;
1037
1038        let local_uri_str = format!(
1039            "{}/api/v2/actions-datastores",
1040            local_configuration.get_operation_host(operation_id)
1041        );
1042        let mut local_req_builder =
1043            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1044
1045        // build headers
1046        let mut headers = HeaderMap::new();
1047        headers.insert("Accept", HeaderValue::from_static("application/json"));
1048
1049        // build user agent
1050        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1051            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1052            Err(e) => {
1053                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1054                headers.insert(
1055                    reqwest::header::USER_AGENT,
1056                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1057                )
1058            }
1059        };
1060
1061        // build auth
1062        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1063            headers.insert(
1064                "DD-API-KEY",
1065                HeaderValue::from_str(local_key.key.as_str())
1066                    .expect("failed to parse DD-API-KEY header"),
1067            );
1068        };
1069        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1070            headers.insert(
1071                "DD-APPLICATION-KEY",
1072                HeaderValue::from_str(local_key.key.as_str())
1073                    .expect("failed to parse DD-APPLICATION-KEY header"),
1074            );
1075        };
1076
1077        local_req_builder = local_req_builder.headers(headers);
1078        let local_req = local_req_builder.build()?;
1079        log::debug!("request content: {:?}", local_req.body());
1080        let local_resp = local_client.execute(local_req).await?;
1081
1082        let local_status = local_resp.status();
1083        let local_content = local_resp.text().await?;
1084        log::debug!("response content: {}", local_content);
1085
1086        if !local_status.is_client_error() && !local_status.is_server_error() {
1087            match serde_json::from_str::<crate::datadogV2::model::DatastoreArray>(&local_content) {
1088                Ok(e) => {
1089                    return Ok(datadog::ResponseContent {
1090                        status: local_status,
1091                        content: local_content,
1092                        entity: Some(e),
1093                    })
1094                }
1095                Err(e) => return Err(datadog::Error::Serde(e)),
1096            };
1097        } else {
1098            let local_entity: Option<ListDatastoresError> =
1099                serde_json::from_str(&local_content).ok();
1100            let local_error = datadog::ResponseContent {
1101                status: local_status,
1102                content: local_content,
1103                entity: local_entity,
1104            };
1105            Err(datadog::Error::ResponseError(local_error))
1106        }
1107    }
1108
1109    /// Updates an existing datastore's attributes.
1110    pub async fn update_datastore(
1111        &self,
1112        datastore_id: String,
1113        body: crate::datadogV2::model::UpdateAppsDatastoreRequest,
1114    ) -> Result<crate::datadogV2::model::Datastore, datadog::Error<UpdateDatastoreError>> {
1115        match self
1116            .update_datastore_with_http_info(datastore_id, body)
1117            .await
1118        {
1119            Ok(response_content) => {
1120                if let Some(e) = response_content.entity {
1121                    Ok(e)
1122                } else {
1123                    Err(datadog::Error::Serde(serde::de::Error::custom(
1124                        "response content was None",
1125                    )))
1126                }
1127            }
1128            Err(err) => Err(err),
1129        }
1130    }
1131
1132    /// Updates an existing datastore's attributes.
1133    pub async fn update_datastore_with_http_info(
1134        &self,
1135        datastore_id: String,
1136        body: crate::datadogV2::model::UpdateAppsDatastoreRequest,
1137    ) -> Result<
1138        datadog::ResponseContent<crate::datadogV2::model::Datastore>,
1139        datadog::Error<UpdateDatastoreError>,
1140    > {
1141        let local_configuration = &self.config;
1142        let operation_id = "v2.update_datastore";
1143
1144        let local_client = &self.client;
1145
1146        let local_uri_str = format!(
1147            "{}/api/v2/actions-datastores/{datastore_id}",
1148            local_configuration.get_operation_host(operation_id),
1149            datastore_id = datadog::urlencode(datastore_id)
1150        );
1151        let mut local_req_builder =
1152            local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
1153
1154        // build headers
1155        let mut headers = HeaderMap::new();
1156        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1157        headers.insert("Accept", HeaderValue::from_static("application/json"));
1158
1159        // build user agent
1160        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1161            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1162            Err(e) => {
1163                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1164                headers.insert(
1165                    reqwest::header::USER_AGENT,
1166                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1167                )
1168            }
1169        };
1170
1171        // build auth
1172        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1173            headers.insert(
1174                "DD-API-KEY",
1175                HeaderValue::from_str(local_key.key.as_str())
1176                    .expect("failed to parse DD-API-KEY header"),
1177            );
1178        };
1179        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1180            headers.insert(
1181                "DD-APPLICATION-KEY",
1182                HeaderValue::from_str(local_key.key.as_str())
1183                    .expect("failed to parse DD-APPLICATION-KEY header"),
1184            );
1185        };
1186
1187        // build body parameters
1188        let output = Vec::new();
1189        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1190        if body.serialize(&mut ser).is_ok() {
1191            if let Some(content_encoding) = headers.get("Content-Encoding") {
1192                match content_encoding.to_str().unwrap_or_default() {
1193                    "gzip" => {
1194                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1195                        let _ = enc.write_all(ser.into_inner().as_slice());
1196                        match enc.finish() {
1197                            Ok(buf) => {
1198                                local_req_builder = local_req_builder.body(buf);
1199                            }
1200                            Err(e) => return Err(datadog::Error::Io(e)),
1201                        }
1202                    }
1203                    "deflate" => {
1204                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1205                        let _ = enc.write_all(ser.into_inner().as_slice());
1206                        match enc.finish() {
1207                            Ok(buf) => {
1208                                local_req_builder = local_req_builder.body(buf);
1209                            }
1210                            Err(e) => return Err(datadog::Error::Io(e)),
1211                        }
1212                    }
1213                    "zstd1" => {
1214                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1215                        let _ = enc.write_all(ser.into_inner().as_slice());
1216                        match enc.finish() {
1217                            Ok(buf) => {
1218                                local_req_builder = local_req_builder.body(buf);
1219                            }
1220                            Err(e) => return Err(datadog::Error::Io(e)),
1221                        }
1222                    }
1223                    _ => {
1224                        local_req_builder = local_req_builder.body(ser.into_inner());
1225                    }
1226                }
1227            } else {
1228                local_req_builder = local_req_builder.body(ser.into_inner());
1229            }
1230        }
1231
1232        local_req_builder = local_req_builder.headers(headers);
1233        let local_req = local_req_builder.build()?;
1234        log::debug!("request content: {:?}", local_req.body());
1235        let local_resp = local_client.execute(local_req).await?;
1236
1237        let local_status = local_resp.status();
1238        let local_content = local_resp.text().await?;
1239        log::debug!("response content: {}", local_content);
1240
1241        if !local_status.is_client_error() && !local_status.is_server_error() {
1242            match serde_json::from_str::<crate::datadogV2::model::Datastore>(&local_content) {
1243                Ok(e) => {
1244                    return Ok(datadog::ResponseContent {
1245                        status: local_status,
1246                        content: local_content,
1247                        entity: Some(e),
1248                    })
1249                }
1250                Err(e) => return Err(datadog::Error::Serde(e)),
1251            };
1252        } else {
1253            let local_entity: Option<UpdateDatastoreError> =
1254                serde_json::from_str(&local_content).ok();
1255            let local_error = datadog::ResponseContent {
1256                status: local_status,
1257                content: local_content,
1258                entity: local_entity,
1259            };
1260            Err(datadog::Error::ResponseError(local_error))
1261        }
1262    }
1263
1264    /// Partially updates an item in a datastore by its key.
1265    pub async fn update_datastore_item(
1266        &self,
1267        datastore_id: String,
1268        body: crate::datadogV2::model::UpdateAppsDatastoreItemRequest,
1269    ) -> Result<crate::datadogV2::model::ItemApiPayload, datadog::Error<UpdateDatastoreItemError>>
1270    {
1271        match self
1272            .update_datastore_item_with_http_info(datastore_id, body)
1273            .await
1274        {
1275            Ok(response_content) => {
1276                if let Some(e) = response_content.entity {
1277                    Ok(e)
1278                } else {
1279                    Err(datadog::Error::Serde(serde::de::Error::custom(
1280                        "response content was None",
1281                    )))
1282                }
1283            }
1284            Err(err) => Err(err),
1285        }
1286    }
1287
1288    /// Partially updates an item in a datastore by its key.
1289    pub async fn update_datastore_item_with_http_info(
1290        &self,
1291        datastore_id: String,
1292        body: crate::datadogV2::model::UpdateAppsDatastoreItemRequest,
1293    ) -> Result<
1294        datadog::ResponseContent<crate::datadogV2::model::ItemApiPayload>,
1295        datadog::Error<UpdateDatastoreItemError>,
1296    > {
1297        let local_configuration = &self.config;
1298        let operation_id = "v2.update_datastore_item";
1299
1300        let local_client = &self.client;
1301
1302        let local_uri_str = format!(
1303            "{}/api/v2/actions-datastores/{datastore_id}/items",
1304            local_configuration.get_operation_host(operation_id),
1305            datastore_id = datadog::urlencode(datastore_id)
1306        );
1307        let mut local_req_builder =
1308            local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
1309
1310        // build headers
1311        let mut headers = HeaderMap::new();
1312        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1313        headers.insert("Accept", HeaderValue::from_static("application/json"));
1314
1315        // build user agent
1316        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1317            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1318            Err(e) => {
1319                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1320                headers.insert(
1321                    reqwest::header::USER_AGENT,
1322                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1323                )
1324            }
1325        };
1326
1327        // build auth
1328        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1329            headers.insert(
1330                "DD-API-KEY",
1331                HeaderValue::from_str(local_key.key.as_str())
1332                    .expect("failed to parse DD-API-KEY header"),
1333            );
1334        };
1335        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1336            headers.insert(
1337                "DD-APPLICATION-KEY",
1338                HeaderValue::from_str(local_key.key.as_str())
1339                    .expect("failed to parse DD-APPLICATION-KEY header"),
1340            );
1341        };
1342
1343        // build body parameters
1344        let output = Vec::new();
1345        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1346        if body.serialize(&mut ser).is_ok() {
1347            if let Some(content_encoding) = headers.get("Content-Encoding") {
1348                match content_encoding.to_str().unwrap_or_default() {
1349                    "gzip" => {
1350                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1351                        let _ = enc.write_all(ser.into_inner().as_slice());
1352                        match enc.finish() {
1353                            Ok(buf) => {
1354                                local_req_builder = local_req_builder.body(buf);
1355                            }
1356                            Err(e) => return Err(datadog::Error::Io(e)),
1357                        }
1358                    }
1359                    "deflate" => {
1360                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1361                        let _ = enc.write_all(ser.into_inner().as_slice());
1362                        match enc.finish() {
1363                            Ok(buf) => {
1364                                local_req_builder = local_req_builder.body(buf);
1365                            }
1366                            Err(e) => return Err(datadog::Error::Io(e)),
1367                        }
1368                    }
1369                    "zstd1" => {
1370                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1371                        let _ = enc.write_all(ser.into_inner().as_slice());
1372                        match enc.finish() {
1373                            Ok(buf) => {
1374                                local_req_builder = local_req_builder.body(buf);
1375                            }
1376                            Err(e) => return Err(datadog::Error::Io(e)),
1377                        }
1378                    }
1379                    _ => {
1380                        local_req_builder = local_req_builder.body(ser.into_inner());
1381                    }
1382                }
1383            } else {
1384                local_req_builder = local_req_builder.body(ser.into_inner());
1385            }
1386        }
1387
1388        local_req_builder = local_req_builder.headers(headers);
1389        let local_req = local_req_builder.build()?;
1390        log::debug!("request content: {:?}", local_req.body());
1391        let local_resp = local_client.execute(local_req).await?;
1392
1393        let local_status = local_resp.status();
1394        let local_content = local_resp.text().await?;
1395        log::debug!("response content: {}", local_content);
1396
1397        if !local_status.is_client_error() && !local_status.is_server_error() {
1398            match serde_json::from_str::<crate::datadogV2::model::ItemApiPayload>(&local_content) {
1399                Ok(e) => {
1400                    return Ok(datadog::ResponseContent {
1401                        status: local_status,
1402                        content: local_content,
1403                        entity: Some(e),
1404                    })
1405                }
1406                Err(e) => return Err(datadog::Error::Serde(e)),
1407            };
1408        } else {
1409            let local_entity: Option<UpdateDatastoreItemError> =
1410                serde_json::from_str(&local_content).ok();
1411            let local_error = datadog::ResponseContent {
1412                status: local_status,
1413                content: local_content,
1414                entity: local_entity,
1415            };
1416            Err(datadog::Error::ResponseError(local_error))
1417        }
1418    }
1419}