sendgrid_api/custom_fields.rs
1use crate::Client;
2use crate::ClientResult;
3
4pub struct CustomFields {
5 pub client: Client,
6}
7
8impl CustomFields {
9 #[doc(hidden)]
10 pub fn new(client: Client) -> Self {
11 CustomFields { client }
12 }
13
14 /**
15 * Get All Field Definitions.
16 *
17 * This function performs a `GET` to the `/marketing/field_definitions` endpoint.
18 *
19 * **This endpoint retrieves all defined Custom Fields and Reserved Fields.**
20 */
21 pub async fn get_mc_field_definitions(
22 &self,
23 ) -> ClientResult<crate::Response<crate::types::GetMcFieldDefinitionsResponse>> {
24 let url = self.client.url("/marketing/field_definitions", None);
25 self.client
26 .get(
27 &url,
28 crate::Message {
29 body: None,
30 content_type: None,
31 },
32 )
33 .await
34 }
35 /**
36 * Create Custom Field Definition.
37 *
38 * This function performs a `POST` to the `/marketing/field_definitions` endpoint.
39 *
40 * **This endpoint creates a new custom field definition.**
41 *
42 * Custom field definitions are created with the given `name` and `field_type`. Although field names are stored in a case-sensitive manner, all field names must be case-insensitively unique. This means you may create a field named `CamelCase` or `camelcase`, but not both. Additionally, a Custom Field name cannot collide with any Reserved Field names. You should save the returned `id` value in order to update or delete the field at a later date. You can have up to 120 custom fields.
43 *
44 * The custom field name should be created using only alphanumeric characters (A-Z and 0-9) and underscores (\_). Custom fields can only begin with letters A-Z or underscores (_). The field type can be date, text, or number fields. The field type is important for creating segments from your contact database.
45 *
46 * **Note: Creating a custom field that begins with a number will cause issues with sending in Marketing Campaigns.**
47 */
48 pub async fn post_mc_field_definition(
49 &self,
50 body: &crate::types::PostMcFieldDefinitionsRequest,
51 ) -> ClientResult<crate::Response<crate::types::PostMcFieldDefinitionsResponseAllOf>> {
52 let url = self.client.url("/marketing/field_definitions", None);
53 self.client
54 .post(
55 &url,
56 crate::Message {
57 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
58 content_type: Some("application/json".to_string()),
59 },
60 )
61 .await
62 }
63 /**
64 * Delete Custom Field Definition.
65 *
66 * This function performs a `DELETE` to the `/marketing/field_definitions/{custom_field_id}` endpoint.
67 *
68 * **This endpoint deletes a defined Custom Field.**
69 *
70 * You cand delete only Custom Fields; Reserved Fields cannot be deleted.
71 */
72 pub async fn delete_mc_field_definitions_custom(
73 &self,
74 custom_field_id: &str,
75 ) -> ClientResult<crate::Response<()>> {
76 let url = self.client.url(
77 &format!(
78 "/marketing/field_definitions/{}",
79 crate::progenitor_support::encode_path(custom_field_id),
80 ),
81 None,
82 );
83 self.client
84 .delete(
85 &url,
86 crate::Message {
87 body: None,
88 content_type: None,
89 },
90 )
91 .await
92 }
93 /**
94 * Update Custom Field Definition.
95 *
96 * This function performs a `PATCH` to the `/marketing/field_definitions/{custom_field_id}` endpoint.
97 *
98 * **This endopoint allows you to update a defined Custom Field.**
99 *
100 * Only your Custom fields can be modified; Reserved Fields cannot be updated.
101 */
102 pub async fn patch_mc_field_definitions_custom(
103 &self,
104 custom_field_id: &str,
105 body: &crate::types::IpPool,
106 ) -> ClientResult<crate::Response<crate::types::PostMcFieldDefinitionsResponseAllOf>> {
107 let url = self.client.url(
108 &format!(
109 "/marketing/field_definitions/{}",
110 crate::progenitor_support::encode_path(custom_field_id),
111 ),
112 None,
113 );
114 self.client
115 .patch(
116 &url,
117 crate::Message {
118 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
119 content_type: Some("application/json".to_string()),
120 },
121 )
122 .await
123 }
124}