updateInvoice method
Future<Invoice>
updateInvoice({
- required int invoiceId,
- required UpdateInvoiceRequest request,
- String? authToken,
Updates an invoice by modifying fields, clearing fields, or both.
For most updates, you can use a sparse Invoice object to add fields or change values and use the fields_to_clear field to specify fields to clear. However, some restrictions apply. For example, you cannot change the order_id or location_id field and you must provide the complete custom_fields list to update a custom field. Published invoices have additional restrictions.
Implementation
Future<Invoice> updateInvoice({
required int invoiceId,
required UpdateInvoiceRequest request,
String? authToken,
}) async {
authToken ??= authenticationService.getCachedToken()?.accessToken;
Map<String, String> headers = {
"Authorization": "Bearer ${authToken ?? ""}",
'Content-Type': 'application/json; charset=UTF-8',
'Accept': 'application/json',
};
Uri endpoint = Uri.https(
baseUrl, "/v2/invoices/$invoiceId");
//print (endpoint.toString());
var response = await
http.put(endpoint, body: jsonEncode(request.toJson()), headers: headers);
if (response.statusCode == 200) {
print (jsonDecode(response.body));
return InvoiceResponse.fromJson(jsonDecode(response.body)).invoice!;
}
else {
print (response.body);
throw InvoiceException(statusCode: response.statusCode, message: InvoiceResponse.fromJson(jsonDecode(response.body)).errors?[0].detail?.toString());
}
}