© 2015 X2Engine Inc.

Web API Reference (Legacy)

From X2Engine
Revision as of 16:59, 30 April 2013 by Demitri (talk | contribs)
Jump to: navigation, search


X2CRM features a remote API for inserting, updating, querying and deleting records. The API is accessed via POST requests to the API controller (see: ApiController) and thus, URLs (after the domain name and relative path to the document root) for calls to the API will begin with index.php/api/.

Usage

The post data variables should be named according to the column names of the model for which the API being called. When making API calls, the same validation rules as in normal use of the app also apply. In the case that the input does not pass validation, the API will respond with the validation errors.

Authenticating

Using the API requires authentication credentials for the web application in the form of two post data fields: user and userKey, containing the username and API key of that user (versions 2.9.1 and later), or authUser and authPassword, containing the username and password hash (versions earlier than 2.9.1), respectively. A user's API key can be set by the administrator in the User module by visiting the update page for the given user.

Available API functions

(See also the documentation on ApiController)

The methods of ApiController used for creating, querying, viewing (by ID), updating and deleting records are:

Method Base URL ID required Usage
actionCreate() index.php/api/create no Creates a new record
actionLookup() index.php/api/lookup no Searches for a record based on one or more fields
actionView() index.php/api/view yes Views a record
actionUpdate() index.php/api/update yes Updates a record
actionDelete() index.php/api/delete yes Deletes a record
actionVoip() index.php/api/voip no Notifies the assignee of a contact having called (if the phone number matches).
Requires only the "phone" field, as a GET parameter, it being a 10+ digit phone number.

Specifying Model

The API requires specifying the model for which the transaction will be performed as a GET parameter with key "model", with actionVoip being the only current exception. Per the URL format rule of X2CRM, which is "path" (see CUrlManager for more information), the full URL of the request will be: index.php/api/[method]/model/[model name]. So, for example, an API call to create a new contact record should use index.php/api/create/model/Contacts

Usage Example

The file leadCapture.php in the web root of the codebase contains a few noteworthy examples of API calls. Of particular significance is the necessity of creating a contact first and then using lookup to obtain its numeric ID in order to create an action associated with that contact.

(section in progress)