Problems using the API

Hi all, I need to create through API of domains and databases and generate ssl however I can’t do it.
I used this PHP code: https://github.com/hestiacp/hestiacp-api-examples/blob/main/php/add_domain.php
https://github.com/hestiacp/hestiacp-api-examples/blob/main/php/add_database.php
I have a user account with administrator permissions and I used to authenticate both user and password and just hash as mentioned in your knowledge The response I get is always the same ie:

Query returned error code: <html>
<head><title>302 Found</title></head>
<body>
<center><h1>302 Found</h1></center>
<hr><center>nginx</center>
</body>
</html>

To connect to the API I connect from the local server where the HestiaCP control panel is hosted so I have the permission, despite this I added the IP address as well in the permissions for the API.
Also in the CLI and API documentation I did not find how to set web template, backend template and document root customization.
Also there is an anomaly when I create the keys for the API from the hestiaCP panel, i.e. I only find these permissions how come? On the admin accounts. I don’t understand why only these are included.
billing
mail-accounts
phpmyadmin-sso
purge-nginx-cache
sync-dns-cluster
update-dns-records

What do you see if you visit:

https://hostname.com:8083/api/

This error:
Error: data received is null or invalid, check REST API | Hestia Control Panel

That is fine

Can you share the code that you have used for connection to ht api?

  // Prepare POST query
        $postvars = array(
            //'hash' => env('HESTIA_KEY_ID') . ':' . env('HESTIA_SECRET'),
            'user' => 'johndoe',
            'password' => 'password account johndoe',
            'returncode' => 'yes', //I also tried 'no' but nothing changes, still the same 302 message
            'cmd' => 'v-add-domain',
            'arg1' => 'johndoe', //this should be the domain name, I also tried other names and the account username
            'arg2' => 'test.com'
        );

        // Send POST query via cURL
        $postdata = http_build_query($postvars);
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, 'http://127.0.0.1:8083/api/'); //I also tried using the server's IP address or hostname but it's still the same
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
        $answer = curl_exec($curl);

        if ($answer === 0) {
            return "Domain has been successfuly created\n";
        } else {
            return "Query returned error code: " . $answer . "\n";
        }

Use https://

Perfect thanks friend, with https:// I can send api call, however I get this error:

Query returned error code: Error: Key (KEY ID) don’t have permission to run the command v-add-domain

If I go to the user settings from the Hestia panel to the user access keys page, I can only select these permissions, why?
billing
mail-accounts
phpmyadmin-sso
purge-nginx-cache
sync-dns-cluster
update-dns-records

Billing should have the permissions to run v-add-web-domain

If you need more permissions you can create a custom profile or create one via cli and use astrix * as permission

Perfect it works correctly now the domain is created. I have one last question: how do I always set “Web Template”, “Backend Template” from the API when creating the domain and customize the document root? I would like it to point to another domain and a specific folder

Webtemplate / Backend Template can be set with the package

For the costum docroot v-change-web-domain-docroot

The v-change-web-domain-docroot command doesn’t work I get the error with status 401.

Create a new api profile or use

v-add-access-key admin '*'

To get the correct permissions

I can’t execute the command I get these errors, I tried to log into the terminal with both an admin account and a user account.

/usr/local/hestia/func/main.sh: line 1575: /usr/local/hestia/conf/hestia.conf: Permission denied
grep: /usr/local/hestia/conf/hestia.conf: Permission denied
Error: user (USERACCOUNT) doesn't exist
/usr/local/hestia/func/main.sh: line 102: /usr/local/hestia/log/error.log: Permission denied

Run as root

Done already but I get these errors.

admin@manage:~$ sudo /usr/local/hestia/bin/v-add-access-key USERACCOUNT v-change-web-domain-docroot 
Error: API v-change-web-domain-docroot doesn't exist

I don’t want to activate all permissions for security reasons, but only specific permissions.

Should work …

It doesn’t work I always get the same error. How do I solve it?
Error: API v-change-web-domain-docroot doesn't exist

What api key profile do you use?

What do you mean by API profile? How do I create an API profile for an administrator account?

ls /usr/local/hestia/data/api/

Is a list of all command the specific profile can use or run you can create a new one if you want…

For billing it is

ROLE='admin'
COMMANDS='v-add-user,v-delete-user,v-suspend-user,v-unsuspend-user,v-change-user-shell,v-list-user,v-list-users,v-make-tmp-file,v-add-domain,v-change-user-package,v-make-tmp-file,v-change-user-password'

For example