 +        }
 +    }
 +
-+    my $branch = Koha::Libraries->find({branchcode => $body->{branchcode} });
++    my $branch = Koha::Branches->find({branchcode => $body->{branchcode} });
 +    unless ($branch) {
 +        return $c->$cb({error => "Library with branchcode \"" . $body->{branchcode} . "\" does not exist"}, 404);
 +    }
-+    my $category = Koha::Borrower::Categories->find({ categorycode => $body->{categorycode} });
++    my $category = Koha::Patron::Categories->find({ categorycode => $body->{categorycode} });
 +    unless ($category) {
 +        return $c->$cb({error => "Patron category \"" . $body->{categorycode} . "\" does not exist"}, 404);
 +    }

+    }
+
+    if ($body->{branchcode}) {
+        my $branch = Koha::Libraries->find({branchcode => $body->{branchcode} });
+        unless ($branch) {
+            return $c->$cb({error => "Library with branchcode \"" . $body->{branchcode} . "\" does not exist"}, 404);
+        }
+    }
+
+    if ($body->{categorycode}) {
+        my $category = Koha::Borrower::Categories->find({ categorycode => $body->{categorycode} });
+        unless ($category) {
+            return $c->$cb({error => "Patron category \"" . $body->{categorycode} . "\" does not exist"}, 404);
+        }

 use C4::Auth qw( haspermission );
+use Koha::AuthUtils qw(hash_password);
 use Koha::Borrowers;
+use Koha::Patron::Categories;
+use Koha::Branches;
 
 sub list {
     my ($c, $args, $cb) = @_;
