API initialization

How to initialize the API and use the return values.


API class instantiation

In it's simplest form, all that's necessary is the single AppSpice class file. The class can be instanced in account and network modes.

$appSpice = new AppSpice([apiKey], $networkMode = false);

In account mode (default), the API will only recognize the account directly associated with the API key provided. Use this mode to define the project and optionally develop a network of participating accounts.

In network mode (optional), the API will only recognize the accounts created while in this mode. Use this mode to distribute the project across defined hierarchies.

API initialization

The API should be initiated on every page load to return the current environment. You can determine the best use method based upon your framework or other page logic.

$appSpice->initialize();

This single method will remotely authenticate users and provide the current environment.

Method Description
initialize()* Minimum required method. This method alone will remotely log in a user and return the current environment back to the calling script.
initAllowNewAccountSignup($typeFilter = null) This option will allow new network accounts to be created at the signin pages. (Otherwise, they're created through the user interface.)

$typeFilter is a null|string|array of network account types to select from at the sign up page.
  • null (default); Only types that are not children of any other type. Useful for identifying the top tiers of your network.
  • string (parent type code); Only the child types of the parent type code provided. Useful for identifying specific branches of your network.
  • array (type code(s)); Only the specific type(s) identified in the array. Useful for identifying one or more of your types.
  • asterisk(*) symbol; All types.

The create new account option will not be offered if a valid type code is not found.

The method arguments are designed to support usage of one user interface for a wide variety of sign up scenarios.

// Tip: Use an incoming URL query to choose the type filter.
// http://site.com/index.php?tf=1234

// The default will be offered if $_GET['tf'] doesn't exist.

$appSpice
  ->initAllowNewAccountSignup($_GET['tf'])
  ->initialize();

// Omit the default if $_GET['tf'] doesn't exist.

$appSpice
  ->initAllowNewAccountSignup($_GET['tf'] ? $_GET['tf'] : 'bad-code')
  ->initialize();
initNewAccountProposedFee($percent) If you allow creation of new accounts at the signup pages, this option will set the initial gainsharing fee to collect from their revenue earned through the system. Enter a whole number (e.g. 5.25) without the percent sign. This fee will have to be accepted by the new account before implementation.
initDeveloperEmailAddress($emailAddress) Error alerts that would not be displayed on a form page (invalid system parameters, etc) will be emailed to this address if provided.
initEnforceUserAgreement() If provided in your account settings, the system will enforce your User Agreement at the signin pages. Users are automatically required to update their acceptance each time you update the agreement.