JSON Overview

We recommend using the JavaScript library wherever possible instead of calling the web service directly. However, there may be cases where it is desirable to call our web service (such as in the case of PHP). To do so, simply use the JSON Service web resource and specify the service to call. Note that you can pass a callback name as “callback=”. You can send name/value pairs OR you can send JSON.

Name/value pairs are sent as arguments on an HTTP GET or as data on an HTTP POST. When using HTTP POST, be sure to specify the content-type as “application/x-www-form-urlencoded”

Example as an HTTP GET

JSON can be sent as a name/value pair by either sending a name/value pair called “jsonp”, or by setting content-type on an HTTP POST to “application/json”

Example using jsonp as a name/value

Note: Don’t forget that data on URLs must be URL-Encoded and the above example shows clear text for clarity of content. It is not an accurate URL encoding!

Example using application/json as a content-type:

General

  1. The “service=” value must be provided, and the value is case-sensitive
  2. A “callback=” value is optional and will produce a JavaScript call to the callback
  3. Please use https (SSL) instead of http for all transactions
  4. Please send transactions to trans.slimcd.com and pull reports from stats.slimcd.com
  5. We recommend using HTTP POST instead of HTTP GET whenever possible
  6. Field names in HTTP GET/POST name/value pairs or JSON are not case-sensitive if they are arguments to the WebService functions and not inside WebService XML blocks (see the WebServices tabs for more information)
  7. Field names in JSON replies are case-sensitive
  8. Default values will be provided for any field that is not included or is empty in the request
    • Items of type “int” in the WebServices will be set to zero
    • Items of type “bool” in the WebServices will be set to false
    • Items of type “string” in the WebServices will be set to an empty string
    • Items of type “string” that represent date values in the WebServices will be set to the current date
    • Items of type “date” in the WebServices will be set to the current date/time
  9. JSON or name/value pairs can be sent via HTTP POST
    • To send name/value pairs as the HTTP BODY (standard form post):
      • the HTTP POST header’s Content-type must be set to “application/x-www-form-urlencoded”
      • The values for all name/value pairs must be url-encoded
    • To send JSON a name/value pair in an HTTP GET/POST:
      • the HTTP POST header’s Content-type must be set to “application/x-www-form-urlencoded”
      • set the name/value pair named “jsonData” to the url-encoded request object string
    • To send JSON as the HTTP BODY:
      • the HTTP POST header’s Content-type must be set to “application/JSON”

jQuery-Specific

  1. the ajax function supports direct cross-domain calls using either
    • Call to Ajax: $.ajax({ crossDomain: true, dataType: ‘jsonp’ }
    • Set CORS: $.support.cors=true; // before calling $.ajax
  2. the timeout value is in milliseconds, so 10 minutes is 600000 milliseconds
  3. the content type is specified with “contentType”
  4. the “service” value can either be placed on the URL or placed as one of the request name/value items
  5. the parameters to the web service can be
    • name/value pairs as the querystring or body of the POST, with each name/value created from either JSON or a JavaScript array (jQuery does this for you)
    • json object as the body of the POST, where jQuery serializes the data for you as either name/value pairs or application/json content
    • a single name/value object called “jsonData”, where the value is a JSON.stringify version of the object (jQuery also does this for you)