cPanel API 2 Functions - ZoneEdit::edit_zone_record
The cPanel API 2 system is deprecated. We strongly recommend that you use UAPI instead of cPanel API 2.
Description
This function edits a zone record.
Examples
WHM API (JSON)
https://hostname.example.com:2087/cpsess###########/json-api/cpanel?cpanel_jsonapi_user=user&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=ZoneEdit&cpanel_jsonapi_func=edit_zone_record&Line=5&domain=example.com&name=sub&type=A&txtdata=v=blahblahblah&cname=example.com&address=10.10.10.10&ttl=14400&class=IN
For more information, read our Calls from the WHM API documentation.
LiveAPI PHP Class
$cpanel = new CPANEL(); // Connect to cPanel - only do this once.
// Edit a type "A" zone record on "example.com"
$edit_zone_record = $cpanel->api2(
'ZoneEdit', 'edit_zone_record',
array(
'Line' => '5',
'domain' => 'example.com',
'name' => 'sub',
'type' => 'A',
'address' => '10.10.10.10',
'ttl' => '14400',
'class' => 'IN',
)
);
$cpanel = new CPANEL(); // Connect to cPanel - only do this once.
// Edit a type "CNAME" zone record on "example.com"
$edit_zone_record = $cpanel->api2(
'ZoneEdit', 'edit_zone_record',
array(
'Line' => '5',
'domain' => 'example.com',
'name' => 'sub',
'type' => 'CNAME',
'cname' => 'example.com',
'ttl' => '14400',
'class' => 'IN',
)
);
$cpanel = new CPANEL(); // Connect to cPanel - only do this once.
// Edit a type "TXT" Zone Record on "example.com"
$edit_zone_record = $cpanel->api2(
'ZoneEdit', 'edit_zone_record',
array(
'Line' => '5',
'domain' => 'example.com',
'name' => 'sub',
'type' => 'TXT',
'txtdata' => 'v=blahblahblah',
'ttl' => '14400',
'class' => 'IN',
)
);
$cpanel = new CPANEL(); // Connect to cPanel - only do this once.
// Edit a type "AAAA" Zone Record on "example.com"
$edit_zone_record = $cpanel->api2(
'ZoneEdit', 'edit_zone_record',
array(
'Line' => '5',
'domain' => 'example.com',
'name' => 'genesis',
'type' => 'AAAA',
'address' => 'abac:abab:acab:abac:abab:acab:abac:ab11',
'ttl' => '14400',
'class' => 'IN',
)
);
$cpanel = new CPANEL(); // Connect to cPanel - only do this once.
// Edit a type "SRV" Zone Record on "example.com"
$edit_zone_record = $cpanel->api2(
'ZoneEdit', 'edit_zone_record',
array(
'Line' => '5',
'domain' => 'example.com',
'name' => 'autocorrect',
'type' => 'SRV',
'txtdata' => 'v=blahblahblah',
'ttl' => '14400',
'class' => 'IN',
)
);
$cpanel = new CPANEL(); // Connect to cPanel - only do this once.
// Edit a type "CAA" Zone Record on "example.com"
$edit_zone_record = $cpanel->api2(
'ZoneEdit', 'edit_zone_record',
array(
'domain' => 'example.com',
'name' => 'autocorrect',
'type' => 'CAA',
'flag' => '0',
'tag' => 'issue',
'value' => 'totallyrealca.tld',
'ttl' => '14400',
'class' => 'IN',
)
);
For more information, read our Guide to the LiveAPI System.
LiveAPI Perl Module
my $cpliveapi = Cpanel::LiveAPI->new(); # Connect to cPanel - only do this once.
# Edit a type "A" Zone Record on "example.com"
my $edit_zone_record = $cpliveapi->api2(
'ZoneEdit', 'edit_zone_record',
{
'Line' => '5',
'domain' => 'example.com',
'name' => 'sub',
'type' => 'A',
'address' => '10.10.10.10',
'ttl' => '14400',
'class' => 'IN',
}
);
my $cpliveapi = Cpanel::LiveAPI->new(); # Connect to cPanel - only do this once.
# Edit a type "CNAME Zone Record on "example.com"
my $add_zone_record = $cpliveapi->api2(
'ZoneEdit', 'edit_zone_record',
{
'Line' => '5',
'domain' => 'example.com',
'name' => 'sub',
'type' => 'CNAME',
'cname' => 'example.com',
'ttl' => '14400',
'class' => 'IN',
}
);
my $cpliveapi = Cpanel::LiveAPI->new(); # Connect to cPanel - only do this once.
# Edit a type "TXT" Zone Record on "example.com"
my $edit_zone_record = $cpliveapi->api2(
'ZoneEdit', 'edit_zone_record',
{
'Line' => '5',
'domain' => 'example.com',
'name' => 'sub',
'type' => 'TXT',
'txtdata' => 'v=blahblahblah',
'ttl' => '14400',
'class' => 'IN',
}
);
my $cpliveapi = Cpanel::LiveAPI->new(); # Connect to cPanel - only do this once.
# Edit a type "AAAA" Zone Record on "example.com"
my $add_zone_record = $cpliveapi->api2(
'ZoneEdit', 'edit_zone_record',
{
'Line' => '5',
'domain' => 'example.com',
'name' => 'genesis',
'type' => 'CNAME',
'address' => 'abac:abab:acab:abac:abab:acab:abac:ab11',
'ttl' => '14400',
'class' => 'IN',
}
);
my $cpliveapi = Cpanel::LiveAPI->new(); # Connect to cPanel - only do this once.
# Edit a type "TXT" Zone Record on "example.com"
my $edit_zone_record = $cpliveapi->api2(
'ZoneEdit', 'edit_zone_record',
{
'Line' => '5',
'domain' => 'example.com',
'name' => 'autocorrect',
'type' => 'SRV',
'txtdata' => 'v=blahblahblah',
'ttl' => '14400',
'class' => 'IN',
}
);
my $cpliveapi = Cpanel::LiveAPI->new(); # Connect to cPanel - only do this once.
# Edit a type "CAA" Zone Record on "example.com"
my $edit_zone_record = $cpliveapi->api2(
'ZoneEdit', 'edit_zone_record',
{
'domain' => 'example.com',
'name' => 'autocorrect',
'type' => 'CAA',
'flag' => '0',
'tag' => 'issue'
'value' => 'totallyrealca.tld'
'ttl' => '14400',
'class' => 'IN',
}
);
# Edit a type "MX" Zone Record on "example.com"
my $edit_zone_record = $cpliveapi->api2(
'ZoneEdit', 'edit_zone_record',
{
'domain' => 'example.com',
'name' => 'autocorrect',
'type' => 'MX',
'exchange' => '0',
'preference' => '10',
'ttl' => '14400',
'class' => 'IN',
}
);
For more information, read our Guide to the LiveAPI System.
cPanel Tag System (deprecated)
- cPanel tags are deprecated . We strongly recommend that you only use the LiveAPI system to call the cPanel APIs. Examples are only present in order to help developers move from the old cPanel tag system to our LiveAPI .
- cPanel API 2 calls that use cPanel tags vary in code syntax and in their output.
- For more information, read our Deprecated cPanel Tag Usage documentation.
Command Line
cpapi2 --user=username ZoneEdit edit_zone_record Line=5 domain=example.com name=sub type=A txtdata=v%3Dblahblahblah cname=example.com address=10.10.10.10 ttl=14400 class=IN
- You must URI-encode values.
-
username
represents your account-level username. -
You
must
include the
--user=username
option. -
For more information and additional output options, read our
Guide to cPanel API 2
documentation or run the
cpapi2 --help
command. -
If you run CloudLinux™, you
must
use the full path of the
cpapi2
command:/usr/local/cpanel/bin/cpapi2
Output (JSON)
{
"cpanelresult": {
"apiversion": 2,
"func": "edit_zone_record",
"data": [
{
"result": {
"newserial": 2014101603,
"statusmsg": "Bind reloading on hostname using rndc zone: [example.com]\n",
"status": 1
}
}
],
"event": {
"result": 1
},
"module": "ZoneEdit"
}
}
Use cPanel's API Shell interface (cPanel >> Home >> Advanced >> API Shell) to directly test cPanel API calls.
Parameters
Parameters | Type | Description | Possible values | Example |
---|---|---|---|---|
line |
integer | Required The line in the zone file to edit. |
A positive integer. | 5 |
domain |
string | Required The record's domain. |
A valid domain name. | example.com |
name |
string | Required The record's name, which maps to the subdomain. |
A valid string. | sub |
type |
string | Required The record type. |
Note:
This function can only edit AAAA, MX, and SRV records if the cPanel account's hosting provider enables the following settings in WHM's Feature Manager interface (WHM >> Home >> Packages >> Feature Manager): |
A |
txtdata |
string |
The record's text data. Note:
This parameter is required if you use
TXT as the type parameter's value. |
A valid string. | v=blahblahblah |
target |
string |
The service's target host. Notes:
|
A valid hostname. | subdomain.example.com |
weight |
integer |
A relative weight. The system uses this value to rank entries with the same Note:
This parameter is required if you use
SRV as the type parameter's value.
|
A positive integer that represents the target host's weight against other hosts with the same priority value. |
1 |
port |
integer |
The target host's port. Note:
This parameter is required if you use
SRV as the type parameter's value. |
A positive integer thats represents a port number. Note:
For a complete list of ports, read our How to Configure Your Firewall for cPanel Services documentation. |
443 |
priority |
integer |
The service record's priority value. Note:
This parameter is required if you use
SRV as the type parameter's value.
|
A positive integer that represents the target host's priority order . | 1 |
cname |
string |
The record's canonical name. Note:
This parameter is required if you use
cname as the type parameter's value.
|
A valid canonical name. | example.com |
address |
string |
The IP address to map to the record. Note:
This parameter is required if you use
A or AAAA as the type parameter's value.
|
A valid IPv4 or IPv6 address. | 10.10.10.10 |
flag |
integer |
Whether the CA will issue an SSL certificate. Notes:
|
|
0 |
tag |
string |
The CAA record's property type. Notes:
|
|
issue |
value |
string |
The CA's domain or URL. Notes:
|
|
totallyrealca.ca |
ttl |
integer | The record's time to live (TTL). This value defaults to |
A valid positive integer that represents the record's TTL, in seconds. | 14400 |
class |
string | The record's class. This value defaults to |
IN |
IN |
preference |
integer |
The mail exchanger's priority value. Note:
This value defaults to |
A positive integer. Note:
We recommend that you set the priority value to a number divisible by five.
|
15 |
exchange |
string |
The mail exchanger's name. Note:
This value defaults to an empty string. |
A valid mail exchanger on the cPanel account. | mail.example.com |
Returns
Return | Type | Description | Possible values | Example |
---|---|---|---|---|
result |
hash | A hash of the zone record information. | The hash includes the newserial , statusmsg , and status returns. |
|
|
integer | The zone file's new serial number. The function returns this value in the |
A positive integer. | 2014101603 |
|
string | A status message from the DNS server. The function returns this value in the |
A string. | Bind reloading on hostname using rndc zone: [example.com]\n
|
|
Boolean | Whether the function succeeded. The function returns this value in the |
|
1 |
reason |
string |
A reason for failure. Note:
This function only returns a
reason value if it failed.
|
A string that describes the error. |
This is an error message. |
result |
Boolean | Whether the function succeeded. |
|
1 |