Adding domains to account through API

villah

Verified User
Joined
Jan 2, 2004
Messages
29
Hi,
Does the API allow for additional domains to be added to an existing account? We use ModernBill together with DA, which all seems to work fine when creating accounts. But Ii haven't been able to figure out how to add an extra domain through MB.

Thanks!
Hans
 
Sure you can. You can do *anything* with the API.

See here for an example that will delete a subdomain.

This should add one:
PHP:
<?php

include 'httpsocket.php';

$sock = new HTTPSocket;
$sock->connect('yoursite.com',2222);

$sock->set_login("admin|{username}","{admin_password}");

$sock->set_method('POST');

$sock->query('/CMD_SUBDOMAIN',array( 'action' => 'create',
	'domain' => '{parent_domain}', 'subdomain' => '{subdomain_name}' ));
$result = $sock->fetch_result();

echo $result;

?>
Remember, {username} needs replaced with the owner of {parent_domain}, {parent_domain} is the domain we're creating the sub on, {admin_password} should be your 'admin' login password, and {subdomain_name} is the name of the new sub. :)
 
Does that also work for additional domains? Eg a client has domain123.com and I want to add domains123.tv through the API. Can it be used for that?

Hans
 
Hello,

It can be used for anything that you normally do through a web browser. The only difference is that some functions wont return data that will let you know if it worked (will return a big html file instead, which isn't easily parseable ;))

John
 
villah said:
Does that also work for additional domains? Eg a client has domain123.com and I want to add domains123.tv through the API. Can it be used for that?

Hans
Sure. Sure it can. Silly 'ol me t'was thinking you were after subdomains. *sigh*

I'll post something shortly.
 
Hello folks,

I've got the following problem:

Let's assume I have an admin called "admin1" with pass "admin1" and a user called "user1" with pass "user1".

User1 has been added with domain1.tld. Now I need to add domain2.tld to user1 as well.

If I do it like this..


$create = new HTTPSocket;
$create->connect('ssl://HOST.DOMAIN.TLD',2222);
$create->set_login("admin|user1","admin1");
$create->set_method('POST');
$create->query('/CMD_API_DOMAIN',
array(
'action' => 'create',
'domain' => 'domain2.tld',
'ubandwidth' => 'unlimited',
'uquota' => 'unlimited',
'ssl' => 'ON',
'cgi' => 'ON',
'php' => 'ON',
'create' => 'Create'
));

..I get the error that I have no permissions [while user1 _has_ rights to add domain2.tld within DA] to do that.

If I replace "$create->set_login("admin|user1","admin1");" with "$create->set_login("admin|admin1","admin1");" the domain is added to admin and that's not what I need. Is there any solution to this? Thanks for your time.
 
Hello,

I'm a total beginner here.

It looks like it's possible to automatically create a subdomain when a domain is created. For instance, I want all new domains created to have email.domain.TLD.

I want domain_create_post.sh in /usr/local/directadmin/scripts/custom to call the file with the subdomain API call.

Let's assume we want to create the subdomain email for mydomain.com -- email.mydomain.com

My questions are:

1) What extension should the API file be?
2) How do you call the API file from within domain_create_post.sh ?
3) How do you specify the domain to add the subdomain to?
4) Please fix the bad start of the following script so it actually works.



<?php

include 'httpsocket.php';

$sock = new HTTPSocket;
$sock->connect(www.domain.TLD',2222);

$sock->set_login("admin|$username",$password);

$sock->set_method('POST');

$sock->query('/CMD_SUBDOMAIN',
array(
'action' => 'create',
'domain' => email,
'create' => 'Create'
));
$result = $sock->fetch_body();

echo $result;

?>


Thank you from the bottom of my heart,

Shannon
 
Hello, this link is not working. Is it possible to share an up-to-date code sample to add Add-on domains with API?

Look at the post, since 2004... and 16 years later I believe the code is outdated. I remember 2004 is my first time having an old Windows 98 desktop CPU. By the way, if you are looking for sample php code API (official), this is it: http://files.directadmin.com/services/all/httpsocket/examples/. It has sample to add domains there.
 
Yes, you are right. Since I could not find a source, I had to revive the 2004 issue. I can add new domains with API. But what I want is to add a plugin domain. So I am looking for adding code with Domain Pointers API as I show in the picture below. There are domain or subdomain addition codes everywhere. I could not find what I was looking for.

2020-12-28_18-58-03.png
 
Yes, you are right. Since I could not find a source, I had to revive the 2004 issue. I can add new domains with API. But what I want is to add a plugin domain. So I am looking for adding code with Domain Pointers API as I show in the picture below. There are domain or subdomain addition codes everywhere. I could not find what I was looking for.

View attachment 4011
Does this help? https://www.directadmin.com/features.php?id=382.

I wish DA would have written more examples on how to use this API especially using python or bash. Most of the example I've seen using only PHP. When API is easier to use, more developers will develop plugins for DA = profit.
 
I finally did. The command I need is CMD_API_DOMAIN_POINTER. I've been looking for the solution far away :)

<?php
include 'httpsocket.php';
$sock = new HTTPSocket;
$sock->connect('ssl://hostname.com',2222);
$sock->set_login("admin","password");
$sock->set_method('POST');
$sock->query('/CMD_API_DOMAIN_POINTER',
array(
'domain' => 'maindomain name',
'action' => 'add',
'from' => 'addon domain name',
'alias' => 'yes'
));
$result = $sock->fetch_body();
echo $result;
?>
 
I finally did. The command I need is CMD_API_DOMAIN_POINTER. I've been looking for the solution far away :)

<?php
include 'httpsocket.php';
$sock = new HTTPSocket;
$sock->connect('ssl://hostname.com',2222);
$sock->set_login("admin","password");
$sock->set_method('POST');
$sock->query('/CMD_API_DOMAIN_POINTER',
array(
'domain' => 'maindomain name',
'action' => 'add',
'from' => 'addon domain name',
'alias' => 'yes'
));
$result = $sock->fetch_body();
echo $result;
?>

Good job. Keep sharing what you have done. So more people will enjoy using Directadmin. We need more people to help each other in this forum.
 
Good job. Keep sharing what you have done. So more people will enjoy using Directadmin. We need more people to help each other in this forum.
Absolutely I agree. Today in this forum I got help from people who are not information stingy and took care of my work. Likewise, I will contribute. We say that in Turkey; directadmin is our life, the rest is excitement. I may not be able to explain it in terms of translation, but the Turkish is as follows; DirectAdmin Candır Gerisi heyecan... :)
 
Back
Top