JSON Data Model example of use

Using the JSON Data Model for API Actions in Post Affiliate Pro

In Post Affiliate Pro, you can create and use a JSON data model for any action that is possible via the Merchant Panel or Affiliate Panel. You can obtain the actual JSON used for different actions by debugging the requests, for example, with Firebug.

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

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

Example: Creating and Sending a 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: Creating and Sending a Login JSON Request with 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"

If your request is not correct, you may receive an error response such as:

  • {"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 the POST parameter D.
  • You have used an incorrect class name or method in your request.
  • The request is not sent with the Content-Type header set to application/x-www-form-urlencoded.
×