submitResponse method

Submit a new response/feedback on behalf of a customer.

options - Response options including customer ID, title, description, and type Returns the submitted response data

Implementation

Future<SubmitResponseResult> submitResponse(SubmitResponseOptions options) async {
  final response = await _post(
    '/api/responses',
    json.encode({
      'clientId': _clientId,
      'customerId': options.customerId,
      'title': options.title,
      'description': options.description,
      'responseTypeId': options.typeId,
      if (options.email != null) 'customerEmail': options.email,
      if (options.name != null) 'customerName': options.name,
    }),
  );

  if (response.statusCode != 200) {
    final error = json.decode(response.body) as Map<String, dynamic>;
    final details = error['details'] as List<dynamic>?;
    final detailsStr = details?.join(', ') ?? '';
    throw Exception(error['error'] ?? detailsStr ?? 'Failed to submit response');
  }

  return SubmitResponseResult.fromJson(
    json.decode(response.body) as Map<String, dynamic>,
  );
}