updateField method

Future<FieldResponse> updateField({
  1. required String tableId,
  2. required int fieldId,
  3. required FieldsUpsertRequest request,
  4. String? authorization,
  5. String? userAgent,
})

Update a field

Updates the properties and custom permissions of a field. The attempt to update certain properties might cause existing data to no longer obey the field’s new properties and may be rejected. See the descriptions of required, unique, and choices, below, for specific situations. Any properties of the field that you do not specify in the request body will remain unchanged.

Implementation

Future<FieldResponse> updateField({
      required String tableId, required int fieldId,
      required FieldsUpsertRequest request, String? authorization, String? userAgent }) async {

  Map<String, String> headers = {
    "Authorization": authorization ?? appAuthorization,
    'Content-Type': 'application/json; charset=UTF-8',
    'Accept': 'application/json',
    "QB-Realm-Hostname": qBRealmHostname,
    "User-Agent": userAgent?? ""
  };

  Uri endpoint = Uri.https(
      baseUrl, "v1/fields/$fieldId?tableId=$tableId");

  var response = await http.post(endpoint, body: jsonEncode(request.toJson()), headers: headers);

  if (response.statusCode >= 400) {
    throw ApiException(response.statusCode, response.body);
  }
  else if (response.statusCode == 200) {
    return FieldResponse.fromJson(jsonDecode(response.body));
  }
  else {
    throw ApiException(response.statusCode, response.body);
  }
}