Can't delete MX record via API

eSupport.org.ua

Verified User
Joined
Oct 4, 2004
Messages
62
Location
UA
Hi!
I was try delete MX record for domain example.com. This is my code:
PHP:
                $sock->query('/CMD_API_DNS_ADMIN',
                    array(
                        'domain' => "example.com",
                        'action' => "select",
                        'mxrecs0' => "name=example.com&value=mail"
                ));
                $result = $sock->fetch_body();
                echo $result;

When I run this code, I receive return:
HTML:
error=0&text=Records Deleted&details=
But record is not deleted from zone.
There is records from DA debug mode:
PHP:
/CMD_API_DNS_ADMIN
 0: Accept: */*
 1: Authorization: Basic ***
 2: Connection: Close
 3: Content-length: 74
 4: Content-type: application/x-www-form-urlencoded
 5: Host: localhost:2222
 6: User-Agent: HTTPSocket/2.7.2
Post string: domain=example.com&action=select&mxrecs0=name%3Dexample.com%26value%3Dmail
Command::doCommand(/CMD_API_DNS_ADMIN)
File /var/named/example.com.db.temp appears ok to named-checkzone
Dynamic(api=1, error=0):
	text='Records Deleted'
	result=''
Command::doCommand(/CMD_API_DNS_ADMIN) : finished
Command::run: finished /CMD_API_DNS_ADMIN

Also I try delete A record:
HTML:
                $sock->query('/CMD_API_DNS_ADMIN',
                    array(
                        'domain' => "example.com",
                        'action' => "select",
                        'arecs0' => "name=localhost&value=127.0.0.1"
                ));
                $result = $sock->fetch_body();
                echo $result;

This works without any problem. So, MX deleting is not full documented or not works.
 
Hello,

Use this guide:
http://help.directadmin.com/item.php?id=356

1) Run DA in debug mode.
2) Delete an MX record normally through the GUI and check to see what the Post string is.
3) Keep DA in debug mode.
4) Delete an MX record using your script.

Check to see what the difference is between your scirpt and the normal request (they should be the same, except CMD_API_ vs CMD_)

John
 
Thanks for quick answer.
There is GUI request:
HTML:
domain=example.com&mxrecs0=name=example.com.&value=10 mail&delete=Delete Selected&action=select
There is script request for API
HTML:
domain=example.com&action=select&mxrecs0=name=example.com&value=10 mail

API is not works and MX record is not deleted.
 
Well, deleting A records works without "&delete". Anyway, I was updated my code:
HTML:
                $sock->query('/CMD_API_DNS_ADMIN',
                    array(
                        'domain' => "example.com",
                        'action' => "select",
                        'mxrecs0' => "example.com&value=mail 10&delete=Delete Selected"

This is not help
 
Try:
Code:
$sock->query('/CMD_API_DNS_ADMIN',
    array(
        'domain' => "example.com",
        'action' => "select",
        'mxrecs0' => "name%3Dexample.com%26value%3Dmail 10",
        [FONT=Verdana]'[/FONT][FONT=Verdana]delete'    => "Delete Selected"[/FONT]
where the mxrecs0 is url encoded.
 
Last edited:
Right code:
PHP:
$sock->query('/CMD_API_DNS_ADMIN',
        array(
                'domain' => 'example.com',
                'action' => 'select',
                'mxrecs0' => 'name=example.com.&value=10 mail',
                'delete' => 'Delete Selected'
    ));
Need use dot after domain in name variable
 
Back
Top