How to add a MySQL database, user, and set privileges in CyberPanel via command line or API?

I’m looking for a way to add a database, create a database user, and set user and database privileges in CyberPanel using either CLI or the CyberPanel API.

In cPanel I can use the “uapi” command to do this. For instance I can use ssh2_exec() to execute this command with a given $db_name, $db_user, $db_password.

First I can connect via SSH using ssh2_connect and a given $domain, $ssh_port, $username, $password.

$connection = ssh2_connect($domain, $ssh_port);
ssh2_auth_password($connection, $username, $password);

Then I can create the database, the user, and set privileges using uapi.

$stream = ssh2_exec($connection, "cd public_html; uapi Mysql create_database name=$db_name; uapi Mysql create_user name=$db_user password=$db_password; uapi Mysql set_privileges_on_database user=$db_user database=$db_name privileges=ALL");

Is there any way to do something like this in CyberPanel?

If one cannot delete the user via the API, can one just execute “sudo userdel -r [username]” as root? Would what be the best solution here, to delete a user? I don’t know if there’s any potential conflicts or not with using userdel.