PHP code example of keboola / notification-api-php-client

1. Go to this page and download the library: Download keboola/notification-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/ */

    

keboola / notification-api-php-client example snippets


use DateTimeImmutable;
use Keboola\NotificationClient\EventsClient;
use Keboola\NotificationClient\Requests\Event;
use Keboola\NotificationClient\Requests\PostEvent\JobData;
use Keboola\NotificationClient\Requests\PostEvent\JobFailedEventData;

$client = new EventsClient(
    'https://notification.connection.keboola.com/',
    'xxx-xxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', // or null to use the ServiceAccount token
    backoffMaxTries: 3,
    userAgent: 'my-service',
);
$client->postEvent(
    new Event(
        new JobFailedEventData(
            '123',
            'My Project',
            'branch-id',
            'Job finished with error',
            new JobData(
                '456',
                'http://someUrl',
                new DateTimeImmutable('2020-01-01T11:11:00+00:00'),
                new DateTimeImmutable('2020-01-01T11:12:00+00:00'),
                'keboola.orchestrator',
                'Orchestrator',
                'my-configuration',
                'My configuration',
            ),
        )
    )
);

use Keboola\NotificationClient\Requests\PostSubscription\EmailRecipient;
use Keboola\NotificationClient\Requests\PostSubscription\Filter;
use Keboola\NotificationClient\Requests\Subscription;
use Keboola\NotificationClient\SubscriptionClient;

$subscriptionClient = new SubscriptionClient(
    'https://notification.connection.keboola.com/',
    'xxx-storage-api-token',
);

// create a subscription
$created = $subscriptionClient->createSubscription(new Subscription(
    'job-failed',
    new EmailRecipient('[email protected]'),
    [new Filter('project.id', '123')],
));

// list all subscriptions for the project (returned by token)
$subscriptions = $subscriptionClient->listSubscriptions();
foreach ($subscriptions as $subscription) {
    echo $subscription->getId() . ': ' . $subscription->getEvent() . "\n";
}

// fetch a single subscription by ID
$subscription = $subscriptionClient->getSubscription($created->getId());

// delete a subscription
$subscriptionClient->deleteSubscription($created->getId());

use Keboola\NotificationClient\Responses\Recipient\EmailRecipient;
use Keboola\NotificationClient\Responses\Recipient\WebhookRecipient;

$recipient = $subscription->getRecipient();
if ($recipient instanceof EmailRecipient) {
    $email = $recipient->getAddress();
} elseif ($recipient instanceof WebhookRecipient) {
    $url = $recipient->getUrl();
}
json 
    {
      "appId": "268a6f05-xxxxxxxxxxxxxxxxxxxxxxxxxxx", //-> TEST_AZURE_CLIENT_ID
      "displayName": "testing-notification-api-php-client",
      "name": "http://testing-notification-api-php-client",
      "password": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", //-> TEST_AZURE_CLIENT_SECRET
      "tenant": "9b85ee6f-xxxxxxxxxxxxxxxxxxxxxxxxxxx" //-> TEST_AZURE_TENANT_ID
    }