OBM REST API

This REST API is a work in progress. It implements access to some entities of OBM database without using the UI interface.

As februar, 2010, only contacts and companies are accessibles.

:!: WARNING :!:

There's no access control, with this API you have access to all items without usual restrictions.
The user used to access the data is the superadmin.

Prerequisites

Apache module mod_rewriting installed and active. (tests done with apache 2.2)
OBM 2.0.3 or newer.
The files are located in the contrib/rest directory in obm svn module.

Install

Apache rewrite rules (in OBM virtual host)

RewriteEngine On
RewriteLog "/var/log/apache2/rewrite.log"
RewriteCond %{THE_REQUEST} /rest/([^/]*)/search/([^?\ ]*)
RewriteRule ^.*$ /rest/index.php?entity=%1&action=search&%2 [L]
RewriteRule ^/rest/([^/]*)/values/(.*) /rest/index.php?entity=$1&action=values&field=$2 [L]
RewriteRule ^/rest/([^/]*)(/(.*))?$ /rest/index.php?entity=$1&entity_id=$3 [L]

PHP files

Please put the entire rest directory inside the /path/to/obm/php/ tree.
Copy the config.inc.sample to config.inc and modify the config.inc if necessary.

Use it

The URL are :

- for the list

 http://www.domain.tld/obm/rest/<entity> 
 ex. : http://www.mydomain.com/obm/rest/contact

- for the detail

 http://www.domain.tld/obm/rest/<entity>/<entity_id> 
 ex. : http://www.mydomain.com/obm/rest/contact/2

- for a search

 http://www.domain.tld/obm/rest/<entity>/search/<query> 
 ex. : http://www.mydomain.com/obm/rest/contact/search/fname=Roger&town=Paris

- for a multi-parameters search

 http://www.domain.tld/obm/rest/<entity>/search/<query> 
 ex. : http://www.mydomain.com/obm/rest/contact/search/firstname=Roger|Robert&town=Paris

- for a multi-parameters search with only some field required

 http://www.domain.tld/obm/rest/<entity>/search/<query> 
 ex. : http://www.mydomain.com/obm/rest/contact/search/firstname=Roger|Paul&town=Paris&require_fields=contact_firstname|contact_lastname

- for a list of possible values for some contact field (firstnames, lasnames, zipcodes, towns)

 http://www.domain.tld/obm/rest/contact/values/<field>
 ex. : http://www.mydomain.com/obm/rest/contact/values/firstnames

Tech notes

index.php is the main file. It receives the requests, call the functions and send back the correct http header and xml.

config.inc sets some paths and parameters

contact.php and company.php are similar :

  • get_contact_list_ids() queries the database
  • get_contact_list() constructs the xml list of all contacts
  • get_contact_detail_by_id() queries the database and manage a translation between db field and wml field names
  • get_contact_detail() constructs the xml detail listing for one contact
  • get_contact_search() contructs the xml listing of all contacts matching the <query>, using the search function of OBM framework
contrib/obmrest.txt · Last modified: 2010/03/15 10:44 by patrick
Driven by DokuWiki