Changes between Initial Version and Version 1 of control-panel/alternative-interfaces


Ignore:
Timestamp:
Feb 7, 2012, 7:03:10 AM (12 years ago)
Author:
Jamie McClelland
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • control-panel/alternative-interfaces

    v1 v1  
     1= Alternatives to using a web browser to access your Control Panel =
     2
     3The May First/People Link [https://members.mayfirst.org/cp Members Control panel] is typically accesed via the web using a web browser.
     4
     5In addition, there are two alternative ways to access and modify data in the control panel: via an Application Programmers Interface (API) that is accessible via http POST calls that any member can make from a remote computer and via a command line program (only accessible to administrators via a shell on hay.mayfirst.org).
     6
     7Both methods follow a common syntax. See below for details about using each method.
     8
     9== Common Syntax ==
     10
     11Each call is an array of key/value paramters. Every call must include an action and an object.
     12
     13Available actions are: insert, update, delete, and select
     14
     15Available objects are: member, contact, unique_unix_group, hosting_order, item
     16
     17The remaing values are the values you wish to set on the given object (e.g. member_friendly_name = 'May First/People Link', or list_name = 'outreach-group').
     18
     19There are three ways to set these values:
     20
     21 * set: set the given field to the given value
     22 * where: operate on a object matching the given field value
     23 * sub: lookup a foreign key and match on that value
     24
     25For example, if you want to display all user account records in which the user_account_login field is set to 'jamie', you would pass:
     26
     27 * action=select
     28 * object=item
     29 * where:service_id=1
     30 * where:user_account_login=jamie
     31
     32User accounts (and all things represented as tabs in a hosting order) are considered to be objects of the type "item". When acting on items, the service_id is required. That integer represents the kind of item (service_id 1 represents a user account). If you want to see the service_id number of other items, it is embedded in the URL of the web interface when you click on a tab. Email addresses are 2, DNS records are 9, etc.
     33
     34Finding the membership record for May First/People Link:
     35
     36 * action=select
     37 * object=member
     38 * where:member_friendly_name="May First/People Link"
     39
     40If you want to insert a new record, you can use the insert action. To create a new user account in the May First/People Link hosting order (which is hosting_order_id 1):
     41
     42 * action=insert
     43 * object=item
     44 * set:service_id=1
     45 * set:hosting_order_id=1
     46 * set:user_account_login=jamie
     47 * set:user_account_password="secretPass0rd"
     48
     49If you weren't sure what hosting_order_id to use (perhaps you are writing a script that first creates the hosting order so you don't know before hand what ID it will get), you can use the sub option:
     50
     51 * action=insert
     52 * object=item
     53 * set:service_id=1
     54 * sub:hosting_order_identifier=mayfirst.org
     55 * set:user_account_login=jamie
     56 * set:user_account_password="secretPass0rd"
     57
     58The sub option will lookup a hosting order with an identifier set to mayfirst.org and, if found, add a hosting_order_id parameter set to the hosting_order_id of the matching record.
     59
     60Similarly, if you are adding a contact, you can do the same trick with the Member Friendly Name. The following two examples will have the same result, since May First/People Link's member_id is 1.
     61
     62 * action=insert
     63 * object=contact
     64 * sub:member_friendly_name="May First/People Link"
     65 * set:contact_first_name=jamie
     66 * set:contact_last_name=jamie
     67 * set:contact_email={{{jamie@example.com}}}
     68 * set:contact_billing=y
     69
     70 * action=insert
     71 * object=contact
     72 * set:member_id=1
     73 * set:contact_first_name=jamie
     74 * set:contact_last_name=jamie
     75 * set:contact_email={{{jamie@example.com}}}
     76 * set:contact_billing=y
     77
     78== Using the web accessible API ==
     79
     80To use the web accessible API you must pass two additional parameters:
     81an api user name and password.
     82
     83We strongly encourage you to create a user account specifically for your applications and only give this user the privileges it needs to create the items you need created (usually, for creating items, you just need to add it to the "Hosting Order Access" tab in your control panel). 
     84
     85You can write programs in any language you want. These examples happen to be written in PHP.
     86
     87This example creates a user account with a corresponding email address.
     88
     89{{{
     90$api_user = 'your-api-user';
     91$api_password = 'secretPass0rd';
     92$hosting_order_id = 432;
     93$url = 'https://members.mayfirst.org/cp';
     94
     95$user_name = 'julio';
     96$user_pass = 'secret';
     97$email_address = 'julio@example.com';
     98
     99function red_fetch($url, $data) {
     100  $ch = curl_init();
     101  curl_setopt($ch, CURLOPT_URL, $url);
     102  curl_setopt($ch, CURLOPT_POST, 1);
     103  curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
     104  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     105  return json_decode(curl_exec($ch));
     106}
     107
     108$data = array(
     109  'action' => 'insert',
     110  'object' => 'item',
     111  'set:service_id' => 1,
     112  'set:hosting_order_id' => $hosting_order_id,
     113  'set:user_account_login' => $user_name,
     114  'set:user_account_password' => $user_pass,
     115);
     116
     117$ret = red_fetch($url, $data);
     118
     119if($ret['is_error'] == 1) {
     120  // handle errors
     121}
     122
     123$data = array(
     124  'action' => 'insert',
     125  'object' => 'item',
     126  'set:service_id' => 2,
     127  'set:hosting_order_id' => $hosting_order_id,
     128  'set:email_address' => $email_address,
     129  'set:email_recipient' => $user_name,
     130);
     131
     132$ret = red_fetch($url, $data);
     133
     134if($ret['is_error'] == 1) {
     135  // handle errors
     136}
     137}}}
     138
     139== Using the command line (red-cli) ==
     140
     141The command line program is only accessible to administrators and can only be run from the command line on hay.mayfirst.org.
     142
     143The cli program is in: /usr/local/share/red/ui/sbin/red-cli
     144
     145No username or password is needed to run red-cli.
     146
     147Options are passed via double-dash prefixed argument, e.g.:
     148
     149{{{
     150red-cli --action select --object hosting_order --where:hosting_order_identifier mayfirst.org
     151}}}
     152
     153Optionally, you can use the following syntax:
     154
     155{{{
     156red-cli --action=select --object=hosting_order --where:hosting_order_identifier=mayfirst.org
     157}}}
     158
     159