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 https://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:

<?php
$data = array("C"=>"Pap_Api_AuthService","M"=>"authenticate","fields"=>array(array("name","value","values","error"),array("username","merchantuser@test.com",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 = 'https://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);
curl_close($curl);
echo ($json_response);
?>

Example for creating and sending login JSON request in CURL:

curl --location --request POST 'https://your_postaffiliatepro_url/scripts/server.php' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'D={"C":"Pap_Api_AuthService","M":"authenticate","fields":[["name","value","values","error"],["username","MERCHANT@USERNAME.COM",null,""],["password","PASSWORD@1234",null,""],["roleType","M",null,""],["isFromApi","Y",null,""],["apiVersion","c278cce45ba296bc421269bfb3ddff74",null,""]]}'

"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

 

×