sendEstimate method

Future<Estimate> sendEstimate({
  1. required String estimateId,
  2. required String emailTo,
  3. String? realmId,
  4. String? authToken,
})

The Estimate.EmailStatus parameter is set to EmailSent. The Estimate.DeliveryInfo element is populated with sending information. The Estimate.BillEmail.Address parameter is updated to the address specified with the value of the sendTo query parameter, if specified.

Implementation

Future<Estimate> sendEstimate({
  required String estimateId,
  required String emailTo,
  String? realmId,
  String? authToken,
}) async {

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

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

  };

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

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

  //print (endpoint.toString());

  var response = await
  http.post(endpoint, headers: headers);

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