Overview

API calls to the server can be performed using cURL - a command line transferring data via multiple protocols.

Prepare the Request

The request is performed via JSON-RPC and transferred to the server via an HTTP POST. The request can be placed in a text file.

getAdminStatistics.json
{
    "method": "getAdminStatistics",
    "params": [1015,1315972800,1316059200],
    "id": 1
}

There are three parts to the request

  1. method: This is a string indicating the method in the API you want to call (the class is specified via URL)
  2. params: This is a JSON encoded array of parameters in the same order as defined in the method you are calling
  3. id: This is a value used to correlate a response with a request. This can be any value

Sample requests are attached to this page as requests.zip

Send the Request

Now that the request has been prepared, we can send the request to the server

Send the Request
curl --cookie PHPSESSID=<your session> --data @getAdminStatistics.json --url http://dev05web01.online.disney.com/en/ClubPenguin/phraseapproval/json/0

The first parameter, --cookie, is used to pass key/value pairs as cookies. In this sample, we are sending a PHPSESSID, which is needed for all API calls requiring an authenticated user. The session ID can be obtained from view a request in Charles. The --cookie parameter can be passed only once. To specify multiple cookies, separate name=value pairs with a semicolon. Don't forget to quote the whole cookie parameter. If I wanted to trigger xDebug to connect to Eclipse, I would use use

cURL with multiple cookies
curl --cookie "PHPSESSID=<session_id>;XDEBUG_SESSION=1" --data @getAdminStatistics.json --url http://dev05web01.online.disney.com/en/ClubPenguin/phraseapproval/json/0

The second parameter, --data, is used to POST the contents of the file specified to the web server (file name must be prefixed with @). The file would be the JSON-RPC prepared in the previous step.

The third parameter, --url, is used to specify the target of the POST. The path in the URL is broken down into five components

  1. The language (eg: 'en' for English)
  2. The virtual world (eg: 'ClubPenguin')
  3. The API key (eg: 'phraseapproval' for PhraseApprovalClientAPI. The key/class mapping is defined in ClientAPIFactory)
  4. The RPC type (eg: 'json' for JSON-RPC)
  5. The task ID (normally not used, except in Flurry)

Tips

  • For complex parameter types, it would be easiest to build them in PHP and use json_encode() to generate the JSON representation
  • To have cURL use Charles as a proxy, set the http_proxy environment variable to localhost on port 8888 (Charles' default)
    export http_proxy=127.0.0.1:8888
    

Attachments:

requests.zip (application/zip)