Data model (JSON) example of use

In Post Affiliate Pro you can create and use JSON data model for any action that is possible to do via Merchant Panel and Affiliate Panel. You can get the actual JSON which is called on different actions by debugging the requests with Firebug for example.

The JSON data which you get by debugging should be URL encoded (you can use this nice tool or urlencode() function in PHP) and sent in D parameter to http://your_postaffiliatepro_url/scripts/server.php. You can use either GET or POST method for the request although for security reasons we strongly recommend to use POST.

If you use POST the request should be sent with Content-Type header set to application/x-www-form-urlencoded (curl function in PHP does this automatically when using POST).
If you wish to get a nice array for the $data variable in the bellow example code you can use the json_decode($variable, true); function on the JSON which you obtain by debugging.


Example for creating and sending login JSON request in php:

$data = array("C"=>"Pap_Api_AuthService","M"=>"authenticate","fields"=>array(array("name","value","values","error"),array("username","",null,""),array("password","xxxx",null,""),array("roleType","M",null,""),array("language","en-US",null,""),array("isFromApi","Y",null,""),array("apiVersion","",null,"")));
$encodedJsonData = 'D=' . urlencode(json_encode($data));  //encoded json data request
$url = 'http://your_postaffiliatepro_url/scripts/server.php';
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $encodedJsonData);
$json_response = curl_exec($curl);
echo ($json_response);

"Class does not exist" or "Invalid format of class name or method name"

In case your request is not correct you can get an error response like:

  • {"e":"Class does not exist"}
  • {"e":"Invalid format of class name or method name"}
This usually happens if:
  • the JSON payload/data is not encoded properly
  • it is not added as post parameter "D"
  • you've really used wrong class name or method in your request
  • the request isn't send with Content-Type header set to application/x-www-form-urlencoded