Page tree
Skip to end of metadata
Go to start of metadata

 

Description

This function edits a zone record.

Note:

This API function can edit MX records only if the cPanel account has the Ability to Change MX setting enabled in WHM's Feature Manager interface (Home >> Packages >> Feature Manager).

 

Warning:

We strongly recommend that you use UAPI instead of cPanel API 2. However, no equivalent UAPI function exists.

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

Note:

 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',
  ) 
);

Note:

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',
   }
);

Note:

For more information, read our Guide to the LiveAPI System.

 

 cPanel Tag System (deprecated)

Warning:

In cPanel & WHM version 11.30 and later, cPanel tags are deprecated. We strongly recommend that you only use the LiveAPI system to call the cPanel APIs.

cPanel API 2 calls that use cPanel tags vary widely in code syntax and in their output. For more information, read our Deprecated cPanel Tag Usage documentation. Examples are only present in order to help developers move from the old cPanel tag system to our LiveAPI.

 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

Notes:

  • You must URI-encode values.
  • username represents your account-level username.
  • For more information and additional output options, read our Guide to cPanel API 2 documentation or run the cpapi2 --help command. 
  • We introduced this functionality in cPanel & WHM version 56.

 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"
  }
}

Note:

Use cPanel's API Shell interface (Home >> Advanced >> API Shell) to directly test cPanel API calls.

Parameters

ParametersTypeDescriptionPossible valuesExample
lineinteger

Required

The line in the zone file to edit.

A positive integer.5
domainstring

Required

The record's domain.

A valid domain name.example.com
namestring

Required

The record's name, which maps to the subdomain.

A valid string.sub
typestring

Required

The type of record.

  • A
  • AAAA
  • CNAME
  • SRV
  • TXT
A
txtdatastring

The record's text data.

Note:

This parameter is required if the type parameter's value is TXT or SRV.
A valid string.v=blahblahblah
cnamestring

The record's canonical name.

Note:

This parameter is required if the type parameter's value is CNAME.
A valid canonical name.example.com
addressstring

The IP address to map to the record.

Note:

This parameter is required if the type parameter's value is A or AAAA.
A valid IPv4 or IPv6 address.10.10.10.10
ttlinteger

The record's time to live.

This value defaults to 14400.

A valid positive integer that represents the record's time to live, in seconds.14400
classstring

The record's class.

This value defaults to IN.

ININ
preferenceinteger

The mail exchanger's priority value.  

Note:

We added this parameter in cPanel & WHM version 62.

This value defaults to 0.

A positive integer.

Note:

It is common practice to set the priority value to a number divisible by five.

15
exchangestring

The mail exchanger's name.

Note:

We added this parameter in cPanel & WHM version 62.

This value defaults to an empty string.

A valid mail exchanger on the cPanel account.mail.example.com

Returns

Return TypeDescriptionPossible valuesExample
resulthashA hash of the zone record information.The hash includes the newserialstatusmsg, and status returns. 

newserial

integer

The new serial number of the zone file.

The function returns this value in the result hash.

A positive integer.
2014101603

statusmsg

string

A status message from the DNS server.

The function returns this value in the result hash.

A string.
 Click to view...
Bind reloading on hostname using rndc zone: [example.com]\n

status

Boolean

Whether the function succeeded.

The function returns this value in the result hash.

  • 1 — The function succeeded.
  • 0 — The function failed.
1
reasonstring

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.
resultBoolean

Whether the function succeeded.

  • 1 — The function succeeded.
  • 0 — The function failed.
1