I4A API Guide
I4A API Guide
About
This guide will outline how to use the Internet4associations API. The api makes use of the SOAP protocol for authentication only. All other aspects of the API use REST.
Currently the API determines if the user wishes to retrieve an Object or a Collection based on the plurality of the object. So requesting: /membership.contact/ and /membership.contacts/ will access the object and the collection respectively. There is also a /view.XXX/ method that will allow you to retrieve a table or view directly, however that mode is and always will be READONLY.
Security
To access any of the API functionality, you must first authenticate. Information is available on the API Settings page on how to obtain the values needed to authenticate and update them if need be.
Authentication can come in one of 2 forms:
REST Authentication
REST is the preferred method of authenticating with your API. To authenticate with REST you would simply navigate to:
http://<site.com>/i4a/api/authenticate/<USER>/<PASSWORD>/<TOKEN>
You will get back a json packet which will contain your authKey which you can then use to make calls to the API.
Soap Authentication
This method is deprecated and should no longer be used for new projects.
- Use the SOAP method authenticateAdmin that is available from the SOAP WSDL located at:
http://<site.com>/i4a/utilities/authenticate.cfc?wsdl
The authenticateAdmin takes 3 parameters, they are:
- Username: Must be an administrator username capable of logging onto the site admin.
- Password: the password for the user.
- Token: The Token is specific to each website. It will be made available in your site admin.
Syntax
Calling the API involves building a URL that the API engine can decode. The API engine uses the REST method. REST allows you to utilize GET, POST and DELETE methods. Currently the i4a api only supports GET, which means the API is read-only at this time.
To access the API you can test it in your browser. First you should login to your admin, then direct your page to:
http://site.com/i4a/api/json/membership.contact/24228/<authkey>
Another method could be:
http://site.com/i4a/api/json/membership.contacts/city like Chicago/<authkey>
The REST command is broken up into several parts, they are from left-right
http://site.com/i4a/api/
- this is the base url that every api call will have in common- /json/ This tells the processor what format to return data in. The options here are Json, XML and WDDX. Json is the fastest format and also more common when using AJAX. For more information see API Return Format
- /membership.contact/ - This tells the processor what object or table to access.
- /city like Chicago/ - This allows you to filter your results.
Filtering
Some examples:
- /firstname=don/ - returns records that match firstname=don
- /City Like Chicago/ - returns records where the city field starts with Chicago
- /City CONTAINS CAN/ - finds records where the city field contains the string 'CAN'
- /logincount > 500 / (Need to test this
- /NULL/ - For querying a collection of records, this would allow for NO filter. This is required because simply leaving the filter empty results in 2 // and the 2nd / is removed by apache during the processing.
API Objects
API Examples
- /i4a/api/json/membership.contact/24228/<authkey> - Returns a json packet for contact record ID = 24228
- /i4a/api/xml/membership.contact/24228/<authkey> - returns an xml packet for contact record ID = 24228
- /i4a/api/wddx/membership.contact/24228/<authkey> - Returns a WDDX packet for contct record ID = 24228
The above examples are only relevent when referencing I4a objects. When interacting with views as below, you must always specify the name/value pair.
- /i4a/api/json/view.ams_contactinformation/id=24228/<authkey> - Returns a json packet for contact record ID = 24228
- /i4a/api/json/view.All Contacts/lastname like L/<authkey> - Returns a json packet that would contain all matching records where lastname started with the letter L
- /i4a/api/json/view.All Contacts/lastname Like L:isActive=1/<authkey> - Same as above, but further filters by isActive = 1
- /i4a/api/json/membership.contacts/<authkey> - returns all records from the table related to the ORM object com.om.collections.membership.contacts.
- /i4a/api/json/view.ams_contact/<authkey> - returns the same recordset as the example above, but interacts directly with the table itself.
Implemention Examples
Testing the API
Testing the API and inspecting the data returned is very easily achieved with any modern browser. It is worth noting that by default, only Firefox will display XML (if the header is set to text/xml) in a readable format. It is possible however in both Google Chrome and Safari to view the xml data in a user-friendly format by going into the developer tools for the browsers. For a better experience however it is recommended you install the following add-ons to each browser for a better experience:
Google Chrome
- https://chrome.google.com/extensions/detail/mfnjijpckfecpgchobgcfndicenjldoe - will display json data in a user-friendly format. Note: This is a great extension and displays json in a very good format, but it appears when viewing XML with the plugin below this plugin seems to insert some data at the top of the page. The xml viewer still works fine and rest assured this information is not IN the XML packet, but rather added in after by your browser and this plugin.
- https://chrome.google.com/extensions/detail/gbammbheopgpmaagmckhpjbfgdfkpadb - will display XML and WDDX in a friendly format directly in your browser page.
Firefox
- https://addons.mozilla.org/en-US/firefox/addon/10869 - will display json data in a user-friendly format
Safari
At this time there appears to be no plugins for Safari that can aid in viewing the data formats, it's recommended you use either Chrome or Firefox if you are going to be interacting with the API from the browser.
Links
- http://en.wikipedia.org/wiki/Representational_State_Transfer Wikipedia article on REST
- http://en.wikipedia.org/wiki/SOAP - Wikipedia Article on SOAP protocol