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
0 1 2 |
http://.../jsonscript.asp?service=GetDailySummary&callback=myfunction&username=X&password=Y |
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
0 1 2 |
http://.../jsonscript.asp?service=GetDailySummary&callback=myfunction&jsonp={ { “username”:”X”} , {“password”:”Y”} } |
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:
0 1 2 3 4 5 6 7 |
HTTP POST to http://.../jsonscript.asp?service=GetDailySummary&callback=mycallback content-type=application/json { { "username":"X" } , { "password":"Y" } } |
General
- The “service=” value must be provided, and the value is case-sensitive
- A “callback=” value is optional and will produce a JavaScript call to the callback
- Please use https (SSL) instead of http for all transactions
- Please send transactions to trans.slimcd.com and pull reports from stats.slimcd.com
- We recommend using HTTP POST instead of HTTP GET whenever possible
- 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)
- Field names in JSON replies are case-sensitive
- 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
- 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”
- the HTTP POST header’s Content-type must be set to “application/JSON”
- To send name/value pairs as the HTTP BODY (standard form post):
jQuery-Specific
- 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
- the timeout value is in milliseconds, so 10 minutes is 600000 milliseconds
- the content type is specified with “contentType”
- the “service” value can either be placed on the URL or placed as one of the request name/value items
- 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)