PDA

View Full Version : Adding domains to account through API



villah
01-21-2004, 11:38 PM
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

l0rdphi1
01-22-2004, 08:28 AM
Sure you can. You can do *anything* with the API.

See here (http://www.directadmin.com/forum/showthread.php?s=&postid=10445#post10444) for an example that will delete a subdomain.

This should add one:
<?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. :)

villah
01-22-2004, 09:28 AM
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

DirectAdmin Support
01-22-2004, 09:33 AM
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

l0rdphi1
01-22-2004, 01:16 PM
Originally posted by villah
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.

l0rdphi1
01-22-2004, 01:24 PM
http://www.l0rdphi1.com/tools/httpsocket/examples/example.add_domain.phps

Enjoy.

villah
01-22-2004, 02:57 PM
Great!! Thanks a million!

Hans

dennisc
03-31-2005, 02:13 AM
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.

srelliott
04-25-2005, 11:27 PM
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