updateVendor method

Future<Vendor> updateVendor({
  1. required Vendor vendor,
  2. String? realmId,
  3. String? authToken,
})

Use this operation to update any of the writable fields of an existing vendor object. The request body must include all writable fields of the existing object as returned in a read response. Writable fields omitted from the request body are set to NULL. The ID of the object to update is specified in the request body.Add the query parameter, include=updateaccountontxns&minorversion=5, to the endpoint to automatically update the AP account on historical transactions (from soft close date forward) for this vendor with that defined by the APAccountRef attribute in the Vendor object. Updates on soft closed transacitons associated will fail.

Implementation

Future<Vendor> updateVendor({
  required Vendor vendor,
  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/vendor", params);

  //print (endpoint.toString());

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

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