PHP code example of bluerocktel / atera-api-php-client
1. Go to this page and download the library: Download bluerocktel/atera-api-php-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bluerocktel / atera-api-php-client example snippets
use BlueRockTEL\AteraClient\AteraConnector;
$api = new AteraConnector(
apiToken: 'secret_token',
apiUrl: 'https://app.atera.com/api', // optional
);
$response = $api->agent()->index();
var_dump(
$response->failed(), // true is the request returned 4xx or 5xx code.
$response->json(), // json response as an array
);
use BlueRockTEL\AteraClient\AteraConnector;
use BlueRockTEL\AteraClient\Endpoints;
$api = new AteraConnector('secret_token');
$response = $api->call(
new Endpoints\Contacts\GetContactRequest(id: $contactId)
);
class NamespaceResource
{
public function index(array $params = [], int $perPage = 20, int $page = 1): Response;
public function show(int $id): Response;
public function store(Entity $entity): Response;
public function update(Entity $entity): Response;
public function upsert(Entity $entity): Response;
public function delete(int $id): Response;
}
use BlueRockTEL\AteraClient\AteraConnector;
use BlueRockTEL\AteraClient\Resources\AgentResource;
$api = new AteraConnector();
$resource = new AgentResource($api);
$agent = $resource->show($agentId);
$resource->upsert($agent);
// Check response status
$response->ok();
$response->failed();
$response->status();
$response->headers();
// Get response data
$response->json(); # as an array
$response->body(); # as an raw string
$response->dtoOrFail(); # as a Data Transfer Object
# Create a PagedPaginator instance
$paginator = $api->paginate(new GetCustomersRequest());
# Iterate on all pages entities, using lazy loading for performance
foreach ($paginator->items() as $customer) {
$name = $customer->CustomerName;
$city = $customer->City;
}
use BlueRockTEL\AteraClient\AteraConnector;
class MyCustomConnector extends AteraConnector
{
public function defaultConfig(): array
{
return [
'timeout' => 120,
];
}
public function customResource(): \App\Resources\CustomResource
{
return new \App\Resources\CustomResource($this);
}
}
$api = new MyCustomConnector('secret_token');
$api->customResource()->index();
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.