front_api/
custom_fields.rs

1use anyhow::Result;
2
3use crate::Client;
4#[derive(Clone, Debug)]
5pub struct CustomFields {
6    pub client: Client,
7}
8
9impl CustomFields {
10    #[doc(hidden)]
11    pub fn new(client: Client) -> Self {
12        Self { client }
13    }
14
15    #[doc = "List Contact's custom fields\n\nLists the custom fields in your company that are \
16             application to a Contact.\n\n```rust,no_run\nasync fn \
17             example_custom_fields_list_contact() -> anyhow::Result<()> {\n    let client = \
18             front_api::Client::new_from_env();\n    let result: \
19             front_api::types::ListContactCustomFieldsResponse =\n        \
20             client.custom_fields().list_contact().await?;\n    println!(\"{:?}\", result);\n    \
21             Ok(())\n}\n```"]
22    #[tracing::instrument]
23    pub async fn list_contact<'a>(
24        &'a self,
25    ) -> Result<crate::types::ListContactCustomFieldsResponse, crate::types::error::Error> {
26        let mut req = self.client.client.request(
27            http::Method::GET,
28            &format!("{}/{}", self.client.base_url, "contacts/custom_fields"),
29        );
30        req = req.bearer_auth(&self.client.token);
31        let resp = req.send().await?;
32        let status = resp.status();
33        if status.is_success() {
34            let text = resp.text().await.unwrap_or_default();
35            serde_json::from_str(&text).map_err(|err| {
36                crate::types::error::Error::from_serde_error(
37                    format_serde_error::SerdeError::new(text.to_string(), err),
38                    status,
39                )
40            })
41        } else {
42            Err(crate::types::error::Error::UnexpectedResponse(resp))
43        }
44    }
45
46    #[doc = "List Contact's custom fields\n\nLists the custom fields in your company that are \
47             application to a Contact.\n> ⚠\u{fe0f} Deprecated endpoint\n>\n> This endpoint has \
48             been deprecated. Please use the fully compatible `GET /contacts/custom_fields` \
49             endpoint instead.\n\n\n**NOTE:** This operation is marked as \
50             deprecated.\n\n```rust,no_run\nasync fn example_custom_fields_list() -> \
51             anyhow::Result<()> {\n    let client = front_api::Client::new_from_env();\n    let \
52             result: front_api::types::ListCustomFieldsResponse = \
53             client.custom_fields().list().await?;\n    println!(\"{:?}\", result);\n    \
54             Ok(())\n}\n```"]
55    #[tracing::instrument]
56    pub async fn list<'a>(
57        &'a self,
58    ) -> Result<crate::types::ListCustomFieldsResponse, crate::types::error::Error> {
59        let mut req = self.client.client.request(
60            http::Method::GET,
61            &format!("{}/{}", self.client.base_url, "custom_fields"),
62        );
63        req = req.bearer_auth(&self.client.token);
64        let resp = req.send().await?;
65        let status = resp.status();
66        if status.is_success() {
67            let text = resp.text().await.unwrap_or_default();
68            serde_json::from_str(&text).map_err(|err| {
69                crate::types::error::Error::from_serde_error(
70                    format_serde_error::SerdeError::new(text.to_string(), err),
71                    status,
72                )
73            })
74        } else {
75            Err(crate::types::error::Error::UnexpectedResponse(resp))
76        }
77    }
78
79    #[doc = "Update custom field\n\nUpdate a custom field. (⚠\u{fe0f} Deprecated)\n\n**Parameters:**\n\n- `custom_field_id: &'astr`: Custom Field ID (required)\n\n**NOTE:** This operation is marked as deprecated.\n\n```rust,no_run\nasync fn example_custom_fields_update() -> anyhow::Result<()> {\n    let client = front_api::Client::new_from_env();\n    client\n        .custom_fields()\n        .update(\n            \"some-string\",\n            &serde_json::Value::String(\"some-string\".to_string()),\n        )\n        .await?;\n    Ok(())\n}\n```"]
80    #[tracing::instrument]
81    pub async fn update<'a>(
82        &'a self,
83        custom_field_id: &'a str,
84        body: &crate::types::UpdateCustomField,
85    ) -> Result<(), crate::types::error::Error> {
86        let mut req = self.client.client.request(
87            http::Method::PATCH,
88            &format!(
89                "{}/{}",
90                self.client.base_url,
91                "custom_fields/{custom_field_id}".replace("{custom_field_id}", custom_field_id)
92            ),
93        );
94        req = req.bearer_auth(&self.client.token);
95        req = req.json(body);
96        let resp = req.send().await?;
97        let status = resp.status();
98        if status.is_success() {
99            Ok(())
100        } else {
101            Err(crate::types::error::Error::UnexpectedResponse(resp))
102        }
103    }
104}