readAllAccounts method

Future<List<BankAccount>> readAllAccounts({
  1. required String requestId,
  2. required String customerId,
  3. String? realmId,
  4. String? authToken,
})

Returns a list of up to ten bank accounts for the company specified with the id parameter. The accounts are returned in descending order with most recent accounts first.

Implementation

Future<List<BankAccount>> readAllAccounts({
  required String requestId,
  required String customerId,
  String? realmId,
  String? authToken,
}) async {
  authToken ??= authenticationService.getCachedToken()?.access_token;
  realmId ??= authenticationService.getCachedRealmId();

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


  //v4/customers/2/bank-accounts
  Uri endpoint = Uri.https(
      baseUrl, "/quickbooks/v4/customers/$customerId/bank-accounts");

  //print (endpoint.toString());

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

  if (response.statusCode == 200) {
    return (jsonDecode(response.body) as List).map((e) => BankAccount.fromJson(e)).toList();
  }
  else {
    throw BankAccountException(statusCode: response.statusCode, message: response.body);
  }
}