We'll make a short example of making a simple request that will retrieve a list of affiliates. You will get more detailed documentation about the classes and methods in the documentation for each class.
To start using the API, you have to include file PapApi.class.php into your PHP code.
This file contains all the necessary classes.
You can download the PapApi.class.php file from the merchant panel: Tools > Integration > API Integration > Download PAP API
include 'PapApi.class.php';
The next thing we have to do is to create session for the application. You have to do it by logging in with your username and password.
One more thing to specify is the URL to the /scripts/server.php.
//----------------------------------------------
// login (as merchant)
$session = new Pap_Api_Session("https://demo.postaffiliatepro.com/scripts/server.php");
if(!@$session->login("merchant@example.com", "demo")) {
die("Cannot login. Message: ".$session->getMessage());
}
You can log in using either merchant or affiliate. By default it is assumed you are a merchant.
Unless stated otherwise, all the examples in this documentation are made with merchant (administrator) functionality.
After successful login you can do another requests, for example retrieving list of affiliates.
Note: The first parameter of setLimit() is an offset that is no longer used since version 5.11.8.1 — always pass 0. Paging is handled automatically: sending the same request object again returns the next page of records. The maximum number of records returned in one request is 500. Details are described in the Gpf_Rpc_GridRequest article.
//----------------------------------------------
// get recordset with list of affiliates
$request = new Pap_Api_AffiliatesGrid($session);
// sets the page size to 30 rows
// the first parameter is an offset which is not used, always keep it at 0
$request->setLimit(0, 30);
// send request
try {
$request->sendNow();
} catch(Exception $e) {
die("API call error: ".$e->getMessage());
}
// request was successful, get the grid result
$grid = $request->getGrid();
// get recordset from the grid
$recordset = $grid->getRecordset();
// iterate through the records
foreach($recordset as $rec) {
echo 'Affiliate name: '.$rec->get('firstname').' '.$rec->get('lastname').'<br>';
}
Complete source code for the example
<?php
include 'PapApi.class.php';
//----------------------------------------------
// login (as merchant)
$session = new Pap_Api_Session("https://demo.postaffiliatepro.com/scripts/server.php"
);
if(!$session->login("merchant@example.com","demo")) {
die("Cannot login. Message: ".$session->getMessage());
}
//----------------------------------------------
// get recordset with list of affiliates
$request = new Pap_Api_AffiliatesGrid($session);
// sets the page size to 30 rows
// the first parameter is an offset which is not used, always keep it at 0
$request->setLimit(0, 30);
//----------------------------------------------
// send request
try {
$request->sendNow();
} catch(Exception $e) {
die("API call error: ".$e->getMessage());
}
//----------------------------------------------
// request was successful, get the grid result
$grid = $request->getGrid();
//----------------------------------------------
// get recordset from the grid
$recordset = $grid->getRecordset();
echo 'Total number of affiliates: '.$grid->getTotalCount().'<br>';
echo 'Number of affiliates returned in result: '.$recordset->getSize();
// iterate through the records
foreach($recordset as $rec) {
echo 'Affiliate name: '.$rec->get('firstname').' '.$rec->get('lastname').'<br>';
}
?>