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)
);

use BlueRockTEL\AteraClient\AteraConnector;

$api = new AteraConnector('secret_token');

$query = [
    'searchOptions.email' => '[email protected]',
];

$response = $api->contact()->index(
    query: $query,
    perPage: 20,
    page: 1,
);

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;
}

$connector = new AteraConnector(...);

$connector->agent(): Resources\AgentResource
$connector->customer(): Resources\CustomerResource
$connector->contact(): Resources\ContactResource
...

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

$response = $api->agent()->show(id: 92);

/** @var \BlueRockTEL\AteraClient\Entities\Agent */
$agent = $response->dtoOrFail();

$entity = $response->dtoOrFail();   // \BlueRockTEL\AteraClient\Contracts\Entity
$entity->getResponse();             // \Saloon\Http\Response

use BlueRockTEL\AteraClient\Entities\Customer;

// create
$response = $api->customer()->store(
    customer: new Customer(
        CustomerName: 'Acme Enterprise',
        City: 'Paris',
    ),
);

$customer = $response->dtoOrFail();

// update
$customer->CustomerName = 'Acme Enterprise Inc.';
$api->customer()->update($customer);

# 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