Getting started example

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("http://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.

 


//----------------------------------------------
// get recordset with list of affiliates
$request = new Pap_Api_AffiliatesGrid($session);
// sets limit to 30 rows, offset to 0 (first row will start)
$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("http://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 limit to 30 rows, offset to 0 (first row will start)
$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>';
}
?>