Callback Request

There are times when we want to submit data to Selfhelp from another application. Then we need a callback request and a way to handle it.

1. System Overview

All callback requests must be sent to the url /callback/[v:class]/[v:method] where [v:class] is the name of a PHP class and [v:method] the name of a method of the class. The class and the method must be defined in the folder server/callback/.

The folder server/callback/ already contains several files holding class definitions and methods which are used callbacks and can serve as examples. Note that the following two files are special utility files and should not be extended lightly:

  • server/callback/BaseCallback.php: A base class which provides easy access to services and ACL control. When creating a new Callback request class use this as parent.
  • server/ajax/CallbackRequest: A wrapper class which will
    • load the correct php file
    • instantiate the class indicated with the request url
    • execute the callback method by passing POST parameters
    • evaluate ACL as defined in the class BaseCallback
    • encode the return value of the callback function as JSON
2. Create the Request Callback

To create a new request callback, either create a new method in an existing class or create a new class. Note that if a new class is created it must be placed in a new file and the file name must match the class name exactly and requires the .php file extension.

The callback method receives the php $_POST variable as parameter. Hence, all request data needs to be sent via POST to the server and cannot be attached as GET variables. The callback request can be protected with a callback key which is stored in CMS preferences for a private callback calls or no api key check if the callback is public.