Skip to content

Latest commit

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

PHP OpenProvider REST API

PHP implementation for OpenProvider REST API 1.0.0-beta https://docs.openprovider.com/doc/all

Keep in mind API is in Beta and might change.

Setup

Setup variables in your .env or other configuration option you're using. The ApiHelper class expects a config() function to exist.

OPENPROVIDER_USER=username@openprovider.cpOPENPROVIDER_PASS=Sup3rs3cret4cc0untp455w0rd

Usage

Example below shows how to change a record.

useOpenprovider\Api\ApiHelper;
useOpenprovider\Api\Dns\ZoneService;
useOpenprovider\Entities\Dns\Zone;
useOpenprovider\Entities\Dns\ZoneRecord;
$client = ApiHelper::getClient();
$zone_api = newZoneService($client);
$domain_name = "domain.tld";
try {
// Try to retrieve zone$zone = $zone_api->get($domain_name);
} catch (Exception$ex) {
// Exception, zone doesn't exist so lets create it$zone = newZone();
$zone->active = true;
$zone->setType(Zone::TYPE_MASYER);
$zone->setName($domain_name);
$zone_api->create($zone);
}
// Create a CNAME www record to "domain.tld."$www_record = newZoneRecord();
$www_record->setName('www');
$www_record->setType(ZoneRecord::TYPE_CNAME);
$www_record->setValue($domain_name . '.');
$www_record->setTtl(ZoneRecord::TTL_15MIN);
// Replace all recordstry {
$add_records = [];
$remove_records = [];
$replace_records = [$www_record];
$zone_api->update($zone, $add_records, $remove_records, $replace_records);
} catch (Exception$ex) {
echo"Error when updating zone: ", $domain_name, PHP_EOL;
echo$ex->getMessage();
}

About

PHP implementation for OpenProvider REST API 1.0.0-beta

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages