function add_folder($name, $externalid, $parentfolderid = '') {
        // Check parent folder existense first.
        if (empty($parentfolderid)) {
            $parentfolderid = null;
        } else {
            $param = new \Panopto\SessionManagement\GetFoldersById($this->auth, array($parentfolderid));
            $folders = $this->smclient->GetFoldersById($param)->getGetFoldersByIdResult();
            if (!count($folders)) {
                throw new SoapFault('client', "Folder $parentfolderid does not exist.");
            }
        }

        // Add new folder.
        try {
            $param = new \Panopto\SessionManagement\AddFolder($this->auth, $name, $parentfolderid, false);
            $folderid = $this->smclient->AddFolder($param)->getAddFolderResult()->getId();
        } catch(Exception $e) {
            throw new SoapFault('client', $e->getMessage());
        }

        // Update folder external ID.
        try {
            $param = new \Panopto\SessionManagement\UpdateFolderExternalId($this->auth, $folderid, $externalid);
            $this->smclient->UpdateFolderExternalId($param);
        } catch(Exception $e) {
            throw new SoapFault('client', $e->getMessage());
        }

        return $folderid;
    }