distributeAnnouencementToDevices method

Future<MdmEmpty> distributeAnnouencementToDevices(
  1. String apiKey, {
  2. required String announcementId,
  3. required DistributeAnnouncementToDevicesRequestDto distributeAnnouncementToDevicesRequestDto,
})

Implementation

Future<MdmEmpty> distributeAnnouencementToDevices(
  String apiKey, {
  required String announcementId,
  required DistributeAnnouncementToDevicesRequestDto
      distributeAnnouncementToDevicesRequestDto,
}) async {
  final String url =
      '$channel/api/v1/mdm/announcements/$announcementId/devices';

  final requestDto = distributeAnnouncementToDevicesRequestDto.toJson();
  requestDto.removeWhere((key, value) => value == null);

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

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

  return MdmEmpty();
}