getDeviceIdForUser method

Future<GetDeviceForUserResponseDto> getDeviceIdForUser(
  1. String apiKey, {
  2. required GetDeviceForUserRequestDto getDeviceForUserRequestDto,
})

Implementation

Future<GetDeviceForUserResponseDto> getDeviceIdForUser(
  String apiKey, {
  required GetDeviceForUserRequestDto getDeviceForUserRequestDto,
}) async {
  final String url = '$channel/api/v1/mdm/users';

  final requestDto = getDeviceForUserRequestDto.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 GetDeviceForUserResponseDto.fromJson(
    jsonDecode(response.body) as Map<String, dynamic>,
  );
}