addUserToProjectByEmail method

Future<Map<String, dynamic>> addUserToProjectByEmail(
  1. String projectId,
  2. String email, {
  3. bool? isAdmin,
  4. bool? isDeveloper,
  5. bool? canCreateRooms,
})

Corresponds to: POST /accounts/projects/:project_id/users Body: { "project_id", "user_id" } Returns JSON like { "ok": true } on success.

Implementation

Future<Map<String, dynamic>> addUserToProjectByEmail(
  String projectId,
  String email, {
  bool? isAdmin,
  bool? isDeveloper,
  bool? canCreateRooms,
}) async {
  final encodedProjectId = Uri.encodeComponent(projectId);
  final uri = Uri.parse('$baseUrl/accounts/projects/$encodedProjectId/users');
  final body = {
    'project_id': projectId,
    'email': email,
    if (isAdmin != null) "is_admin": isAdmin,
    if (isDeveloper != null) "is_developer": isDeveloper,
    if (canCreateRooms != null) "can_create_rooms": canCreateRooms,
  };

  final response = await httpClient.post(uri, body: jsonEncode(body));

  if (response.statusCode >= 400) {
    throw MeshagentException('Failed to add user to project. Status code: ${response.statusCode}, body: ${response.body}');
  }
  return jsonDecode(response.body) as Map<String, dynamic>;
}