Can't create SSL Certificate via API

jwvisser

New member
Joined
Apr 23, 2020
Messages
3
Hi guys,

I am trying to create a SSL Certificate with the option 'Free & automatic certificate from Let's Encrypt' with an API Call. According to the documentation (https://www.directadmin.com/features.php?id=1828) it should be possible.

Below you can find the php code we use for this:
Code:
$this->directAdminSDK->query("CMD_API_SSL", [
            'domain' => 'katest.example.nl',
            'action' => 'save',
            'type' => 'create',
            'request' => 'letsencrypt',
            'country' => '',
            'province' => '',
            'city' => '',
            'company' => '',
            'division' => '',
            'name' => 'katest.example.nl',
            'email' => '',
            'keysize' => '4096',
            'encryption' => 'sha256',
            'le_select0' => 'katest.example.nl',
            'le_select2' => 'mail.katest.example.nl',
            'le_select5' => 'www.katest.example.nl',
            'le_wc_select0' => 'katest.example.nl',
            'le_wc_select1' => '*.katest.example.nl',
            'certificate' => '',
            'submit' => 'save',
        ]);

Based on the directadmin post, we added a few more parameters like country, province etc. But nothing works, the certificatie is not created also there is no error or message in the user account.

I hope someone can help us out and give a working solution.
 
I wonder about this subject too. Can't create SSL certificate with API? If it can be done, thank you in advance to the friend who will present the sample code.
 
What error do you see in the DirectAdmin Error log? I have it working, so I can maybe help.

I have this in PHP:

$sock->method = "POST";

$sock->query('/CMD_API_SSL',
array(
'domain' => $domain,
'action' => 'save',
'type' => 'create',
'request' => 'letsencrypt',
'name' => $domain,
'keysize' => 'secp384r1',
'encryption' => 'SHA256',
'le_select0' => $domain,
'le_select1' => 'www.'.$domain,
'submit' => 'save'
)
);

This creates the Let's Encrypt SSL :)
 
Last edited:
What error do you see in the DirectAdmin Error log? I have it working, so I can maybe help.

I have this in PHP:

$sock->method = "POST";

$sock->query('/CMD_API_SSL',
array(
'domain' => $domain,
'action' => 'save',
'type' => 'create',
'request' => 'letsencrypt',
'name' => $domain,
'keysize' => 'secp384r1',
'encryption' => 'SHA256',
'le_select0' => $domain,
'le_select1' => 'www.'.$domain,
'submit' => 'save'
)
);

This creates the Let's Encrypt SSL :)

I saw the answer a little late, I will try. Thank you so much. ;)
 
I have a problem today with generate let's encrypt through api... I added hundreds of domains with my script and api but today I have an error with one domain... I don't know why...

PHP:
"Array (    [error] => 1    [text] => Can't do this request.    [details] => You do not own that domain )"

But it's added in that user... what should I check? Even if I delete that domain and add again (through API) it can't generate SSL :/

My script:

PHP:
$da->set_method('post');
                    $da->query('/CMD_API_SSL', array('action' => 'save', 'domain' => $domain, 'type' => 'create', 'request' => 'letsencrypt', 'name' => 'www.' . $domain, 'email' => '[email protected]', 'keysize' => '4096', 'encryption' => 'sha256', 'le_select0' => $domain, 'le_select1' => 'www.' . $domain));
DA 1.62.7
PHP 7.4
Version 3.0.4 of http://files1.directadmin.com/services/all/httpsocket/
@smtalk
 
Last edited:
I've got this also after the update and changed it to login as the user, so this need to be changed:

$server_login="admin|".$username;

And then it will work again
 
I've got this also after the update and changed it to login as the user, so this need to be changed:

$server_login="admin|".$username;

And then it will work again
So how should this look if my username of admin is "acdm" ? "admin|acdm" ?
 
A veeery late response from my side. Thanks for the answers, I will try the offered solutions!
 
Did you get it working?

I am having the same issue with this code:

$sock->set_login('admin|apitest','XXXXXXXXXXXX');

$domain = 'api.domain.com';

$sock->method = 'POST';

$sock->query('/CMD_API_SSL',
array(
'action' => 'save',
'domain' => $domain,
'type' => 'create',
'request' => 'letsencrypt',
'name' => $domain,
'keysize' => 'secp384r1',
'encryption' => 'SHA256',
'le_select0' => $domain,
'le_select1' => 'www.'.$domain,
'le_select2' => 'mail.'.$domain,
'submit' => 'save'
)
);

Result:
Array ( [error] => 1 [text] => Cannot Execute Your Request [details] => You do not own that domain )

Cert creation works fine when created manually in the webinterface.

Edit: When using the apitest credentials directly ( $sock->set_login('apitest','XXXXXX'); ), the same error ocours. What am I missing here? Domain is visible under domain setup for that account...
 
Last edited:
The error "You do not own that domain" hints enough in the right direction ;)
I think you don't login as that user where the domain in is and SSL needs to be requested.

apitest needs to be the user and the domain api.domain.com needs to be in that account and SSL needs to be ON for that domain.
Can you verify that?

My working code:
Code:
    $server_login="admin|".$username;
    $sock = new HTTPSocket;
    $sock->connect("ssl://".$server,'2222');
    $sock->set_login($server_login, $server_pass);
    $sock->method = "POST";
  
    $sock->query('/CMD_API_SSL',
            array(
                    'domain' => $domain,
                    'action' => 'save',
                    'type' => 'create',
                    'request' => 'letsencrypt',
                    'name' => $domain,
                    'keysize' => 'secp384r1',
                    'encryption' => 'SHA256',
                    'le_select0' => $domain,
                    'le_select1' => 'www.'.$domain,
                    'submit' => 'save'
            )
    );
 
Back
Top