getDeviceConfiguration method

Future<GetDeviceConfigurationResponseDto> getDeviceConfiguration(
  1. String apiKey, {
  2. required String deviceId,
  3. required GetDeviceConfigurationRequestDto getDeviceConfigurationRequestDto,
})

Implementation

Future<GetDeviceConfigurationResponseDto> getDeviceConfiguration(
  String apiKey, {
  required String deviceId,
  required GetDeviceConfigurationRequestDto getDeviceConfigurationRequestDto,
}) async {
  final String url =
      '$channel/api/v1/mdm/devices/$deviceId/configurationprofiles';

  // need to remove null values from the request
  final requestDto = getDeviceConfigurationRequestDto.toJson();
  requestDto.removeWhere((key, value) => value == null);

  final response = await http.get(
    Uri.parse(url).replace(
      queryParameters: requestDto.isEmpty ? null : requestDto,
    ),
    headers: {
      'Authorization': 'Zoho-oauthtoken $apiKey',
      'Content-Type': 'application/json;charset=UTF-8',
    },
  );

  if (!response.statusCode.isSuccessful) {
    throw MdmEngineException(
      method: response.request?.method,
      url: url,
      statusCode: response.statusCode,
      error: response.body,
    );
  }

  return GetDeviceConfigurationResponseDto.fromJson(
    jsonDecode(response.body) as Map<String, dynamic>,
  );
}