updateCompanyInfo method

Future<CompanyInfo> updateCompanyInfo({
  1. required CompanyInfo companyInfo,
  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.​ Available with minor version 11

Implementation

Future<CompanyInfo> updateCompanyInfo({
  required CompanyInfo companyInfo,
  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/companyinfo", params);

  //print (endpoint.toString());

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

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