Article ID: 120170, created on Feb 17, 2014, last review on Nov 18, 2015

  • Applies to:
  • APS 2.x


I want to run some code when limits for my application's resources are changed in a subscription. For instance, as soon as the customer purchases additional amount of a certain resource, I want to send a notification about it to some external system. How can I do this?


In most cases, if your application needs to keep track of some limits in external system (disk space, traffic, etc.) you should implement counters in customer's resource. Then, if limits for counter change, your resource gets a PUT request with new limits (or, if you use PHP runtime, configure function is executed, more about this in documentation, you may also want to check out the resource consumption monitoring project).

Starting with POA 5.5.7 it is possible to subscribe to a custom event that is triggered when resources limits is changed in POA subscription.

More information about this event is available in documentation.

If you use the PHP runtime library, you can subscribe to these events like this:

  • You need to declare a relation with POA subscription in customer's resource (typically the one that is automatically provided automatically):

     * @link("")
     * @required
    public $subscription;
  • Then, from any function in your code, e.g. from provision(), you can subscribe to limits change event for this subscription:

    $sub = new \APS\EventSubscription("", "onLimitChange");
    $apsc = \APS\Request::getController();
    $apsc->subscribe($this, $sub);
  • Finally, declare the actual event handler with the logic you need executed when limits change. This example will add a log entry:

     * @verb(POST)
     * @path("/onLimitChange")
     * @param("",body)
    public function onLimitChange($event) {
        APS\Logger::get()->debug("Limits changed, and we got a notification about it!");

After subscription limits get changed, onLimitChange function for your resource will be called by APS controller. Note that you will not get limits with the event object, you can fetch the limits using the SubscriptionResource structure in the event handler.

70bf700e0cdb9d7211df2595ef7276ab 717db81efe94e616312b74fb03a5d474

Email subscription for changes to this article
Save as PDF