addUser method

Future<AddUserResponseDto> addUser(
  1. String apiKey, {
  2. required AddUserRequestDto addUserRequestDto,
})

Implementation

Future<AddUserResponseDto> addUser(
  String apiKey, {
  required AddUserRequestDto addUserRequestDto,
}) async {
  final String url = '$channel/api/v1/mdm/users';

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