Built to be used within WordPress for accessing Constellix's API to manage DNS records.
Start by adding the Constellix's API keys from manage.constellix.com/user to wp-config.php.
define( 'CONSTELLIX_API_KEY', "XXXXXXXXXXXXXXXXXXXXXXXXXXX");
define( 'CONSTELLIX_SECRET_KEY', "XXXXXXXXXXXXXXXXXXXXXXXXXXX");
Next include in WordPress theme or plugin: include "constellix-api/constellix-api.php";
.
$response = constellix_api_get("domains");
foreach($response as $domain) {
$domain_id = $domain->id;
$domain_name = $domain->name;
$domain_nameservers = $domain->nameservers;
}
$domain_id = "1234";
$response = constellix_api_get("domains/$domain_id/records/a");
$response = constellix_api_get("domains/$domain_id/records/aaaa");
$response = constellix_api_get("domains/$domain_id/records/mx");
$response = constellix_api_get("domains/$domain_id/records/cname");
$response = constellix_api_get("domains/$domain_id/records/httpredirection");
foreach($response as $records) {
$record_id = $records->id;
$record_name = $records->name;
$record_values = $records->value;
foreach($record_values as $record) {
$record_value = $record->value;
$record_level = $record->level; // Used by MX records
}
}
$post = array(
"names" => array(
"newanchordomain1.com",
"newanchordomain2.com"
)
);
$response = constellix_api_post("domains", $post);
foreach($response as $domain) {
// Capture new domain IDs from $response
$domain_id = $domain->id;
$domain_name = $domain->name;
}
$domain_id = "1234";
$post = array(
"recordOption" => "roundRobin",
"name" => "sample",
"ttl" => 1800,
"roundRobin" => array(
array(
"value" => "104.197.69.102",
"disableFlag" => false,
),
),
);
$response = constellix_api_post("domains/$domain_id/records/a", $post);
$domain_id = "1234";
$post = array(
"name" => "cdn",
"host" => "lorem-1234.kxcdn.com.",
"ttl" => 1800,
);
$response = constellix_api_post("domains/$domain_id/records/cname", $post);
$domain_id = "1234";
$post = array(
"name" => "plans",
"ttl" => 1800,
"url" => "https://anchor.host/plans/",
"redirectTypeId" => "3",
);
$response = constellix_api_post("domains/$domain_id/records/httpredirection", $post);
$domain_id = "1234";
$record_id = "1234";
$post = array(
"recordOption" => "roundRobin",
"name" => "www",
"ttl" => 1800,
"roundRobin" => array(
array(
"value" => "104.197.69.102",
"disableFlag" => false,
),
),
);
$response = constellix_api_put("domains/$domain_id/records/a/$record_id", $post);
$domain_id = "1234";
$record_id = "1234";
$post = array(
"name" => "cdn",
"host" => "lorem-1234.kxcdn.com.",
"ttl" => 1800,
);
$response = constellix_api_put("domains/$domain_id/records/cname/$record_id", $post);
$domain_id = "1234";
$record_id = "1234";
$post = array(
"name" => "plans",
"ttl" => 1800,
"url" => "https://anchor.host/plans/",
"redirectTypeId" => "3",
);
$response = constellix_api_post("domains/$domain_id/records/httpredirection/$record_id", $post);
$domain_id = "1234";
$record_id = "1234";
$response = constellix_api_delete("domains/$domain_id/records/cname/$record_id");
- Increased timeouts to 30 seconds.
- Added basic error handling
- Added new PHP wrapper for sending PUT request to Constellix's API. Updated docs with examples of updating existing records.
- Initial release of constellix-api.php. Includes PHP wrappers for sending GET, POST and DELETE requests to Constellix's API. Based on their official Perl code sample.
Copyright (c) 2017 Anchor Hosting
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.