getCustomers method
Returns a list of all WooCustomer, with filter options.
Related endpoint: https://woocommerce.github.io/woocommerce-rest-api-docs/#customers
Implementation
Future<List<WooCustomer>> getCustomers(
{int? page,
int? perPage,
String? search,
List<int>? exclude,
List<int>? include,
int? offset,
String? order,
String? orderBy,
//String email,
String? role}) async {
Map<String, dynamic> payload = {};
({
'page': page, 'per_page': perPage, 'search': search,
'exclude': exclude, 'include': include, 'offset': offset,
'order': order, 'orderby': orderBy, //'email': email,
'role': role,
}).forEach((k, v) {
if (v != null) payload[k] = v.toString();
});
List<WooCustomer> customers = [];
_setApiResourceUrl(path: 'customers', queryParameters: payload);
final response = await get(queryUri.toString());
_printToLog('response gotten : ' + response.toString());
for (var c in response) {
var customer = WooCustomer.fromJson(c);
_printToLog('customers here : ' + customer.toString());
customers.add(customer);
}
return customers;
}