JSON Data Model description

The data transferred between the client (your script making requests) and the server (represented by scripts > server.php) is encoded in JSON format. This is the lowest level of communication.

You can use this level of communication if you cannot use our PHP-based API (PapApi.class.php), which allows you to create requests and process responses more easily.

Pap_Api_Session (Gpf_Api_Session)

Login JSON request contains the following parameters:

  • C: Class name, Pap_Api_AuthService
  • M: Method name, authenticate
  • fields: List of fields:
    • username
    • password
  • roleType: M for merchant username, A for affiliate username
  • isFromApi: Should always be Y
  • apiVersion: Version hash code from PapApi.class.php; can be empty

Example login JSON request:

{"C":"Pap_Api_AuthService","M":"authenticate","fields":[["name","value","values","error"],["username","merchant@example.com",null,""],["password","demo",null,""],["roleType","M",null,""],["isFromApi","Y",null,""],["apiVersion","c278cce45ba296bc421269bfb3ddff74",null,""]]}

Login JSON response contains:

  • fields: List of fields in the format ["name","value","values","error"]:
    • correspondsApi: Y or N; indicates if API version hash code matches the version of Post Affiliate Pro
    • username
    • password
    • accountid
    • rememberMe
    • language
    • S: Session ID (this is required for all subsequent API requests)
  • success: Y or N; indicates if the username is correct
  • message: Information about the success or failure of the login

Example JSON response:

{"fields":[["name","value","values","error"],["correspondsApi","N",null,""],["username","merchant@example.com",null,""],["password","demo",null,""],["accountid","",null,""],["rememberMe","N",null,""],["language","en-US",null,""],["S","6ble393nqp6tpla842bmmimop5",null,null]],"success":"Y","message":"User authenticated. Logging in."}

Gpf_Rpc_Request

Gpf_Rpc_Request is the base for all requests.

A request JSON contains the following parameters:

  • C: Class name
  • M: Method name
  • S: Session ID

(It may contain other parameters, depending on the specific request.)

Example: Loading the count of rows from the affiliate grid (contains only class name, method name, and session ID):

{"C":"Pap_Merchants_User_AffiliatesGrid","M":"getRowCount","S":"u2on93uhrr6jqbvjl32ncui4f0"}

Response for this request:

{"rows":[[]],"count":14}

count indicates the number of rows in the affiliate grid. The rows field is empty because only the count was requested.

Another example of a request for loading traffic statistics data (in addition to class name, method name, and session ID, this request also contains a list of filters):

{"C":"Pap_Merchants_Reports_TrafficStatsData","M":"load","filters":[["datetime","DP",""],["rstatus","IN","A"],["campaignid","E","11111111"]],"S":"u2on93uhrr6jqbvjl32ncui4f0"}

Response for this request:

[["name","value"],["countImpressions","167"],["countClicks",99],["countSales",66],["sumSales",233004],["sumCommissions",44039.94]]

The response contains a list of fields in the format ["name","value"].

Gpf_Rpc_FormRequest

Gpf_Rpc_FormRequest can be used to send form information (it extends Gpf_Rpc_Request).

Request JSON contains the following parameters:

  • C: Class name (suffix Form)
  • M: Method name (generally add, load, or save)
  • fields: List of form fields in the format ["name","value"]
  • S: Session ID

Example: Request for adding an affiliate to a commission group:

{"C":"Pap_Features_CommissionGroups_AffiliateGroupForm", "M":"add", "fields":[["name","value"],["Id",""],["userid","ceba10bf"],["rstatus","A"],["note",""],["commissiongroupid","a17209a9"],["campaignid","11111111"]],"S":"u2on93uhrr6jqbvjl32ncui4f0"}

Response for this request contains:

  • fields: List of fields in the format ["name","value","values","error"]
  • success: Y or N
  • message: Information about the success or failure
{"fields":[["name","value","values","error"],["Id","73c468b0",null,""],["userid","ceba10bf",null,""],["rstatus","A",null,""],["note","",null,""],["commissiongroupid","a17209a9",null,""],["campaignid","11111111",null,null],["usercommgroupid","73c468b0",null,""],["dateadded","2012-04-27 09:12:23",null,""]],"success":"Y","message":"Affiliate was successfully added"}

Gpf_Rpc_GridRequest

Gpf_Rpc_GridRequest can be used to retrieve lists of affiliates, transactions, campaigns, etc.

Request JSON contains the following parameters:

  • C: Class name (suffix Grid)
  • M: Method name (generally getRows)
  • sort_col: Name of the sorting column
  • sort_asc: false or true
  • offset: Number of rows to skip
  • limit: Number of rows to retrieve
  • filters: List of filters for the data (optional; if omitted, only the default filter is used)
  • columns: List of column names in the format ["name"] (optional; if omitted, the response contains the default columns for the grid)
  • S: Session ID

Example: Request for loading affiliates grid rows:

{"C":"Pap_Merchants_User_AffiliatesGrid", "M":"getRows", "sort_col":"dateinserted", "sort_asc":false, "offset":0, "limit":30,"filters":[["dateinserted","DP","TY"],["rstatus","IN","A,D,P"]], "columns":[["id"],["id"],["refid"],["userid"],["username"],["firstname"],["lastname"],["rstatus"],["parentuserid"],["parentusername"],["parentfirstname"],["parentlastname"],["dateinserted"],["actions"]], "S":"u2on93uhrr6jqbvjl32ncui4f0"}

Response for this request contains:

  • rows: All loaded data (the first row contains the column names)
  • count: Number of loaded rows
{"rows":[["id","userid","refid","firstname","lastname","username","rstatus","dateinserted","parentuserid","parentusername","parentfirstname","parentlastname"],["96beb96f","96beb96f","testaff","Test","Affiliate","affiliate@example.com","A","2012-03-08 07:13:27",null,null,null,null],["761b2a5d","761b2a5d","aff","test","affiliate","test@affiliate.com","A","2012-02-06 02:33:30",null,null,null,null]],"count":2}

Multirequest

If you want to send multiple requests at once, you can merge them into a single request (multirequest). A multirequest is sent to the class Gpf_Rpc_Server with the method run and the parameter requests. If the requests require authentication, you do not need to include the session ID in every individual request in the multirequest; it is sufficient to provide the session ID in the multirequest as the parameter S.

Example JSON (two requests in one multirequest):

{"C":"Gpf_Rpc_Server", "M":"run", "requests":[{"C":"Pap_Merchants_User_AffiliatesGrid", "M":"getRows", "sort_col":"dateinserted", "sort_asc":false, "offset":0, "limit":30, "columns":[["id"],["id"],["refid"],["userid"],["username"],["firstname"],["lastname"],["rstatus"],["parentuserid"],["parentusername"],["parentfirstname"],["parentlastname"],["dateinserted"],["actions"]]},{"C":"Pap_Features_CommissionGroups_AffiliateGroupForm", "M":"add", "fields":[["name","value"],["Id",""],["userid","ceba10bf"],["rstatus","A"],["note",""],["commissiongroupid","a17209a9"],["campaignid","11111111"]]}], "S":"r3egjfj4d2te8aou4k37rckkr7"}

For a PHP example, see: Data model JSON example of use

For more information on sale/action tracking request data model, refer to: Sale/action tracking request data model (JSON) description

×