class representing session (logged user). You must log in using this object before making any other requests.


constructor Pap_Api_Session($url) – creates session object. You have to specify full valid URL to the /scripts/server.php file of your installation.

For example:

login($username, $password, $roleType, $languageCode) – authorizes the user and creates session object. The username and password must be your merchant or affiliate login information.

By default the user is considered to be a merchant. If you want to log in as an affiliate, you have to specify the third parameter $roleType = self::AFFILIATE.

$languageCode parameter is optional. If you do not specify any value for this parameter, default language will be used. Language can be secified by its code e.g. en-US, de-DE, sk, cz, ...

If login was successful, it returns true, otherwise false. If you use incompatible API version, login throws Gpf_Api_IncompatibleVersionException (see bellow for more details).

setDebug(true/false) sets debugging. If you set it to true, it will output every request and response in JSON format.

getMessage() - returns error message in case of error

Logging in as merchant:

$session = new Pap_Api_Session('');
if(!$session->login('', 'demo')) {
  die("Cannot login. Message: ".$session->getMessage());

Logging in as affiliate

$session = new Pap_Api_Session('');
if(!$session->login('', 'demo', Pap_Api_Session::AFFILIATE)) {
  die("Cannot login. Message: ".$session->getMessage());

Of course, as an affiliate you don't have access to the functionality of merchant, for example to the list of all affiliates.

If you want to redirect user (merchant/affiliate) to his panel after Pap_Api_Session is created you can do it using following code:

// redirecting to merchant panel (requires merchant session)
header('Location: '.$session->getUrlWithSessionInfo(''));

// redirecting to affiliate panel (requires affiliate session)
header('Location: '.$session->getUrlWithSessionInfo(''));

Get version of installed application by calling of method getAppVersion. Returns string (version number) or false in case of error was generated.
Example: Print version of Post Affiliate Pro installation.
$session = new Pap_Api_Session('');
if ($papversion = $session->getAppVersion()) {
    echo 'Post Affiliate Pro version: ' . $papversion;
} else {
    echo 'Failed to load version with error: ' . $session->getMessage();
$session->login(...) throws Gpf_Api_IncompatibleVersionException exception in case when your PapApi.class.php file is not compatible with PostAffiliatePro you are connecting to. Example of handling this exception:
$session = new Pap_Api_Session('');
try {
    if (!$session->login('', 'demo')) {
        die("Unable to login: ".$session->getMessage());
    echo "logged";
} catch (Gpf_Api_IncompatibleVersionException $e) {
    echo "Download new API file here: ".$e->getApiDownloadLink();

Method getApiDownloadLink() in Gpf_Api_IncompatibleVersionException returns full url o the PapApi.class.php file of the installation you are connecting to so you can download it and update your PapApi.class.php file.


setSessionId($sessionId) - use this instead of login() function, for login from session id. If you wish to log in as affiliate, also specify the role with second parameter set to Pap_Api_Session::AFFILIATE.

Authenticate as merchant:

$session = new Pap_Api_Session('');

Authenticate as affiliate:

$session = new Pap_Api_Session('');
$session->setSessionId('sdf4sdfg5465sdfgqw65uytkm68fguku', Pap_Api_Session::AFFILIATE);