updateItem method Null safety
- GlpiItemType itemType,
- int id,
- Map<
String, dynamic> data
override
Return an array with the updated item id
and a message.
To correctly format the data, see the examples and the documentation.
Reference: https://github.com/glpi-project/glpi/blob/master/apirest.md#update-items
Implementation
@override
Future<Map<String, String>> updateItem(
GlpiItemType itemType, int id, Map<String, dynamic> data) 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('$host/${itemType.toString().split('.').last}/$id');
final response =
await _innerClient.put(uri, headers: headers, body: json.encode(data));
if (response.statusCode != 200 && response.statusCode != 207) {
throw GlpiException.fromResponse(
response.statusCode, json.decode(response.body));
}
return Future.value(json.decode(response.body));
}