Get Any Records
Here’s a PHP example using the PHP SoapClient class:
- Login and Acquire a Session Token [SessionLogin]
- Get a list of All Records [GetANYRecords]
- Logout a Session [SessionLogout]
<?php
# Dynect API SOAP Examples - PHP
# The Base Dynect API2 URL
$base_url = 'https://api2.dynect.net/wsdl/3.0.0/Dynect.wsdl ';
# Connect to the WSDL
$client = new SoapClient($base_url, array('cache_wsdl' => 0));
?>
<?php
/* ##########################
Logging In
------------
To log in to the dynect API you must call SessionLogin with customer name, username and password
Some Returned Values
status - success or failure
data->token - to be used with all other commands
** Complete Documentations can be found at
https://manage.dynect.net/help/docs/api2/soap/
########################## */
$parameters = array(
'parameters' => array(
'user_name'=> 'user_name',
'customer_name' => 'customer_name',
'password' => 'password'
)
);
echo '<b>Logging In</b><br/>';
echo '--------------------------<br/>';
$result = $client->__soapCall('SessionLogin',$parameters);
if(is_soap_fault($result)){
trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
die();
}
$message = $result->msgs;
echo $message->lvl.": ".(isset($message->err_cd) && $message->err_cd != '' ? '('.$message->err_cd.') ' : '').$message->source." - ".$message->info."<br/>";
if($result->status == 'success'){
$token = $result->data->token;
echo '<pre>'; print_r($result->data); echo '</pre>';
} else {
die('Unable to Log in');
}
?>
<?php
/* ##########################
Getting All Records on a zone
------------
To get a list of all records send a GetANYRecords command with the token, zone, and fqdn as paramters
Some Returned Values
status - success or failure
data - object containing a list record type containers each with the rdata, fqdn, record_type, ttl and zone
** Complete Documentations can be found at
https://manage.dynect.net/help/docs/api2/soap/
########################## */
$parameters = array(
'parameters' => array(
'token'=> $token,
'zone' => 'test.com',
'fqdn' => 'test.com'
)
);
echo '<b>Retrieving all Records</b><br/>';
echo '--------------------------<br/>';
$result = $client->__soapCall('GetANYRecords',$parameters);
if(is_soap_fault($result)){
trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
die();
}
$message = $result->msgs;
echo $message->lvl.": ".(isset($message->err_cd) && $message->err_cd != '' ? '('.$message->err_cd.') ' : '').$message->source." - ".$message->info."<br/>";
if($result->status == 'success'){
echo '<pre>'; print_r($result->data); echo '</pre>';
} else {
die('Unable to Get records');
}
?>
<?php
/* ##########################
Logging Out
------------
To log in to the dynect API you must call SessionLogout with the token received at login
Some Returned Values
status - success or failure
** Complete Documentations can be found at
https://manage.dynect.net/help/docs/api2/soap/
########################## */
$parameters = array(
'parameters' => array(
'token'=> $token
)
);
echo '<b>Logging Out</b><br/>';
echo '--------------------------<br/>';
$result = $client->__soapCall('SessionLogout',$parameters);
if(is_soap_fault($result)){
trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
die();
}
$message = $result->msgs;
echo $message->lvl.": ".(isset($message->err_cd) && $message->err_cd != '' ? '('.$message->err_cd.') ' : '').$message->source." - ".$message->info."<br/>";
if($result->status == 'success'){
echo '<pre>'; print_r($result); echo '</pre>';
} else {
die('Unable to Log out');
}
?>
Manage Zones with Node List
Here’s a PHP example using the PHP SoapClient class:
- Login and Acquire a Session Token [SessionLogin]
- Get a List of Zones [GetZones]
- Get a Specific Zone Detail [GetOneZone]
- Add an A record to a node [CreateARecord]
- Publishing a Zone [PublishZone]
- Get a node list under a Zone [GetNodeList]
- Delete a Zone Node [PruneZone]
- Logout a Session [SessionLogout]
<?php
# Dynect API SOAP Examples - PHP
# The Base Dynect API2 URL
$base_url = 'https://api2.dynect.net/wsdl/3.0.0/Dynect.wsdl ';
# Connect to the WSDL
$client = new SoapClient($base_url, array('cache_wsdl' => 0));
?>
<?php
/* ##########################
Logging In
------------
To log in to the dynect API you must call SessionLogin with customer name, username and password
Some Returned Values
status - success or failure
data->token - to be used with all other commands
** Complete Documentations can be found at
https://manage.dynect.net/help/docs/api2/soap/
########################## */
$parameters = array(
'parameters' => array(
'customer_name' => 'customer_name',
'user_name'=> 'user_name',
'password' => 'password'
)
);
echo '<b>Logging In</b><br/>';
echo '--------------------------<br/>';
$result = $client->__soapCall('SessionLogin',$parameters);
if(is_soap_fault($result)){
trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
die();
}
$message = $result->msgs;
echo $message->lvl.": ".(isset($message->err_cd) && $message->err_cd != '' ? '('.$message->err_cd.') ' : '').$message->source." - ".$message->info."<br/>";
if($result->status == 'success'){
$token = $result->data->token;
echo '<pre>'; print_r($result->data); echo '</pre>';
} else {
die('Unable to Log in');
}
?>
<?php
/* ##########################
Get Zones
------------
To get a list of all zones on an account call GetZones with the token from logging in as a parameter
Some Returned Values
status - success or failure
data - Array of objects containing zone,serial_style, serial, and zone_type
** Complete Documentations can be found at
https://manage.dynect.net/help/docs/api2/soap/
########################## */
$parameters = array(
'parameters' => array(
'token'=> $token
)
);
echo '<b>Getting your list of Zones</b><br/>';
echo '--------------------------<br/>';
$result = $client->__soapCall('GetZones',$parameters);
if(is_soap_fault($result)){
trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
die();
}
$message = $result->msgs;
echo $message->lvl.": ".(isset($message->err_cd) && $message->err_cd != '' ? '('.$message->err_cd.') ' : '').$message->source." - ".$message->info."<br/>";
if($result->status == 'success'){
echo '<pre>'; print_r($result->data); echo '</pre>';
} else {
die('Unable to Get Zones list');
}
?>
<?php
/* ##########################
Get a Specific Zone detail
------------
To get a list of all zones on an account call GetOneZone with the token from logging in and the zone as a parameter
Some Returned Values
status - success or failure
data - object containing zone,serial_style, serial, and zone_type
** Complete Documentations can be found at
https://manage.dynect.net/help/docs/api2/soap/
########################## */
$parameters = array(
'parameters' => array(
'token'=> $token,
'zone' => 'test.com'
)
);
echo '<b>Fetching Details about your Zone</b><br/>';
echo '--------------------------<br/>';
$result = $client->__soapCall('GetOneZone',$parameters);
if(is_soap_fault($result)){
trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
die();
}
$message = $result->msgs;
echo $message->lvl.": ".(isset($message->err_cd) && $message->err_cd != '' ? '('.$message->err_cd.') ' : '').$message->source." - ".$message->info."<br/>";
if($result->status == 'success'){
echo '<pre>'; print_r($result->data); echo '</pre>';
} else {
die('Unable to Get Zone Data');
}
?>
<?php
/* ##########################
Add an A record to a node
------------
To add an A record to a zone send a CreateARecord with the token from logging in and following paramters
{
'fqdn' => 'www.example.com',
'rdata' => { 'address' => '1.2.3.4', },
'ttl' => '3600',
'zone' => 'example.com',
}
Some Returned Values
status - success or failure
data - object containing record_id, rdata, record_type, fqdn, and zone
** Complete Documentations can be found at
https://manage.dynect.net/help/docs/api2/soap/
########################## */
$parameters = array(
'parameters' => array(
'token'=> $token,
'fqdn' => 'foo.test.com',
'rdata' => array( 'address' => '1.2.3.4' ),
'ttl' => '3600',
'zone' => 'test.com'
)
);
echo '<b>Adding A Record to Zone Node</b><br/>';
echo '--------------------------<br/>';
$result = $client->__soapCall('CreateARecord',$parameters);
if(is_soap_fault($result)){
trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
die();
}
$message = $result->msgs;
echo $message->lvl.": ".(isset($message->err_cd) && $message->err_cd != '' ? '('.$message->err_cd.') ' : '').$message->source." - ".$message->info."<br/>";
if($result->status == 'success'){
echo '<pre>'; print_r($result->data); echo '</pre>';
} else {
die('Unable to Create A Record');
}
?>
<?php
/* ##########################
Add an A record to a node
------------
To add an A record to a zone send a CreateARecord with the token from logging in and following paramters
{
'fqdn' => 'www.example.com',
'rdata' => { 'address' => '1.2.3.4', },
'ttl' => '3600',
'zone' => 'example.com',
}
Some Returned Values
status - success or failure
data - object containing record_id, rdata, record_type, fqdn, and zone
** Complete Documentations can be found at
https://manage.dynect.net/help/docs/api2/soap/
########################## */
$parameters = array(
'parameters' => array(
'token'=> $token,
'fqdn' => 'bar.foo.test.com',
'rdata' => array( 'address' => '5.5.5.5' ),
'ttl' => '3600',
'zone' => 'test.com'
)
);
echo '<b>Adding A Record to Zone Node</b><br/>';
echo '--------------------------<br/>';
$result = $client->__soapCall('CreateARecord',$parameters);
if(is_soap_fault($result)){
trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
die();
}
$message = $result->msgs;
echo $message->lvl.": ".(isset($message->err_cd) && $message->err_cd != '' ? '('.$message->err_cd.') ' : '').$message->source." - ".$message->info."<br/>";
if($result->status == 'success'){
echo '<pre>'; print_r($result->data); echo '</pre>';
} else {
die('Unable to Create A Record');
}
?>
<?php
/* ##########################
Publishing a zone
------------
To commit changes and publish a zone you must send a PublishZone command with the token and zone as paramters
Some Returned Values
status - success or failure
data - object containing serial, serial_style, zone, zone_type
** Complete Documentations can be found at
https://manage.dynect.net/help/docs/api2/soap/
########################## */
$parameters = array(
'parameters' => array(
'token'=> $token,
'zone' => 'test.com'
)
);
echo '<b>Publishing Zone</b><br/>';
echo '--------------------------<br/>';
$result = $client->__soapCall('PublishZone',$parameters);
if(is_soap_fault($result)){
trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
die();
}
$message = $result->msgs;
echo $message->lvl.": ".(isset($message->err_cd) && $message->err_cd != '' ? '('.$message->err_cd.') ' : '').$message->source." - ".$message->info."<br/>";
if($result->status == 'success'){
echo '<pre>'; print_r($result->data); echo '</pre>';
} else {
die('Unable to Publish Zone');
}
?>
<?php
/* ##########################
Get a node list under a zone
------------
To get a list of nodes under a zone send a GetNodeList command with the token, zone and optional fqdn as parameters
Some Returned Values
status - success or failure
** Complete Documentations can be found at
https://manage.dynect.net/help/docs/api2/soap/
########################## */
$parameters = array(
'parameters' => array(
'token'=> $token,
'zone' => 'test.com',
)
);
echo '<b>Fetching Nodes under your Zone</b><br/>';
echo '--------------------------<br/>';
$result = $client->__soapCall('GetNodeList',$parameters);
if(is_soap_fault($result)){
trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
die();
}
$message = $result->msgs;
echo $message->lvl.": ".(isset($message->err_cd) && $message->err_cd != '' ? '('.$message->err_cd.') ' : '').$message->source." - ".$message->info."<br/>";
if($result->status == 'success'){
echo '<pre>'; print_r($result); echo '</pre>';
} else {
die('Unable to Fetch Zone Nodes');
}
?>
<?php
/* ##########################
Get a node list under a zone
------------
To get a list of nodes under a zone send a GetNodeList command with the token, zone and optional fqdn as parameters
Some Returned Values
status - success or failure
** Complete Documentations can be found at
https://manage.dynect.net/help/docs/api2/soap/
########################## */
$parameters = array(
'parameters' => array(
'token'=> $token,
'zone' => 'test.com',
'fqdn' => 'foo.test.com'
)
);
echo '<b>Fetching Nodes under your Zone</b><br/>';
echo '--------------------------<br/>';
$result = $client->__soapCall('GetNodeList',$parameters);
if(is_soap_fault($result)){
trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
die();
}
$message = $result->msgs;
echo $message->lvl.": ".(isset($message->err_cd) && $message->err_cd != '' ? '('.$message->err_cd.') ' : '').$message->source." - ".$message->info."<br/>";
if($result->status == 'success'){
echo '<pre>'; print_r($result); echo '</pre>';
} else {
die('Unable to Fetch Zone Nodes');
}
?>
<?php
/* ##########################
Deleting a Zone node
------------
To remove a zone node you must send the PruneZone command with the token and zone as paramters
Some Returned Values
status - success or failure
data - object containing serial, serial_style, zone, zone_type
** Complete Documentations can be found at
https://manage.dynect.net/help/docs/api2/soap/
########################## */
$parameters = array(
'parameters' => array(
'token'=> $token,
'fqdn' => 'foo.test.com',
'zone' => 'test.com'
)
);
echo '<b>Deleting Zone Node</b><br/>';
echo '--------------------------<br/>';
$result = $client->__soapCall('PruneZone',$parameters);
if(is_soap_fault($result)){
trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
die();
}
$message = $result->msgs;
echo $message->lvl.": ".(isset($message->err_cd) && $message->err_cd != '' ? '('.$message->err_cd.') ' : '').$message->source." - ".$message->info."<br/>";
if($result->status == 'success'){
echo '<pre>'; print_r($result->data); echo '</pre>';
} else {
die('Unable to Publish Zone');
}
?>
<?php
/* ##########################
Publishing a zone
------------
To commit changes and publish a zone you must send a PublishZone command with the token and zone as paramters
Some Returned Values
status - success or failure
data - object containing serial, serial_style, zone, zone_type
** Complete Documentations can be found at
https://manage.dynect.net/help/docs/api2/soap/
########################## */
$parameters = array(
'parameters' => array(
'token'=> $token,
'zone' => 'test.com'
)
);
echo '<b>Publishing Zone</b><br/>';
echo '--------------------------<br/>';
$result = $client->__soapCall('PublishZone',$parameters);
if(is_soap_fault($result)){
trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
die();
}
$message = $result->msgs;
echo $message->lvl.": ".(isset($message->err_cd) && $message->err_cd != '' ? '('.$message->err_cd.') ' : '').$message->source." - ".$message->info."<br/>";
if($result->status == 'success'){
echo '<pre>'; print_r($result->data); echo '</pre>';
} else {
die('Unable to Publish Zone');
}
?>
<?php
/* ##########################
Logging Out
------------
To log in to the dynect API you must call SessionLogout with the token received at login
Some Returned Values
status - success or failure
** Complete Documentations can be found at
https://manage.dynect.net/help/docs/api2/soap/
########################## */
$parameters = array(
'parameters' => array(
'token'=> $token
)
);
echo '<b>Logging Out</b><br/>';
echo '--------------------------<br/>';
$result = $client->__soapCall('SessionLogout',$parameters);
if(is_soap_fault($result)){
trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
die();
}
$message = $result->msgs;
echo $message->lvl.": ".(isset($message->err_cd) && $message->err_cd != '' ? '('.$message->err_cd.') ' : '').$message->source." - ".$message->info."<br/>";
if($result->status == 'success'){
echo '<pre>'; print_r($result); echo '</pre>';
} else {
die('Unable to Log out');
}
?>