getQuery method
Gets the requested query
from Quickbooks Api with the given accessToken
and companyId
.
Parse it in a List<Map<String, dynamic>> with the location
given with the searched
data in it.
Implementation
Future<List<Map<String, dynamic>>> getQuery({
required String query,
required String accessToken,
required String companyId,
String location = 'Item',
}) async {
return await http.get(
Uri.https(
_baseEndpoint,
'$_companyEndpoint$companyId/query',
{
'minorversion': '65',
'query': query,
},
),
headers: {
'Accept': 'application/json',
'content-type': 'text/plain',
'Authorization': 'Bearer $accessToken'
}).then((response) async {
switch (response.statusCode) {
case 200:
Map<String, dynamic> body = jsonDecode(response.body);
List<Map<String, dynamic>> items = [];
try {
items = body["QueryResponse"][location];
} catch (_) {
return [];
}
return items;
default:
throw AlfredException(500, 'Quickbooks error: ${response.body}');
}
});
}