Manage your sites with the PHP SDK

This page will get you started managing your sites with the PHP SDK. Make sure you've read the getting started guide first. Once that's done, you should have our package & authentication ready to go.

Retrieve all sites

The simplest example is one where we list all your sites on your Oh Dear! accounts.

$sites = $ohDear->sites();

This will return an array of OhDear\PhpSdk\Resources\Site instances.

You can get a few properties of a site.

$site->id;
$site->url;
...

You can also get a single site:

$ohDear->site($siteId);

Add a site through the SDK

A new site can be created with createSite().

$ohDear->createSite([
   'url' => 'https://yourbrandnewsite.tld', 
   'team_id' => $yourTeamId
]);

Take a look at the User section to learn how to get your team id.

When an https site is created, all checks will automatically be enabled. When an http site is created only the uptime and broken links checks will be enabled.

If you only want to enable specific checks when creating a site you can just pass them like this:

$ohDear->createSite([
   'url' => 'https://yourbrandnewsite.tld',
   'team_id' => $yourTeamId
   'checks' => ['uptime', 'mixed_content']
]);

Valid values to pass to checks are uptime, broken_links, certificate_health, mixed_content and certificate_transparency.

Deleting a site

A site can easily be deleted. This assumes the $site is an instance of OhDear\PhpSdk\Resources\Site, which you can get with the sites() method.

$site->delete(); // This particular site is deleted

See the retrieving all sites section above to get all available sites.