Skip to content

Usage ​

Getting a client ​

php
use Anikeen\Console\Facades\AnikeenConsole;

$console = AnikeenConsole::forUser($user);     // the user's stored token, refreshed when needed
$console = AnikeenConsole::withToken($token);  // a fixed token, e.g. a personal access token in a script

The shared AnikeenConsole instance keeps no token: forUser() and withToken() return copies.

Tokens ​

  • forUser($user) reads the tokens anikeen/id stores on the user.
  • A token that expires within a minute is refreshed through AnikeenId::refreshToken() before the request. A 401 refreshes it and sends the request once more (with the same headers, so the same Idempotency-Key).
  • The new pair is saved on the user (only those two columns).
  • Refreshes are locked per user through the cache, and a pair another process stored meanwhile is used instead of refreshing again (refresh tokens are single-use).
  • When the refresh fails, an AuthenticationException asks you to send the user through the Anikeen ID login again. A user without any token throws anikeen/id's RequestRequiresAuthenticationException.
  • withToken($token) never refreshes.

App team ​

php
$team = $console->appTeam();   // GET /app-team: {id, name, app, created_at}, created on the first call

See The app team.

Catalog ​

php
$catalog = $console->catalog($team);           // a Team, its id, or null for list prices

$catalog->families();                          // the families in the catalog
$catalog->family('container');                 // one family (stdClass) or null
$plans = $catalog->products('container');      // its products
$locations = $catalog->options('container')->locations;
$catalog->vatRate();                           // e.g. 19.0

Filters ​

php
// only GPU plans, NVIDIA, at most 150 € net per month, cheapest first
$gpuPlans = $console->catalog($team, [
    'gpu' => true,
    'gpu_vendor' => 'nvidia',     // nvidia | amd | intel
    'max_price' => 150,           // on monthly_price: net, the team's price, hourly plans at their monthly cap
    'sort' => 'price',            // price | -price
])->products('container');

All filters are optional and applied by the Console; families left without products are left out. Booleans are sent as true/false, lists comma-separated.

Filter
familyalias or list
gputrue / false
gpu_vendornvidia, amd, intel
gpu_modelsubstring
gpu_modeshared, exclusive
gpu_min_vram_gb, gpu_min_countintegers
min_vcores, min_memory_mb, min_disk_gbintegers
min_price, max_priceon each product's monthly_price: what a month costs at most, net, at the team's price
sortprice, -price

A bad value throws ValidationFailedException. Details: Catalog filters.

Lists ​

Lists return a BaseCollection of resources:

php
$containers = $console->containers()->list();

foreach ($containers as $container) { … }

$containers->count();
$containers->first();
$containers->all();
$containers->total();          // across all pages
$containers->currentPage();
$containers->lastPage();
$containers->hasMorePages();
$next = $containers->nextPage();       // the next page, or null
$prev = $containers->previousPage();
$containers->paginate();       // the raw Result

Resources ​

Resources (Order, Container, Team, Catalog, Product, …) expose the API's fields as properties:

  • nested objects are stdClass,
  • unknown fields read as null,
  • toArray() and JSON serialization work,
  • $resource->result holds the response.

Resources from webhooks have no API client; bind one to act on them:

php
$event->object->withClient(AnikeenConsole::forUser($user))->power('start');

Other endpoints ​

Areas without an SDK wrapper yet (servers, domains, DNS zones, web hosting, load balancers) can be called through the same client - with token refresh and exceptions:

php
$result = $console->call('GET', 'zones', query: ['name' => 'example.com']);
$zones = $result->data;

call() throws the matching exception on failure; send() returns the Result also for 4xx/5xx. A Result has status, body, data and paginator, plus success(), message(), errorCode(), retryAfter() and header().

Anikeen Console documentation