changeActiveEntities method Null safety
- dynamic entitiesId,
- {bool recursive = false}
Allow to change the active entity for the current user.
entitiesId
can either be the numerical id of the entity or all
to load all the entities.
recursive
can be set to true to load all the sub-entities.
Will throw an Exception if the request fails or if the selected id is incorrect.
Reference: https://github.com/glpi-project/glpi/blob/master/apirest.md#change-active-entities
Implementation
Future<bool> changeActiveEntities(dynamic entitiesId,
{bool recursive = false}) async {
if (_sessionToken == null) {
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 _response = await http.post(
Uri.parse('$baseUrl/changeActiveEntities'),
headers: headers,
body: json.encode({'entities_id': entitiesId, 'is_recursive': recursive}),
);
if (_response.statusCode != 200) {
throw Exception('${_response.statusCode} ${_response.body}');
}
return true;
}