Fields¶
list (and exists, get_by_name, which use it) reads field metadata through V2; create and
delete use V1.
Service for managing custom fields.
Use V2 /fields endpoints for reading field metadata. Use V1 for creating/deleting fields.
Source code in affinity/services/v1_only.py
1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 | |
create(data: FieldCreate) -> FieldMetadata
¶
Create a custom field.
Source code in affinity/services/v1_only.py
1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 | |
delete(field_id: FieldId) -> bool
¶
Delete a custom field (V1 API).
Note: V1 deletes require numeric field IDs. The SDK accepts V2-style
field-<digits> IDs and converts them; enriched/relationship-intelligence
IDs are not supported.
Source code in affinity/services/v1_only.py
1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 | |
exists(field_id: AnyFieldId) -> bool
¶
Check if a field exists.
Useful for validation before setting field values.
Note: This fetches all fields and checks locally. If your code calls exists() frequently in a loop, consider caching the result of fields.list() yourself.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field_id
|
AnyFieldId
|
The field ID to check |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the field exists, False otherwise |
Example
if client.fields.exists(FieldId("field-123")): client.field_values.create(...)
Source code in affinity/services/v1_only.py
1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 | |
get_by_name(name: str) -> FieldMetadata | None
¶
Find a field by its display name.
Uses case-insensitive matching (casefold for i18n support).
Note: This fetches all fields and searches locally. If your code calls get_by_name() frequently in a loop, consider caching the result of fields.list() yourself.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The field display name to search for |
required |
Returns:
| Type | Description |
|---|---|
FieldMetadata | None
|
FieldMetadata if found, None otherwise |
Example
field = client.fields.get_by_name("Primary Email Status") if field: fv = client.field_values.get_for_entity(field.id, person_id=pid)
Source code in affinity/services/v1_only.py
1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 | |
list(*, list_id: ListId | None = None, entity_type: EntityType | None = None, skip_cache: bool = False) -> list[FieldMetadata]
¶
Get field metadata.
Results are cached for 5 minutes when caching is enabled on the client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
list_id
|
ListId | None
|
Filter to fields for a specific list |
None
|
entity_type
|
EntityType | None
|
Filter to fields for a specific entity type |
None
|
skip_cache
|
bool
|
When True, bypass the 5-minute cache (useful when resolving a field that may have been added recently). |
False
|
Returns:
| Type | Description |
|---|---|
list[FieldMetadata]
|
List of field metadata |
Source code in affinity/services/v1_only.py
1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 | |