Understanding How The API Works
Login Resources | Manage Zones |
Manage A Records | Manage Zones with Node List |
Get Any Record | Secondary Zones |
PHP Examples – Login ResourcesHere’s a PHP example calling REST resources to:
Click to view the example code. <?php # Dynect API REST Examples - PHP # All examples utilize JSON for the data formating. # Output assumes use of PHP CLI # The Base Dynect API URL - All rest commands will be appended $base_url = 'https://api2.dynect.net/REST'; ?> <?php /* ########################## Logging In ------------ To log in to the DynECT API you must first create a session via a POST command. Some Returned Values status - success or failure data->token - to be used with all other commands ** Complete Documentations can be found at https://help.dyn.com/ ########################## */ # Create an associative array with the required arguments $create_session = array( 'customer_name' => '<customer_name>', 'user_name' => '<username>', 'password' => '<password>'); $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. curl_setopt($ch, CURLOPT_FAILONERROR, false); # Do not fail silently. We want a response regardless curl_setopt($ch, CURLOPT_HEADER, false); # disables the response header and only returns the response body curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); # Set the content type of the post body curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_URL, $base_url.'/Session/'); # Where this action is going, curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($create_session)); print "\nLogging In\n"; print "----------------\n"; $http_result = curl_exec($ch); $decoded_result = json_decode($http_result); # Decode from JSON as our results are in the same format as our request if($decoded_result->status == 'success'){ $token = $decoded_result->data->token; } foreach($decoded_result->msgs as $message){ print $message->LVL.": ".($message->ERR_CD != '' ? '('.$message->ERR_CD.') ' : '').$message->SOURCE." - ".$message->INFO."\n"; } ?> <?php /* ########################### Checking if still Logged In ------------- To verify if your session is still active you must send a GET request with your Auth-Token in the header ############################# */ $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. curl_setopt($ch, CURLOPT_FAILONERROR, false); # Do not fail silently. We want a response regardless curl_setopt($ch, CURLOPT_HEADER, false); # disables the response header and only returns the response body curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Auth-Token: '.$token)); # Set the token and the content type so we know the response format curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); curl_setopt($ch, CURLOPT_URL, $base_url.'/Session/'); # Where this action is going, print "\nChecking if Logged In\n"; print "----------------\n"; $http_result = curl_exec($ch); $decoded_result = json_decode($http_result); # Decode from JSON as our results are in the same format as our request foreach($decoded_result->msgs as $message){ print $message->LVL.": ".($message->ERR_CD != '' ? '('.$message->ERR_CD.') ' : '').$message->SOURCE." - ".$message->INFO."\n"; } ?> <?php /* ########################### Logging Out ------------- To logout you must send a DELETE request with the session Token in header under 'Auth-Token' ############################# */ $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. curl_setopt($ch, CURLOPT_FAILONERROR, false); # Do not fail silently. We want a response regardless curl_setopt($ch, CURLOPT_HEADER, false); # disables the response header and only returns the response body curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Auth-Token: '.$token)); # Set the token and the content type so we know the response format curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); curl_setopt($ch, CURLOPT_URL, $base_url.'/Session/'); # Where this action is going, print "\nLogging Out\n"; print "----------------\n"; $http_result = curl_exec($ch); $decoded_result = json_decode($http_result); # Decode from JSON as our results are in the same format as our request foreach($decoded_result->msgs as $message){ print $message->LVL.": ".($message->ERR_CD != '' ? '('.$message->ERR_CD.') ' : '').$message->SOURCE." - ".$message->INFO."\n"; } ?> |
PHP Examples – Manage A RecordsHere’s a PHP example calling REST resources to:
Click to view the example code. <?php # Dynect API REST Examples - PHP # All examples utilize JSON for the data formating. # Output assumes use of PHP CLI # The Base Dynect API URL - All rest commands will be appended $base_url = 'https://api2.dynect.net/REST'; ?> <?php /* ########################### Add an A Record to a node ---------------- To add an A record to a zone you must send a POST request with an associatve rdata array with the session token in the header under 'Auth-Token' Adding an A record to a node that doesn't exist will create the node and then add the A Record Note: Zones MUST be published for these changes to take effect. ########################### */ $post_fields = array( 'rdata' => array( 'address' => '5.5.5.5', ), 'ttl' => '3600' ); $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. curl_setopt($ch, CURLOPT_FAILONERROR, false); # Do not fail silently. We want a response regardless curl_setopt($ch, CURLOPT_HEADER, false); # disables the response header and only returns the response body curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Auth-Token: '.$token)); # Set the token and the content type so we know the response format curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_URL, $base_url.'/ARecord/test.com/foo.test.com/'); # Where this action is going, curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_fields)); echo "\nAdding A Record to Zone Node\n"; echo "----------------\n"; $http_result = curl_exec($ch); $decoded_result = json_decode($http_result); # Decode from JSON as our results are in the same format as our request if($decoded_result->status == 'success'){ $zone = $decoded_result->data; # Associative Array containing zone data: zone_type, serial_style, serial, zone } foreach($decoded_result->msgs as $message){ echo $message->LVL.": ".($message->ERR_CD != '' ? '('.$message->ERR_CD.') ' : '').$message->SOURCE." - ".$message->INFO."\n"; } ?> <?php /* ########################### Publish all Zone Changes ---------------- To publish changes to a Zone you must send a PUT request with the session token in the header under 'Auth-Token' ########################### */ $put_fields = array( 'publish' => 1 ); $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. curl_setopt($ch, CURLOPT_FAILONERROR, false); # Do not fail silently. We want a response regardless curl_setopt($ch, CURLOPT_HEADER, false); # disables the response header and only returns the response body curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Auth-Token: '.$token)); # Set the token and the content type so we know the response format curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); curl_setopt($ch, CURLOPT_URL, $base_url.'/Zone/test.com/'); # Where this action is going, curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($put_fields)); echo "\nPublishing Zone Changes\n"; echo "----------------\n"; $http_result = curl_exec($ch); $decoded_result = json_decode($http_result); # Decode from JSON as our results are in the same format as our request if($decoded_result->status == 'success'){ $publish_data = $decoded_result->data; # Associative Array containing zone data: zone_type, serial_style, serial, zone } foreach($decoded_result->msgs as $message){ echo $message->LVL.": ".($message->ERR_CD != '' ? '('.$message->ERR_CD.') ' : '').$message->SOURCE." - ".$message->INFO."\n"; } ?> <?php /* ########################### Get a Specific Zone A Record detail ---------------- To get the A Records of a zone you must send a GET request with the session token in the header under 'Auth-Token' ########################### */ $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. curl_setopt($ch, CURLOPT_FAILONERROR, false); # Do not fail silently. We want a response regardless curl_setopt($ch, CURLOPT_HEADER, false); # disables the response header and only returns the response body curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Auth-Token: '.$token)); # Set the token and the content type so we know the response format curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); curl_setopt($ch, CURLOPT_URL, $base_url.'/ARecord/test.com/foo.test.com/'); # Where this action is going, echo "\nFetching Details about your Zone's A Records\n"; echo "----------------\n"; $http_result = curl_exec($ch); # Decode from JSON as our results are in the same format as our request $decoded_result = json_decode($http_result); if($decoded_result->status == 'success'){ # Array containing REST URIs for each A record in a node by record ID # Example: /REST/ARecord/test.com/foo.test.com/1234567 $records = $decoded_result->data; $last_a_record = $records[count($records)-1]; print_r($records); #All Records located on this node } foreach($decoded_result->msgs as $message){ echo $message->LVL.": ".($message->ERR_CD != '' ? '('.$message->ERR_CD.') ' : '').$message->SOURCE." - ".$message->INFO."\n"; } ?> <?php /* ########################### Remove an A Record ---------------- To remove an A Records of a zone you must send a DELETE request with the FQDN and the Record ID as well session token in the header under 'Auth-Token' Removing all records on a node will result in the removal of that node. ########################### */ $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. curl_setopt($ch, CURLOPT_FAILONERROR, false); # Do not fail silently. We want a response regardless curl_setopt($ch, CURLOPT_HEADER, false); # disables the response header and only returns the response body curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Auth-Token: '.$token)); # Set the token and the content type so we know the response format curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); curl_setopt($ch, CURLOPT_URL, $base_url.'/ARecord/test.com/foo.test.com/1234567/'); # Where this action is going; echo "\nDeleting a single Zone A Record: ".$record."\n"; echo "----------------\n"; $http_result = curl_exec($ch); $decoded_result = json_decode($http_result); # Decode from JSON as our results are in the same format as our request if($decoded_result->status == 'success'){ $records = $decoded_result->data; # Array containing REST URIs for each A record in a node by record ID: /REST/ARecord/test.com/foo.test.com/123456 } foreach($decoded_result->msgs as $message){ echo $message->LVL.": ".($message->ERR_CD != '' ? '('.$message->ERR_CD.') ' : '').$message->SOURCE." - ".$message->INFO."\n"; } ?> |
PHP Examples – Get Any RecordHere’s a PHP example calling REST resources to:
Click to view the example code. <?php # Dynect API REST Examples - PHP # All examples utilize JSON for the data formating. # The Base Dynect API URL - All rest commands will be appended $base_url = 'https://api2.dynect.net/REST'; ?> <?php /* ########################## Logging In ------------ To log in to the dynect API you must first create a session via a POST command. 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/rest/ ########################## */ # Create an associative array with the required arguments $create_session = array( 'customer_name' => 'customer_name', 'user_name' => 'user_name', 'password' => 'password'); $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. curl_setopt($ch, CURLOPT_FAILONERROR, false); # Do not fail silently. We want a response regardless curl_setopt($ch, CURLOPT_HEADER, false); # disables the response header and only returns the response body curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); # Set the content type of the post body curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_URL, $base_url.'/Session/'); # Where this action is going, curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($create_session)); print "<br/><b>Logging In</b><br/>"; print "----------------<br/>"; $http_result = curl_exec($ch); $decoded_result = json_decode($http_result); # Decode from JSON as our results are in the same format as our request if($decoded_result->status == 'success'){ $token = $decoded_result->data->token; } foreach($decoded_result->msgs as $message){ print $message->LVL.": ".($message->ERR_CD != '' ? '('.$message->ERR_CD.') ' : '').$message->SOURCE." - ".$message->INFO."<br/>"; } ?> <?php /* ########################### Retrieve a list of record resources for all records of any type at the specified node. ------------- To retrieve this list you must send a GET request with your Auth-Token in the header to the URL https://api2.dynect.net/REST/ARecord/<zone>/<fqdn>/ ############################# */ $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. curl_setopt($ch, CURLOPT_FAILONERROR, false); # Do not fail silently. We want a response regardless curl_setopt($ch, CURLOPT_HEADER, false); # disables the response header and only returns the response body curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Auth-Token: '.$token)); # Set the token and the content type so we know the response format curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); curl_setopt($ch, CURLOPT_URL, $base_url.'/ANYRecord/test.com/test.com/'); # Where this action is going, print "<br/><b>Retrieving list of all records</b><br/>"; print "----------------<br/>"; echo $base_url.'/ANYRecord/test.com/test.com/<br/><br/>'; $http_result = curl_exec($ch); $decoded_result = json_decode($http_result); # Decode from JSON as our results are in the same format as our request echo '<pre>'; print_r($decoded_result->data); echo '</pre_v>'; # NOTE: The "_v" has been added to this tag for WordPress visibility. Remove "_v" for proper functionality of <pre_v> tag. foreach($decoded_result->msgs as $message){ print $message->LVL.": ".($message->ERR_CD != '' ? '('.$message->ERR_CD.') ' : '').$message->SOURCE." - ".$message->INFO."<br/>"; } ?> <?php /* ########################### Logging Out ------------- To logout you must send a DELETE request with the session Token in header under 'Auth-Token' ############################# */ $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. curl_setopt($ch, CURLOPT_FAILONERROR, false); # Do not fail silently. We want a response regardless curl_setopt($ch, CURLOPT_HEADER, false); # disables the response header and only returns the response body curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Auth-Token: '.$token)); # Set the token and the content type so we know the response format curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); curl_setopt($ch, CURLOPT_URL, $base_url.'/Session/'); # Where this action is going, print "<br/><b>Logging Out</b><br/>"; print "----------------<br/>"; $http_result = curl_exec($ch); $decoded_result = json_decode($http_result); # Decode from JSON as our results are in the same format as our request foreach($decoded_result->msgs as $message){ print $message->LVL.": ".($message->ERR_CD != '' ? '('.$message->ERR_CD.') ' : '').$message->SOURCE." - ".$message->INFO."<br/>"; } ?> |
PHP Examples - Manage ZonesHere's a PHP example calling REST resources to:
Click to view the example code. <?php # Dynect API REST Examples - PHP # All examples utilize JSON for the data formating. # Output assumes use of PHP CLI # The Base Dynect API URL - All rest commands will be appended $base_url = 'https://api2.dynect.net/REST'; ?> <?php /* ########################### Get All Zones ---------------- To get a list of zones you must send a GET request with the session token in the header under 'Auth-Token' ########################### */ $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. curl_setopt($ch, CURLOPT_FAILONERROR, false); # Do not fail silently. We want a response regardless curl_setopt($ch, CURLOPT_HEADER, false); # disables the response header and only returns the response body curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Auth-Token: '.$token)); # Set the token and the content type so we know the response format curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); curl_setopt($ch, CURLOPT_URL, $base_url.'/Zone/'); # Where this action is going, print "\nFetching List of Zones\n"; print "----------------\n"; $http_result = curl_exec($ch); $decoded_result = json_decode($http_result); # Decode from JSON as our results are in the same format as our request if($decoded_result->status == 'success'){ $zones = $decoded_result->data; # Array of zones in the following format: /REST/Zone/test.com/ } foreach($decoded_result->msgs as $message){ print $message->LVL.": ".($message->ERR_CD != '' ? '('.$message->ERR_CD.') ' : '').$message->SOURCE." - ".$message->INFO."\n"; } ?> <?php /* ########################### Get a Specific Zone detail ---------------- To get the details of a zone you must send a GET request with the session token in the header under 'Auth-Token' ########################### */ $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. curl_setopt($ch, CURLOPT_FAILONERROR, false); # Do not fail silently. We want a response regardless curl_setopt($ch, CURLOPT_HEADER, false); # disables the response header and only returns the response body curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Auth-Token: '.$token)); # Set the token and the content type so we know the response format curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); curl_setopt($ch, CURLOPT_URL, $base_url.'/Zone/test.com/'); # Where this action is going, print "\nFetching Details about your Zone\n"; print "----------------\n"; $http_result = curl_exec($ch); $decoded_result = json_decode($http_result); # Decode from JSON as our results are in the same format as our request if($decoded_result->status == 'success'){ $zone = $decoded_result->data; # Associative Array containing zone data: zone_type, serial_style, serial, zone } foreach($decoded_result->msgs as $message){ print $message->LVL.": ".($message->ERR_CD != '' ? '('.$message->ERR_CD.') ' : '').$message->SOURCE." - ".$message->INFO."\n"; } ?> <?php /* ########################### Add an A Record to a node ---------------- To add an A record to a zone you must send a POST request with an associatve rdata array with the session token in the header under 'Auth-Token' Adding an A record to a node that doesn't exist will create the node and then add the A Record Note: Zones MUST be published for these changes to take effect. ########################### */ $post_fields = array( 'rdata' => array( 'address' => '5.5.5.5', ), 'ttl' => '3600' ); $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. curl_setopt($ch, CURLOPT_FAILONERROR, false); # Do not fail silently. We want a response regardless curl_setopt($ch, CURLOPT_HEADER, false); # disables the response header and only returns the response body curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Auth-Token: '.$token)); # Set the token and the content type so we know the response format curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_URL, $base_url.'/ARecord/test.com/foo.test.com/'); # Where this action is going, curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_fields)); echo "\nAdding A Record to Zone Node\n"; echo "----------------\n"; $http_result = curl_exec($ch); $decoded_result = json_decode($http_result); # Decode from JSON as our results are in the same format as our request if($decoded_result->status == 'success'){ $zone = $decoded_result->data; # Associative Array containing zone data: zone_type, serial_style, serial, zone } foreach($decoded_result->msgs as $message){ echo $message->LVL.": ".($message->ERR_CD != '' ? '('.$message->ERR_CD.') ' : '').$message->SOURCE." - ".$message->INFO."\n"; } ?> <?php /* ########################### Publish all Zone Changes ---------------- To publish changes to a Zone you must send a PUT request with the session token in the header under 'Auth-Token' ########################### */ $put_fields = array( 'publish' => 1 ); $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. curl_setopt($ch, CURLOPT_FAILONERROR, false); # Do not fail silently. We want a response regardless curl_setopt($ch, CURLOPT_HEADER, false); # disables the response header and only returns the response body curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Auth-Token: '.$token)); # Set the token and the content type so we know the response format curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); curl_setopt($ch, CURLOPT_URL, $base_url.'/Zone/test.com/'); # Where this action is going, curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($put_fields)); echo "\nPublishing Zone Changes\n"; echo "----------------\n"; $http_result = curl_exec($ch); $decoded_result = json_decode($http_result); # Decode from JSON as our results are in the same format as our request if($decoded_result->status == 'success'){ $publish_data = $decoded_result->data; # Associative Array containing zone data: zone_type, serial_style, serial, zone } foreach($decoded_result->msgs as $message){ echo $message->LVL.": ".($message->ERR_CD != '' ? '('.$message->ERR_CD.') ' : '').$message->SOURCE." - ".$message->INFO."\n"; } ?> <?php /* ########################### Remove a Zone Node ---------------- To remove a zone node you must send a DELETE request with the FQDN of the node you wish to remove as well session token in the header under 'Auth-Token' Note: Zones MUST be published for these changes to take effect. ########################### */ $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. curl_setopt($ch, CURLOPT_FAILONERROR, false); # Do not fail silently. We want a response regardless curl_setopt($ch, CURLOPT_HEADER, false); # disables the response header and only returns the response body curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Auth-Token: '.$token)); # Set the token and the content type so we know the response format curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); curl_setopt($ch, CURLOPT_URL, $base_url.'/Node/test.com/foo.test.com/'); # Where this action is going; echo "\nDeleting a Zone Node\n"; echo "----------------\n"; $http_result = curl_exec($ch); $decoded_result = json_decode($http_result); # Decode from JSON as our results are in the same format as our request if($decoded_result->status == 'success'){ $records = $decoded_result->data; # Array containing REST URIs for each A record in a node by record ID: /REST/ARecord/test.com/foo.test.com/123456 } foreach($decoded_result->msgs as $message){ echo $message->LVL.": ".($message->ERR_CD != '' ? '('.$message->ERR_CD.') ' : '').$message->SOURCE." - ".$message->INFO."\n"; } ?> |
PHP Examples - Manage Zones with Node ListHere's a PHP example calling REST resources to:
Click to view the example code. <?php # Dynect API REST Examples - PHP # All examples utilize JSON for the data formating. # The Base Dynect API URL - All rest commands will be appended $base_url = 'https://api2.dynect.net/REST'; ?> <?php /* ########################## Logging In ------------ To log in to the dynect API you must first create a session via a POST command. 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/rest/ ########################## */ # Create an associative array with the required arguments $create_session = array( 'customer_name' => 'customer_name', 'user_name' => 'user_name', 'password' => 'password'); $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. curl_setopt($ch, CURLOPT_FAILONERROR, false); # Do not fail silently. We want a response regardless curl_setopt($ch, CURLOPT_HEADER, false); # disables the response header and only returns the response body curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); # Set the content type of the post body curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_URL, $base_url.'/Session/'); # Where this action is going, curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($create_session)); print "<br/><b>Logging In</b><br/>"; print "----------------<br/>"; $http_result = curl_exec($ch); $decoded_result = json_decode($http_result); # Decode from JSON as our results are in the same format as our request if($decoded_result->status == 'success'){ $token = $decoded_result->data->token; } foreach($decoded_result->msgs as $message){ print $message->LVL.": ".($message->ERR_CD != '' ? '('.$message->ERR_CD.') ' : '').$message->SOURCE." - ".$message->INFO."<br/>"; } if(!isset($token)){ die("Quitting<br/>"); } ?> <?php /* ########################### Get All Zones ---------------- To get a list of zones you must send a GET request with the session token in the header under 'Auth-Token' ########################### */ $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. curl_setopt($ch, CURLOPT_FAILONERROR, false); # Do not fail silently. We want a response regardless curl_setopt($ch, CURLOPT_HEADER, false); # disables the response header and only returns the response body curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Auth-Token: '.$token)); # Set the token and the content type so we know the response format curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); curl_setopt($ch, CURLOPT_URL, $base_url.'/Zone/'); # Where this action is going, print "<br/><b>Fetching List of Zones</b><br/>"; print "----------------<br/>"; $http_result = curl_exec($ch); $decoded_result = json_decode($http_result); # Decode from JSON as our results are in the same format as our request if($decoded_result->status == 'success'){ $zones = $decoded_result->data; # Array of zones in the following format: /REST/Zone/test.com/ } foreach($decoded_result->msgs as $message){ print $message->LVL.": ".($message->ERR_CD != '' ? '('.$message->ERR_CD.') ' : '').$message->SOURCE." - ".$message->INFO."<br/>"; } ?> <?php /* ########################### Get a Specific Zone detail ---------------- To get the details of a zone you must send a GET request with the session token in the header under 'Auth-Token' ########################### */ $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. curl_setopt($ch, CURLOPT_FAILONERROR, false); # Do not fail silently. We want a response regardless curl_setopt($ch, CURLOPT_HEADER, false); # disables the response header and only returns the response body curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Auth-Token: '.$token)); # Set the token and the content type so we know the response format curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); curl_setopt($ch, CURLOPT_URL, $base_url.'/Zone/test.com/'); # Where this action is going, print "<br/><b>Fetching Details about your Zone</b><br/>"; print "----------------<br/>"; $http_result = curl_exec($ch); $decoded_result = json_decode($http_result); # Decode from JSON as our results are in the same format as our request if($decoded_result->status == 'success'){ echo '<pre>'; print_r($decoded_result->data); echo '</pre_v>'; # NOTE: The "_v" has been added to this tag for WordPress visibility. Remove "_v" for proper functionality of <pre_v> tag. $zone = $decoded_result->data; # Associative Array containing zone data: zone_type, serial_style, serial, zone } foreach($decoded_result->msgs as $message){ print $message->LVL.": ".($message->ERR_CD != '' ? '('.$message->ERR_CD.') ' : '').$message->SOURCE." - ".$message->INFO."<br/>"; } ?> <?php /* ########################### Add an A Record to a node ---------------- To add an A record to a zone you must send a POST request with an associatve rdata array with the session token in the header under 'Auth-Token' Adding an A record to a node that doesn't exist will create the node and then add the A Record Note: Zones MUST be published for these changes to take effect. ########################### */ $post_fields = array( 'rdata' => array( 'address' => '5.5.5.5', ), 'ttl' => '3600' ); $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. curl_setopt($ch, CURLOPT_FAILONERROR, false); # Do not fail silently. We want a response regardless curl_setopt($ch, CURLOPT_HEADER, false); # disables the response header and only returns the response body curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Auth-Token: '.$token)); # Set the token and the content type so we know the response format curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_URL, $base_url.'/ARecord/test.com/foo.test.com/'); # Where this action is going, curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_fields)); echo "<br/><b>Adding A Record to Zone Node</b><br/>"; echo "----------------<br/>"; echo "foo.test.com<br/>"; echo '<pre>'; print_r($post_fields); echo '</pre_v>'; # NOTE: The "_v" has been added to this tag for WordPress visibility. Remove "_v" for proper functionality of <pre_v> tag. $http_result = curl_exec($ch); $decoded_result = json_decode($http_result); # Decode from JSON as our results are in the same format as our request if($decoded_result->status == 'success'){ $zone = $decoded_result->data; # Associative Array containing zone data: zone_type, serial_style, serial, zone } foreach($decoded_result->msgs as $message){ echo $message->LVL.": ".($message->ERR_CD != '' ? '('.$message->ERR_CD.') ' : '').$message->SOURCE." - ".$message->INFO."<br/>"; } ?> <?php /* ########################### Add an A Record to a node ---------------- To add an A record to a zone you must send a POST request with an associatve rdata array with the session token in the header under 'Auth-Token' Adding an A record to a node that doesn't exist will create the node and then add the A Record Note: Zones MUST be published for these changes to take effect. ########################### */ $post_fields = array( 'rdata' => array( 'address' => '5.5.5.5', ), 'ttl' => '3600' ); $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. curl_setopt($ch, CURLOPT_FAILONERROR, false); # Do not fail silently. We want a response regardless curl_setopt($ch, CURLOPT_HEADER, false); # disables the response header and only returns the response body curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Auth-Token: '.$token)); # Set the token and the content type so we know the response format curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_URL, $base_url.'/ARecord/test.com/bar.foo.test.com/'); # Where this action is going, curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_fields)); echo "<br/><b>Adding A Record to Zone Node</b><br/>"; echo "----------------<br/>"; echo "bar.foo.test.com<br/>"; echo '<pre>'; print_r($post_fields); echo '</pre_v>'; # NOTE: The "_v" has been added to this tag for WordPress visibility. Remove "_v" for proper functionality of <pre_v> tag. $http_result = curl_exec($ch); $decoded_result = json_decode($http_result); # Decode from JSON as our results are in the same format as our request if($decoded_result->status == 'success'){ $zone = $decoded_result->data; # Associative Array containing zone data: zone_type, serial_style, serial, zone } foreach($decoded_result->msgs as $message){ echo $message->LVL.": ".($message->ERR_CD != '' ? '('.$message->ERR_CD.') ' : '').$message->SOURCE." - ".$message->INFO."<br/>"; } ?> <?php /* ########################### Publish all Zone Changes ---------------- To publish changes to a Zone you must sent a PUT request the session token in the header under 'Auth-Token' ########################### */ $put_fields = array( 'publish' => 1 ); $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. curl_setopt($ch, CURLOPT_FAILONERROR, false); # Do not fail silently. We want a response regardless curl_setopt($ch, CURLOPT_HEADER, false); # disables the response header and only returns the response body curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Auth-Token: '.$token)); # Set the token and the content type so we know the response format curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); curl_setopt($ch, CURLOPT_URL, $base_url.'/Zone/test.com/'); # Where this action is going, curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($put_fields)); echo "<br/><b>Publishing Zone Changes</b><br/>"; echo "----------------<br/>"; $http_result = curl_exec($ch); $decoded_result = json_decode($http_result); # Decode from JSON as our results are in the same format as our request if($decoded_result->status == 'success'){ $publish_data = $decoded_result->data; # Associative Array containing zone data: zone_type, serial_style, serial, zone } foreach($decoded_result->msgs as $message){ echo $message->LVL.": ".($message->ERR_CD != '' ? '('.$message->ERR_CD.') ' : '').$message->SOURCE." - ".$message->INFO."<br/>"; } ?> <?php /* ########################### Get a list of node names under a specific node. ---------------- To get the details of a zone you must send a GET request with the session token in the header under 'Auth-Token' ########################### */ $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. curl_setopt($ch, CURLOPT_FAILONERROR, false); # Do not fail silently. We want a response regardless curl_setopt($ch, CURLOPT_HEADER, false); # disables the response header and only returns the response body curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Auth-Token: '.$token)); # Set the token and the content type so we know the response format curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); curl_setopt($ch, CURLOPT_URL, $base_url.'/NodeList/test.com/'); # Where this action is going, print "<br/><b>Fetching Nodes under your Zone</b><br/>"; print "----------------<br/>"; echo 'test.com'; $http_result = curl_exec($ch); $decoded_result = json_decode($http_result); # Decode from JSON as our results are in the same format as our request if($decoded_result->status == 'success'){ echo '<pre>'; print_r($decoded_result->data); echo '</pre_v>'; # NOTE: The "_v" has been added to this tag for WordPress visibility. Remove "_v" for proper functionality of <pre_v> tag. $zone = $decoded_result->data; # Associative Array containing zone data: zone_type, serial_style, serial, zone } foreach($decoded_result->msgs as $message){ print $message->LVL.": ".($message->ERR_CD != '' ? '('.$message->ERR_CD.') ' : '').$message->SOURCE." - ".$message->INFO."<br/>"; } ?> <?php /* ########################### Get a list of node names under a specific node. ---------------- To get the details of a zone you must send a GET request with the session token in the header under 'Auth-Token' ########################### */ $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. curl_setopt($ch, CURLOPT_FAILONERROR, false); # Do not fail silently. We want a response regardless curl_setopt($ch, CURLOPT_HEADER, false); # disables the response header and only returns the response body curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Auth-Token: '.$token)); # Set the token and the content type so we know the response format curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); curl_setopt($ch, CURLOPT_URL, $base_url.'/NodeList/test.com/foo.test.com/'); # Where this action is going, print "<br/><b>Fetching Nodes under your Zone</b><br/>"; print "----------------<br/>"; echo 'foo.test.com'; $http_result = curl_exec($ch); $decoded_result = json_decode($http_result); # Decode from JSON as our results are in the same format as our request if($decoded_result->status == 'success'){ echo '<pre>'; print_r($decoded_result); echo '</pre_v>'; # NOTE: The "_v" has been added to this tag for WordPress visibility. Remove "_v" for proper functionality of <pre_v> tag. $zone = $decoded_result->data; # Associative Array containing zone data: zone_type, serial_style, serial, zone } foreach($decoded_result->msgs as $message){ print $message->LVL.": ".($message->ERR_CD != '' ? '('.$message->ERR_CD.') ' : '').$message->SOURCE." - ".$message->INFO."<br/>"; } ?> <?php /* ########################### Remove a Zone Node ---------------- To remove a zone node you must send a DELETE request with the FQDN of the node you wish to remove as well session token in the header under 'Auth-Token' Note: Zones MUST be published for these changes to take effect. ########################### */ $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. curl_setopt($ch, CURLOPT_FAILONERROR, false); # Do not fail silently. We want a response regardless curl_setopt($ch, CURLOPT_HEADER, false); # disables the response header and only returns the response body curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Auth-Token: '.$token)); # Set the token and the content type so we know the response format curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); curl_setopt($ch, CURLOPT_URL, $base_url.'/Node/test.com/foo.test.com/'); # Where this action is going; echo "<br/><b>Deleting a Zone Node</b><br/>"; echo "----------------<br/>"; $http_result = curl_exec($ch); $decoded_result = json_decode($http_result); # Decode from JSON as our results are in the same format as our request if($decoded_result->status == 'success'){ $records = $decoded_result->data; # Array containing REST URIs for each A record in a node by record ID: /REST/ARecord/test.com/foo.test.com/123456 } foreach($decoded_result->msgs as $message){ echo $message->LVL.": ".($message->ERR_CD != '' ? '('.$message->ERR_CD.') ' : '').$message->SOURCE." - ".$message->INFO."<br/>"; } ?> <?php /* ########################### Publish all Zone Changes ---------------- To publish changes to a Zone you must sent a PUT request the session token in the header under 'Auth-Token' ########################### */ $put_fields = array( 'publish' => 1 ); $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. curl_setopt($ch, CURLOPT_FAILONERROR, false); # Do not fail silently. We want a response regardless curl_setopt($ch, CURLOPT_HEADER, false); # disables the response header and only returns the response body curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Auth-Token: '.$token)); # Set the token and the content type so we know the response format curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); curl_setopt($ch, CURLOPT_URL, $base_url.'/Zone/test.com/'); # Where this action is going, curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($put_fields)); echo "<br/><b>Publishing Zone Changes</b><br/>"; echo "----------------<br/>"; $http_result = curl_exec($ch); $decoded_result = json_decode($http_result); # Decode from JSON as our results are in the same format as our request if($decoded_result->status == 'success'){ $publish_data = $decoded_result->data; # Associative Array containing zone data: zone_type, serial_style, serial, zone } foreach($decoded_result->msgs as $message){ echo $message->LVL.": ".($message->ERR_CD != '' ? '('.$message->ERR_CD.') ' : '').$message->SOURCE." - ".$message->INFO."<br/>"; } ?> <?php /* ########################### Logging Out ------------- To logout you must send a DELETE request with the session Token in header under 'Auth-Token' ############################# */ $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. curl_setopt($ch, CURLOPT_FAILONERROR, false); # Do not fail silently. We want a response regardless curl_setopt($ch, CURLOPT_HEADER, false); # disables the response header and only returns the response body curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Auth-Token: '.$token)); # Set the token and the content type so we know the response format curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); curl_setopt($ch, CURLOPT_URL, $base_url.'/Session/'); # Where this action is going, print "<br/><b>Logging Out</b><br/>"; print "----------------<br/>"; $http_result = curl_exec($ch); $decoded_result = json_decode($http_result); # Decode from JSON as our results are in the same format as our request foreach($decoded_result->msgs as $message){ print $message->LVL.": ".($message->ERR_CD != '' ? '('.$message->ERR_CD.') ' : '').$message->SOURCE." - ".$message->INFO."<br/>"; } ?> |
PHP Examples - Secondary ZonesHere's a PHP example calling REST resources to:
Click to view the example code. <?php # Dynect API REST Examples - PHP # All examples utilize JSON for the data formating. # The Base Dynect API URL - All rest commands will be appended $base_url = 'https://api2.dynect.net/REST'; ?> <?php /* ########################## Logging In ------------ To log in to the dynect API you must first create a session via a POST command. 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/rest/ ########################## */ # Create an associative array with the required arguments $create_session = array( 'customer_name' => 'customer_name', 'user_name' => 'user_name', 'password' => 'password'); $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. curl_setopt($ch, CURLOPT_FAILONERROR, false); # Do not fail silently. We want a response regardless curl_setopt($ch, CURLOPT_HEADER, false); # disables the response header and only returns the response body curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); # Set the content type of the post body curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_URL, $base_url.'/Session/'); # Where this action is going, curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($create_session)); print "<br/>Logging In<br/>"; print "----------------<br/>"; $http_result = curl_exec($ch); $decoded_result = json_decode($http_result); # Decode from JSON as our results are in the same format as our request if($decoded_result->status == 'success'){ $token = $decoded_result->data->token; } foreach($decoded_result->msgs as $message){ print $message->LVL.": ".($message->ERR_CD != '' ? '('.$message->ERR_CD.') ' : '').$message->SOURCE." - ".$message->INFO."<br/>"; } if(!isset($token)){ die("Quitting<br/>"); } ?> <?php /* ########################### Create a Secondary Zone - Multi Master ---------------- To add an Secondary zone you must send a POST request with the master address(es) along with the session token in the header under 'Auth-Token' Note: Zones MUST be published for these changes to take effect. ########################### */ $post_fields = array( 'masters' => array( '5.5.5.5', '1.2.3.4', '2.3.4.5' ), ); $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. curl_setopt($ch, CURLOPT_FAILONERROR, false); # Do not fail silently. We want a response regardless curl_setopt($ch, CURLOPT_HEADER, false); # disables the response header and only returns the response body curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Auth-Token: '.$token)); # Set the token and the content type so we know the response format curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_URL, $base_url.'/Secondary/secondarytest.com/'); # Where this action is going, curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_fields)); echo "<br/>Adding a Secondary Zone with multiple Masters<br/>"; echo "----------------<br/>"; $http_result = curl_exec($ch); $decoded_result = json_decode($http_result); # Decode from JSON as our results are in the same format as our request if($decoded_result->status == 'success'){ $zone = $decoded_result->data; # Associative Array containing zone data: zone_type, serial_style, serial, zone } foreach($decoded_result->msgs as $message){ echo $message->LVL.": ".($message->ERR_CD != '' ? '('.$message->ERR_CD.') ' : '').$message->SOURCE." - ".$message->INFO."<br/>"; } ?> <?php /* ########################### Get Secondary Zone Info ---------------- To get information about a Secondary Zone you must send a GET request with the session token in the header under 'Auth-Token' ########################### */ $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. curl_setopt($ch, CURLOPT_FAILONERROR, false); # Do not fail silently. We want a response regardless curl_setopt($ch, CURLOPT_HEADER, false); # disables the response header and only returns the response body curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Auth-Token: '.$token)); # Set the token and the content type so we know the response format curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); curl_setopt($ch, CURLOPT_URL, $base_url.'/Secondary/secondarytest.com/'); # Where this action is going, print "<br/>Fetching Secondary Zone Information<br/>"; print "----------------<br/>"; $http_result = curl_exec($ch); $decoded_result = json_decode($http_result); # Decode from JSON as our results are in the same format as our request if($decoded_result->status == 'success'){ $zones = $decoded_result->data; # Array of zones in the following format: /REST/Zone/test.com/ } foreach($decoded_result->msgs as $message){ print $message->LVL.": ".($message->ERR_CD != '' ? '('.$message->ERR_CD.') ' : '').$message->SOURCE." - ".$message->INFO."<br/>"; } ?> <?php /* ########################### Delete a Secondary Zone ---------------- To Delete an Secondary zone you must send a DELETE request to /Rest/Zone/<zone name> with the session token in the header under 'Auth-Token' ########################### */ $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. curl_setopt($ch, CURLOPT_FAILONERROR, false); # Do not fail silently. We want a response regardless curl_setopt($ch, CURLOPT_HEADER, false); # disables the response header and only returns the response body curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Auth-Token: '.$token)); # Set the token and the content type so we know the response format curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); curl_setopt($ch, CURLOPT_URL, $base_url.'/Zone/secondarytest.com/'); # Where this action is going, echo "<br/>Delete a Secondary Zone with /REST/Zone/ DELETE<br/>"; echo "----------------<br/>"; $http_result = curl_exec($ch); $decoded_result = json_decode($http_result); # Decode from JSON as our results are in the same format as our request if($decoded_result->status == 'success'){ $zone = $decoded_result->data; # Associative Array containing zone data: zone_type, serial_style, serial, zone } foreach($decoded_result->msgs as $message){ echo $message->LVL.": ".($message->ERR_CD != '' ? '('.$message->ERR_CD.') ' : '').$message->SOURCE." - ".$message->INFO."<br/>"; } ?> <?php /* ########################### Logging Out ------------- To logout you must send a DELETE request with the session Token in header under 'Auth-Token' ############################# */ $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. curl_setopt($ch, CURLOPT_FAILONERROR, false); # Do not fail silently. We want a response regardless curl_setopt($ch, CURLOPT_HEADER, false); # disables the response header and only returns the response body curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Auth-Token: '.$token)); # Set the token and the content type so we know the response format curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); curl_setopt($ch, CURLOPT_URL, $base_url.'/Session/'); # Where this action is going, print "<br/>Logging Out<br/>"; print "----------------<br/>"; $http_result = curl_exec($ch); $decoded_result = json_decode($http_result); # Decode from JSON as our results are in the same format as our request foreach($decoded_result->msgs as $message){ print $message->LVL.": ".($message->ERR_CD != '' ? '('.$message->ERR_CD.') ' : '').$message->SOURCE." - ".$message->INFO."<br/>"; } ?> |