cPanel API 2 Functions - ZoneEdit::add_zone_record

Description

This function adds a new zone record.

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=add_zone_record&domain=example.com&name=sub&cname=example.com&ttl=14400&class=IN&type=CNAME

 LiveAPI PHP Class

$cpanel new CPANEL(); // Connect to cPanel - only do this once.
  
// Add a type "A" zone record to "example.com"
$add_zone_record $cpanel->api2(
    'ZoneEdit''add_zone_record',
 array(
        '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.
  
// Add a type "CNAME" zone record to "example.com"
$add_zone_record $cpanel->api2(
    'ZoneEdit''add_zone_record',
 array(
        'domain' => 'example.com',
        'name' => 'sub',
        'type' => 'CNAME',
        'cname' => 'example.com',
        'ttl' => '14400',
        'class' => 'IN',
  )
);
 
$cpanel new CPANEL(); // Connect to cPanel - only do this once.
  
// Add a type "TXT" Zone Record to "example.com"
$add_zone_record $cpanel->api2(
    'ZoneEdit''add_zone_record',
 array(
        'domain' => 'example.com',
        'name' => 'sub',
        'type' => 'TXT',
        'txtdata' => 'v=nonicethings',
        'ttl' => '14400',
        'class' => 'IN',
  )
);
 
$cpanel new CPANEL(); // Connect to cPanel - only do this once.
  
// Add a type "AAAA" zone record to "example.com"
$add_zone_record $cpanel->api2(
    'ZoneEdit''add_zone_record',
 array(
        '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.
  
// Add a type "SRV" Zone Record to "example.com"
$add_zone_record $cpanel->api2(
    'ZoneEdit''add_zone_record',
 array(
        'domain' => 'example.com',
        'name' => 'autocorrect',
        'type' => 'SRV',
        'txtdata' => 'v=nonicethings',
        'ttl' => '14400',
        'class' => 'IN',
  )
);

 LiveAPI Perl Module

my $cpliveapi = Cpanel::LiveAPI->new(); # Connect to cPanel - only do this once.
  
# Add a type "A" Zone Record to "example.com"
my $add_zone_record $cpliveapi->api2(
    'ZoneEdit''add_zone_record',
{
        'domain' => 'example.com',
        'name' => 'sub',
        'type' => 'A',
        'address' => '10.10.10.10',
        'ttl' => '14400',
        'class' => 'IN',
   }
);
 
# Add a type "AAAA" Zone Record to "example.com"
my $add_zone_record $cpliveapi->api2(
    'ZoneEdit''add_zone_record',
{
        'domain' => 'example.com',
        'name' => 'genesis',
        'type' => 'AAAA',
        '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.
  
# Add a type "CNAME Zone Record to "example.com"
my $add_zone_record $cpliveapi->api2(
    'ZoneEdit''add_zone_record',
{
        '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.
  
# Add a type "TXT" Zone Record to "example.com"
my $add_zone_record $cpliveapi->api2(
    'ZoneEdit''add_zone_record',
{
        'domain' => 'example.com',
        'name' => 'sub',
        'type' => 'TXT',
        'txtdata' => 'v=nonicethings',
        'ttl' => '14400',
        'class' => 'IN',
   }
);
 
my $cpliveapi = Cpanel::LiveAPI->new(); # Connect to cPanel - only do this once.
  
# Add a type "SRV" Zone Record to "example.com"
my $add_zone_record $cpliveapi->api2(
    'ZoneEdit''add_zone_record',
{
        'domain' => 'example.com',
        'name' => 'autodiscover',
        'type' => 'SRV',
        'txtdata' => 'v=nonicethings',
        'ttl' => '14400',
        'class' => 'IN',
   }
);

 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 ourDeprecated cPanel Tag Usage documentation. Examples are only present in order to help developers move from the old cPanel tag system to our LiveAPI.


 Output (JSON)

{
{
  "cpanelresult": {
    "apiversion": 2,
    "func": "add_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

 Parameters 

Type

Description

Possible values

Example

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.

For example, sub if the subdomain is sub.example.com

A valid string.

sub

type

string

Required

The type of record.

  • A
  • CNAME
  • TXT
  • AAAA
  • SRV

A

txtdata

string

The record's text data.

Note:

This parameter is required if the typeparameter's value is TXT or SRV.

A valid string.

 v=nonicethings 

cname

string

The record's canonical name.

Note:

This parameter is required if the typeparameter's value is CNAME.

A valid canonical name.

example.com

address

string

The IP address to map to the record.

Note:

This parameter is required if the typeparameter's value is A or AAAA.

A valid IPv4 or IPv6 address.

10.10.10.10

ttl

integer

The record's time to live.

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

14400

class

string

The record's class.

IN

IN

flatten

 boolean 

Whether to resolve the specified CNAME value with the record's IP address.

 If you do not also set the flatten_to parameter, the system will attempt to resolve the CNAMEautomatically. 

Notes:

  • This parameter is only valid for CNAME records.
  • Only use this parameter when you alter the zone's root record.
  • 1 — Flattened.
  • 0 — Not flattened (call will fail).
 

1

flatten_to

string

The IP address that the specified CNAME will resolve to.

You must use the flatten parameter with this parameter.

Notes:

  • This parameter is only valid for CNAME records.
  • Only use this parameter when you alter the zone's the root record.

A valid IPv4 or IPv6 address.

192.168.0.20

 

Returns

Return

Type

Description

Possible values

Example

result

hash

A hash of the function call's results.

 This hash includes the newserial, statusmessage, and statusparameters. 

 

newserial

integer

The new serial number of the zone file.

 This function returns this parameter in the result hash. 

A positive integer.

2014101603

 statusmsg 

string

A status message from the DNS server.

This function returns this parameter in the result hash.

A string.

 

status

string

Whether the function succeeded.

This function returns this parameter in the result hash.

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

1

reason

string

A reason for failure.

Note:

This function only returns areason value if it failed.

A string that describes the error.

 This is an error message. 

result

 boolean 

Whether the function succeeded.

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

1

 

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

The cPanel Interface

For  cPanel  &  WHM  version  58 Overview The cPanel interface is...

User Preferences

For cPanel & WHM version 58 Overview This document outlines how to access your cPanel...

Manage External Authentications

For cPanel & WHM version 58 Overview Manage credentials Additional documentation...

What is cPanelID?

In This Article:  Overview ServicesHow to get a cPanelID cPanelID External...

Guide to cPanel Interface Customization - cPanel Style Development

Introduction You can develop custom styles that modify the appearance of the cPanel interface....