Skip to content

Instantly share code, notes, and snippets.

@mbernson
Last active January 2, 2018 19:10
Show Gist options
  • Save mbernson/2b7bc866c854193c2650af34c0260e14 to your computer and use it in GitHub Desktop.
Save mbernson/2b7bc866c854193c2650af34c0260e14 to your computer and use it in GitHub Desktop.
Listing/adding/removing notification filters using the bunq API
<?php
use bunq\Context\ApiContext;
use bunq\Model\Generated\Endpoint\User;
use bunq\Model\Generated\Endpoint\UserCompany;
use bunq\Model\Generated\Endpoint\UserPerson;
use bunq\Model\Generated\Object\NotificationFilter;
require 'vendor/autoload.php';
const INDEX_FIRST = 0;
$apiContext = ApiContext::restore();
$users = User::listing($apiContext)->getValue();
// If your user is UserPerson or UserLight, replace getUserCompany() with getUserPerson() or getUserLight()
$user = $users[INDEX_FIRST]->getUserCompany();
echo "Current UserCompany: ".$user->getDisplayName()."\n";
$userCompany = UserCompany::get($apiContext, $user->getId());
$notificationFilters = $userCompany->getValue()->getNotificationFilters();
// Add the new notification filter
$notificationFilters[] = new NotificationFilter('URL', 'https://mywebsite.nl/foo/bar/', 'MUTATION');
// Replace all notification filters with the updated array
UserCompany::update($apiContext, [
UserPerson::FIELD_NOTIFICATION_FILTERS => $notificationFilters,
], $user->getId());
echo "Added the filter\n";
<?php
use bunq\Context\ApiContext;
use bunq\Model\Generated\Endpoint\User;
use bunq\Model\Generated\Endpoint\UserCompany;
use bunq\Model\Generated\Endpoint\UserPerson;
use bunq\Model\Generated\Object\NotificationFilter;
require 'vendor/autoload.php';
const INDEX_FIRST = 0;
$apiContext = ApiContext::restore();
$users = User::listing($apiContext)->getValue();
// If your user is UserPerson or UserLight, replace getUserCompany() with getUserPerson() or getUserLight()
$user = $users[INDEX_FIRST]->getUserCompany();
echo "Current UserCompany: ".$user->getDisplayName()."\n";
$userCompany = UserCompany::get($apiContext, $user->getId());
$notificationFilters = $userCompany->getValue()->getNotificationFilters();
foreach ($notificationFilters as $filter) {
echo $filter->getNotificationDeliveryMethod() . " " . $filter->getCategory() . " " .$filter->getNotificationTarget() . "\n";
}
<?php
use bunq\Context\ApiContext;
use bunq\Model\Generated\Endpoint\User;
use bunq\Model\Generated\Endpoint\UserCompany;
use bunq\Model\Generated\Endpoint\UserPerson;
use bunq\Model\Generated\Object\NotificationFilter;
require 'vendor/autoload.php';
const INDEX_FIRST = 0;
$apiContext = ApiContext::restore();
$users = User::listing($apiContext)->getValue();
// If your user is UserPerson or UserLight, replace getUserCompany() with getUserPerson() or getUserLight()
$user = $users[INDEX_FIRST]->getUserCompany();
echo "Current UserCompany: ".$user->getDisplayName()."\n";
$userCompany = UserCompany::get($apiContext, $user->getId());
$notificationFilters = $userCompany->getValue()->getNotificationFilters();
for ($i = 0; $i < count($notificationFilters); $i++) {
$filter = $notificationFilters[$i];
// Remove any URL notification callbacks for the MUTATION category from the array
if ($filter->getNotificationDeliveryMethod() == 'URL' && $filter->getCategory() == 'MUTATION') {
echo "Removing URL filter targeting ".$filter->getNotificationTarget()."\n";
unset($notificationFilters[$i]);
}
}
// Replace all notification filters with the updated array
UserCompany::update($apiContext, [
UserPerson::FIELD_NOTIFICATION_FILTERS => $notificationFilters,
], $user->getId());
echo "Removed the URL notification filters\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment