createEstimate method
An Estimate must have at least one line that describes an item. An Estimate must have a reference to a customer. If shipping address and billing address are not provided, the address from the referenced Customer object is used.
Implementation
Future<Estimate> createEstimate({
required Estimate estimate,
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/estimate", params);
//print (endpoint.toString());
var response = await
http.post(endpoint, body: jsonEncode(estimate.toJson()), 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);
}
}