deleteOne method

Future<bool> deleteOne({
  1. required String accessToken,
  2. required String companyId,
  3. required String id,
})

Deletes a QuickbooksInvoice with the given accessToken and companyId

Implementation

Future<bool> deleteOne({
  required String accessToken,
  required String companyId,
  required String id,
}) async {
  var data = await get(
    accessToken: accessToken,
    companyId: companyId,
    id: id,
  );

  if (data == null) {
    throw AlfredException(404, 'Data not found');
  }

  return await http
      .post(
    Uri.https(
      baseEndpoint,
      '$companyEndpoint$companyId/$postEndpoint?operation=delete',
      {
        'minorversion': '65',
      },
    ),
    headers: {
      'Accept': 'application/json',
      'content-type': 'application/json',
      'Authorization': 'Bearer $accessToken'
    },
    body: jsonEncode({
      "SyncToken": data.syncToken,
      "Id": data.id,
    }),
  )
      .then((response) async {
    switch (response.statusCode) {
      case 200:
        return true;
      default:
        throw AlfredException(500, 'Quickbooks error: ${response.body}');
    }
  });
}