davidnsai / ionos-dns-api-client
A PHP client library for the IONOS DNS API, providing easy management of DNS zones, records, and Dynamic DNS configurations.
Requires
- php: >=8.1
- ext-curl: *
- ext-json: *
Requires (Dev)
- php-coveralls/php-coveralls: ^2.5
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^9.0|^10.0|^11.0
- squizlabs/php_codesniffer: ^3.7
This package is auto-updated.
Last update: 2025-07-23 14:14:44 UTC
README
A PHP client library for the IONOS DNS API, providing easy management of DNS zones, records, and Dynamic DNS configurations.
Installation
Install the package via Composer:
composer require ionos/dns-api-client
Requirements
- PHP 8.1 or higher
- cURL extension
- JSON extension
Quick Start
<?php require_once 'vendor/autoload.php'; use DNSApi\DNSApiClient; use DNSApi\DNSApiException; // Initialize the client $dnsClient = new DNSApiClient('your-api-key-here'); try { // Get all zones $zones = $dnsClient->getZones(); echo "Found " . count($zones) . " zones\n"; // Create a new A record $record = $dnsClient->createRecord('www.example.com', 'A', '192.168.1.1', 3600); $createdRecords = $dnsClient->createRecords('zone-id-here', [$record]); } catch (DNSApiException $e) { echo "DNS API Error: " . $e->getMessage() . "\n"; }
Features
- Zone Management: List, get, update, and patch DNS zones
- Record Management: Create, read, update, and delete DNS records
- Dynamic DNS: Activate, update, and manage Dynamic DNS configurations
- Type Safety: Built-in validation for DNS record types
- Error Handling: Comprehensive exception handling with detailed error information
- PSR-4 Autoloading: Follows PHP-FIG standards
- Extensible: Injectable HTTP client interface for custom implementations
Supported DNS Record Types
The client supports all major DNS record types:
- A, AAAA, CNAME, MX, NS, SOA, SRV, TXT
- CAA, TLSA, SMIMEA, SSHFP, DS
- HTTPS, SVCB, CERT, URI, RP, LOC, OPENPGPKEY
Usage Examples
Zone Operations
// Get all zones $zones = $dnsClient->getZones(); // Get a specific zone with optional filters $zone = $dnsClient->getZone('zone-id', [ 'recordType' => 'A', 'recordName' => 'www' ]); // Update entire zone (replaces all records) $records = [ $dnsClient->createRecord('www.example.com', 'A', '192.168.1.1'), $dnsClient->createRecord('mail.example.com', 'A', '192.168.1.2') ]; $dnsClient->updateZone('zone-id', $records); // Patch zone (replaces records of same name and type) $dnsClient->patchZone('zone-id', $records);
Record Operations
// Create multiple records $records = [ $dnsClient->createRecord('www.example.com', 'A', '192.168.1.1'), $dnsClient->createRecord('example.com', 'MX', 'mail.example.com', 3600, 10) ]; $createdRecords = $dnsClient->createRecords('zone-id', $records); // Get a specific record $record = $dnsClient->getRecord('zone-id', 'record-id'); // Update a record $updatedRecord = $dnsClient->updateRecord('zone-id', 'record-id', [ 'content' => '192.168.1.100', 'ttl' => 7200 ]); // Delete a record $dnsClient->deleteRecord('zone-id', 'record-id');
Dynamic DNS
// Activate Dynamic DNS $dynamicDns = $dnsClient->activateDynamicDNS( ['example.com', 'www.example.com'], 'My Dynamic DNS Configuration' ); echo "Update URL: " . $dynamicDns->updateUrl . "\n"; // Update Dynamic DNS configuration $dnsClient->updateDynamicDNS('bulk-id', ['newdomain.com'], 'Updated config'); // Delete specific Dynamic DNS configuration $dnsClient->deleteDynamicDNS('bulk-id'); // Disable all Dynamic DNS $dnsClient->disableDynamicDNS();
Custom HTTP Client
You can inject your own HTTP client implementation:
use DNSApi\HttpClientInterface; class MyHttpClient implements HttpClientInterface { public function request($method, $url, $options = []) { // Your custom HTTP implementation // Must return ['status_code' => int, 'body' => string] } } $dnsClient = new DNSApiClient('api-key', 'https://api.hosting.ionos.com/dns', new MyHttpClient());
Error Handling
The client throws DNSApiException
for API errors:
try { $zones = $dnsClient->getZones(); } catch (DNSApiException $e) { echo "Error: " . $e->getMessage() . "\n"; echo "HTTP Code: " . $e->getCode() . "\n"; // Get detailed error information $errors = $e->getErrors(); if ($errors) { print_r($errors); } }
Development
Running Tests
composer test
Code Style
Check code style:
composer cs-check
Fix code style:
composer cs-fix
Static Analysis
composer analyse
API Documentation
For complete API documentation, visit the IONOS DNS API Documentation.
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
- Create an issue on GitHub
- Check the IONOS API Documentation
Changelog
See CHANGELOG.md for a list of changes and releases.