updateCustomer method

Future<Customer> updateCustomer({
  1. required Customer customer,
  2. String? realmId,
  3. String? authToken,
})

Sparse updating provides the ability to update a subset of properties for a given object; only elements specified in the request are updated. Missing elements are left untouched. The ID of the object to update is specified in the request body.​

Implementation

Future<Customer> updateCustomer({
  required Customer customer,
  String? realmId,
  String? authToken,
}) async {

  authToken ??= authenticationService.getCachedToken()?.access_token;
  realmId ??= authenticationService.getCachedRealmId();

  Map<String, String> headers = {
    "Authorization": "Bearer ${authToken ?? ""}",
    'Content-Type': 'application/json; charset=UTF-8',
    'Accept': 'application/json',

  };

  Map<String, String> params = {
    "minorversion": minorVersion.toString()
  };

  Uri endpoint = Uri.https(
      baseUrl, "/v3/company/$realmId/customer", params);

  //print (endpoint.toString());

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

  if (response.statusCode == 200) {
    //print (jsonDecode(response.body));
    return Customer.fromJson(jsonDecode(response.body)["Customer"]);
  }
  else {
    throw CustomerException(statusCode: response.statusCode, message: response.body);
  }
}