post method
Post the given data
to Quickbooks Api with the given accessToken
and companyId
.
Parse result in Map<String, dynamic> with the location
given with the posted
data in it.
Implementation
Future<Map<String, dynamic>> post({
required String accessToken,
required String companyId,
required Map<String, dynamic> data,
String location = 'Item',
}) async {
return await http
.post(
Uri.https(
_baseEndpoint,
'$_companyEndpoint$companyId/$_postEndpoint',
{
'minorversion': '65',
},
),
headers: {
'Accept': 'application/json',
'content-type': 'application/json',
'Authorization': 'Bearer $accessToken'
},
body: jsonEncode(data),
)
.then((response) async {
switch (response.statusCode) {
case 200:
Map<String, dynamic> body = jsonDecode(response.body);
Map<String, dynamic> result = body[location];
return result;
default:
throw AlfredException(500, 'Quickbooks error: ${response.body}');
}
});
}