public static void addMembersToGroups(MoodleGroupUser[] users) throws MoodleRestGroupException, UnsupportedEncodingException, MoodleRestException {
        StringBuilder data=new StringBuilder();
        String functionCall=MoodleCallRestWebService.isLegacy()?MoodleServices.MOODLE_GROUP_ADD_GROUP_MEMBERS:MoodleServices.CORE_GROUP_ADD_GROUP_MEMBERS;
        if (MoodleCallRestWebService.getAuth()==null)
            throw new MoodleRestGroupException();
        else
            data.append(MoodleCallRestWebService.getAuth());
        data.append("&").append(URLEncoder.encode("wsfunction", MoodleServices.ENCODING)).append("=").append(URLEncoder.encode(functionCall, MoodleServices.ENCODING));
        for (int i=0;i<users.length;i++) {
            if (users[i]==null) throw new MoodleRestGroupException();
            if (users[i].getGroupId()<1) throw new MoodleRestGroupException(); else data.append("&").append(URLEncoder.encode("members["+i+"][groupid]", MoodleServices.ENCODING)).append("=").append(URLEncoder.encode(""+users[i].getGroupId(), MoodleServices.ENCODING));
            if (users[i].getUserId()<1) throw new MoodleRestGroupException(); else data.append("&").append(URLEncoder.encode("members["+i+"][userid]", MoodleServices.ENCODING)).append("=").append(URLEncoder.encode(""+users[i].getUserId(), MoodleServices.ENCODING));
        }
        data.trimToSize();
        MoodleCallRestWebService.call(data.toString());
    }