PHP code example of incident-io / sdk-php

1. Go to this page and download the library: Download incident-io/sdk-php 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/ */

    

incident-io / sdk-php example snippets


use IncidentIo\Api\IncidentsV2Api;
use IncidentIo\Configuration;

$config = (new Configuration())->setAccessToken(getenv('INCIDENT_API_KEY'));
$incidents = new IncidentsV2Api(config: $config);

$result = $incidents->incidentsV2List(pageSize: 25);
foreach ($result->getIncidents() as $incident) {
    echo $incident->getReference(), ' ', $incident->getName(), "\n";
}

use IncidentIo\Api\IncidentsV2Api;
use IncidentIo\Model\IncidentsCreatePayloadV2;

$incident = $incidents->incidentsV2Create(new IncidentsCreatePayloadV2([
    'idempotencyKey' => 'deploy-2026-09-23-01',
    'name' => 'Checkout is returning 500s',
    'severityId' => '01FH5TZRWMNAFB0DZ23FD1TV96',
    'visibility' => IncidentsCreatePayloadV2::VISIBILITY__PUBLIC,
]))->getIncident();

use IncidentIo\ApiException;

try {
    $incidents->incidentsV2Show(id: '01NOTREAL');
} catch (ApiException $e) {
    echo $e->getCode(), "\n";           // 404
    echo $e->getResponseBody(), "\n";   // {"type":"not_found","status":404,"request_id":"...","errors":[...]}
}

$after = null;
do {
    $page = $incidents->incidentsV2List(pageSize: 100, after: $after);
    foreach ($page->getIncidents() as $incident) {
        // ...
    }
    $after = $page->getPaginationMeta()?->getAfter();
} while ($after !== null && $after !== '');

$incidents->incidentsV2List(
    statusCategory: ['one_of' => ['live', 'learning']],
    severity: ['gte' => ['01FH5TZRWMNAFB0DZ23FD1TV96']],
    customField: ['01FCNDV6P870EA6S7TK1DSYDG0' => ['one_of' => ['01FCNDV6P870EA6S7TK1DSYDG1']]],
);

use IncidentIo\Model\ActionV1;

match ($action->getStatus()) {
    ActionV1::STATUS_OUTSTANDING => 'open',
    ActionV1::STATUS_COMPLETED, ActionV1::STATUS_NOT_DOING => 'done',
    default => 'unknown',
};

use GuzzleHttp\Client;

$incidents = new IncidentsV2Api(new Client(['timeout' => 10]), $config);

use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

$stack = HandlerStack::create();
$stack->push(Middleware::retry(
    function (int $retries, RequestInterface $request, ?ResponseInterface $response, ?\Throwable $error): bool {
        if ($retries >= 4) {
            return false;
        }
        return $error !== null || ($response !== null && ($response->getStatusCode() === 429 || $response->getStatusCode() >= 500));
    },
    function (int $retries, ?ResponseInterface $response): int {
        $retryAfter = $response?->getHeaderLine('Retry-After');
        return $retryAfter !== null && ctype_digit($retryAfter)
            ? (int) $retryAfter * 1000
            : min(30_000, 1000 * 2 ** ($retries - 1));
    },
));

$incidents = new IncidentsV2Api(new Client(['handler' => $stack]), $config);

use IncidentIo\Api\AlertEventsV2Api;
use IncidentIo\Model\AlertEventsCreateHTTPPayloadV2;

(new AlertEventsV2Api())->alertEventsV2CreateHTTP(
    alertSourceConfigId: '01GW2G3V0S59R238FAHPDS1R66',
    alertEventsCreateHTTPPayloadV2: new AlertEventsCreateHTTPPayloadV2([
        'title' => 'Disk almost full',
        'status' => AlertEventsCreateHTTPPayloadV2::STATUS_FIRING,
        'deduplicationKey' => 'disk-db-1',
    ]),
    authorization: 'Bearer ' . getenv('ALERT_SOURCE_SECRET'),
);