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 Keboola\NotificationClient\EventsClient;
use Keboola\NotificationClient\Requests\PostEvent\JobFailedEventData;
use Keboola\NotificationClient\Requests\PostEvent\JobData;
use Keboola\NotificationClient\Requests\Event;
use Psr\Log\NullLogger;

$client = new EventsClient(
    new NullLogger(),
    'http://notifications.connection.keboola.com/',
    'xxx-xxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
);
$client->postEvent(
    new Event(        
        new JobFailedEventData(
            '123',
            'My Project',
            'Job finished with error',
            new JobData('my-project', '123', 'http://someUrl', '2020-01-02', '2020-01-01', 'my-orchestration')
        )
    )
);

use Keboola\NotificationClient\ClientFactory;

$clientFactory = new ClientFactory('https://connection.keboola.com');
$clientFactory->getEventsClient('xxx-xxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');

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

$clientFactory = new ClientFactory('https://connection.keboola.com');
$subscriptionClient = $clientFactory->getSubscriptionClient('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
    }