deleteItem method Null safety
- GlpiItemType itemType,
- int id,
- {bool forcePurge = false,
- bool history = true}
Return the id
of the item deleted with true is the deletion is complete.
forcePurge
will delete the item permanently.
history
set to false will prevent the deletion from being added to the global history.
Implementation
Future<Map<String, String>> deleteItem(GlpiItemType itemType, int id,
{bool forcePurge = false, bool history = true}) async {
if (_sessionToken!.isEmpty) {
throw Exception('No session token, initSession first');
}
final Map<String, String> headers = {
'Session-Token': _sessionToken!,
'Content-Type': 'application/json',
...?appToken != null ? {'App-Token': appToken!} : null,
};
final uri = Uri.parse(
'$baseUrl/${itemType.toString().split('.').last}/$id?force_purge=$forcePurge&history=$history');
final response = await http.delete(uri, headers: headers);
if (response.statusCode != 200 &&
response.statusCode != 204 &&
response.statusCode != 207) {
throw GlpiException.fromResponse(
response.statusCode, json.decode(response.body));
}
return Future.value(json.decode(response.body));
}