getSubItems method
Future<List<Map<String, dynamic> > >
getSubItems(
- GlpiItemType mainItemtype,
- int mainItemId,
- GlpiItemType subItemType, {
- bool expandDropdowns = false,
- bool getHateoas = true,
- bool onlyId = false,
- int rangeStart = 0,
- int rangeLimit = 50,
- String sort = 'id',
- String order = 'ASC',
- List? addKeysNames,
override
Return the sub-items of subItemType
the item identified by the mainItemId
and of type mainItemtype
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#get-sub-items
Implementation
@override
Future<List<Map<String, dynamic>>> getSubItems(
GlpiItemType mainItemtype, int mainItemId, GlpiItemType subItemType,
{bool expandDropdowns = false,
bool getHateoas = true,
bool onlyId = false,
int rangeStart = 0,
int rangeLimit = 50,
String sort = 'id',
String order = 'ASC',
List? addKeysNames}) 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 range = '$rangeStart-$rangeLimit';
final uri = Uri.parse(
'$host/${mainItemtype.toString().split('.').last}/$mainItemId/${subItemType.toString().split('.').last}?expand_dropdowns=$expandDropdowns&get_hateoas=$getHateoas&only_id=$onlyId&range=$range&sort=$sort&order=$order');
if (addKeysNames != null) {
for (var key in addKeysNames) {
uri.queryParameters.addAll({'add_keys_names[]': key});
}
}
final response = await _innerClient.get(uri, headers: headers);
if (response.statusCode != 200 && response.statusCode != 206) {
throw GlpiException.fromResponse(
response.statusCode, json.decode(response.body));
}
List<dynamic> decodedJson = json.decode(response.body);
List<Map<String, dynamic>> formatted = decodedJson.map((element) {
return element as Map<String, dynamic>;
}).toList();
return Future.value(formatted);
}