createCustomField method
Future<void>
createCustomField(
- String fieldName,
- String label,
- FieldType fieldType, {
- PubliclyUpdatable isPubliclyUpdatable = PubliclyUpdatable.no,
- RequiredField isRequired = RequiredField.notRequired,
Implementation
Future<void> createCustomField(
String fieldName,
String label,
FieldType fieldType, {
PubliclyUpdatable isPubliclyUpdatable = PubliclyUpdatable.no,
RequiredField isRequired = RequiredField.notRequired,
}) async {
final url = '$mauticBaseUrl/api/fields/contact/new';
final headers = getHeaders();
final fieldData = {
'label': label,
'alias': fieldName,
'type': fieldType,
'is_publicly_updatable': isPubliclyUpdatable.value,
'is_required': isRequired.value,
};
final response = await httpClient.post(
Uri.parse(url),
headers: headers,
body: jsonEncode(fieldData),
);
if (response.statusCode != 200) {
throw Exception('Failed to create custom field: ${response.statusCode}');
}
}