I4A API Guide: Difference between revisions

From i4a API Wiki
Jump to navigation Jump to search
Line 34: Line 34:
To access the API you can test it in your browser. First you should login to your admin, then direct your page to:
To access the API you can test it in your browser. First you should login to your admin, then direct your page to:


<pre>https://yoursite.com/i4a/api/json/membership.contact/24228/<authkey></pre>
<pre>https://yourwebsite.com/i4a/api/json/membership.contact/24228/<authkey></pre>


Another method could be:
Another method could be:


<pre>https://yoursite.com/i4a/api/json/membership.contacts/city like Chicago/<authkey></pre>
<pre>https://yourwebsite.com/i4a/api/json/membership.contacts/city like Chicago/<authkey></pre>


The REST command is broken up into several parts, they are from left-right:
The REST command is broken up into several parts, they are from left-right:


* <code>https://yoursite.com/i4a/api/</code> - this is the base URL that every API call will have in common.
* <nowiki>https://yourwebsite.com/i4a/api/</nowiki> - 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|API Return Format]]
* /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|API Return Format]]
* /membership.contact/ - this tells the processor what object or table to access.   
* /membership.contact/ - this tells the processor what object or table to access.   

Revision as of 19:20, 21 September 2022

I4A API Guide

About

This guide will outline how to use the Internet4associations REST API.

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.

REST Authentication

REST is the preferred method of authenticating with your API. To authenticate with REST you would simply navigate to:

  • https://<yoursite.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.

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:

https://yourwebsite.com/i4a/api/json/membership.contact/24228/<authkey>

Another method could be:

https://yourwebsite.com/i4a/api/json/membership.contacts/city like Chicago/<authkey>

The REST command is broken up into several parts, they are from left-right:

  • https://yourwebsite.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=john/ - returns records that match firstname=john
  • /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 relevant 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.ams_contactinformation/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.ams_contactinformation/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.

Additional Examples

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

Firefox

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