searchInvoice method

Future<InvoiceResponse> searchInvoice({
  1. required SearchInvoiceRequest request,
  2. String? authToken,
})

Searches for invoices from a location specified in the filter.

You can optionally specify customers in the filter for whom to retrieve invoices. In the current implementation, you can only specify one location and optionally one customer.

The response is paginated. If truncated, the response includes a cursor that you use in a subsequent request to retrieve the next set of invoices.

Implementation

Future<InvoiceResponse> searchInvoice({
  required SearchInvoiceRequest 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/search");

  //print (endpoint.toString());

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

  if (response.statusCode == 200) {
    print (jsonDecode(response.body));
    return InvoiceResponse.fromJson(jsonDecode(response.body));
  }
  else {
    print (response.body);
    throw InvoiceException(statusCode: response.statusCode, message: InvoiceResponse.fromJson(jsonDecode(response.body)).errors?[0].detail?.toString());
  }
}