getOne method
Gets the requested data from Quickbooks Api with the given accessToken
, companyId
ans id
.
Parse it in a List<Map<String, dynamic>> with the location
given with the searched
data in it.
Implementation
Future<Map<String, dynamic>?> getOne({
required String accessToken,
required String companyId,
required String id,
String location = 'Item',
}) async {
return await http.get(
Uri.https(
_baseEndpoint,
'$_companyEndpoint$companyId/$_postEndpoint/$id',
{
'minorversion': '65',
},
),
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);
Map<String, dynamic> result = body[location];
return result;
case 400:
return null;
default:
throw AlfredException(500, 'Quickbooks error: ${response.body}');
}
});
}