CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • help starting to write a phone api using the rest ap and drupal 6 backend
Pages: [1]

Author Topic: help starting to write a phone api using the rest ap and drupal 6 backend  (Read 1893 times)

Erich Schulz

  • I post frequently
  • ***
  • Posts: 142
  • Karma: 5
    • When no-one understands what you are going on about its time to start a blog
  • CiviCRM version: 4.4
  • CMS version: Drupal 7
  • MySQL version: 5.somthing
  • PHP version: 5.3.3
help starting to write a phone api using the rest ap and drupal 6 backend
January 30, 2013, 05:21:01 am
hi just starting to explore developing a phone Ap (edited for clarity 31/1/13)

I'm just a php/mysql hacker and having looked a bit at providing rest services it seems tantalising easy and may finally get me singing the v3 api's praises (i am worried about making Xaviers head grow too big, even though the praise is well earned)

I have a mate who does groovy ruby front ends, and others who reckon they can use other frameworks... so i'm wanting just to provide the services... larglely civicrm - but also wanting to expose several non civicrm based services based on the in house information model...

just starting to sketch out the authentication bits (from a level of pretty deep ignorance) it seems like it could work like thus:

- download ap
- enter email address
- if has drupal account -> send api key and populate civicrm_contact
- if no drupal account -> ask user to supply password & email api key (creating record in civicrm_contact if needed)
- user logs in using email/userid and password and api key
- app stores api key (and optionally password)
- future sessions start by prompting for (or retrieving the password), and submitting password allong with stored username and api_key to initiate session...
- then... http://book.civicrm.org/developer/current/techniques/api/ gets a bit confusing...

any tips very welcome!
« Last Edit: January 30, 2013, 08:45:24 pm by Erich Schulz »

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: help starting to write a phone api using the rest api and drupal 6 backend
January 30, 2013, 05:38:31 am
Just to make sure I followed... "phone api" in this case doesn't mean "CRUD API for civicrm_phone data records". Instead, it means "something to help write mobile (phone) applications that connect to the Civi API" (e.g. writing a Ruby-based application with Rhomobile that talks to Civi). The data-based Civi API's seem OK for the task, but the "authentication process" has some missing pieces.

That's the context?

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: help starting to write a phone api using the rest api and drupal 6 backend
January 30, 2013, 07:15:56 am
Quote from: Erich Schulz on January 30, 2013, 05:21:01 am
hi just starting to explore this...

I'm just a php/mysql hacker and having looked a bit at providing rest services it seems tantalising easy and may finally get me singing the v3 api's praises (i am worried about making Xaviers head grow too big, even though the praise is well earned)

Don't you worry, they are enough heads in the API team so you can praise as much as you please before they grow too big ;)

Quote
I have a mate who does groovy ruby front ends, and others who reckon they can use other frameworks... so i'm wanting just to provide the services... larglely civicrm - but also wanting to expose several non civicrm based services based on the in house information model...

just starting to sketch out the authentication bits (from a level of pretty deep ignorance) it seems like it could work like thus:

- download ap
- enter email address
- if has drupal account -> send api key and populate civicrm_contact
- if no drupal account -> ask user to supply password & email api key (creating record in civicrm_contact if needed)
- user logs in using email/userid and password and api key
- app stores api key (and optionally password)
- future sessions start by prompting for (or retrieving the password), and submitting password allong with stored username and api_key to initiate session...
- then... http://book.civicrm.org/developer/current/techniques/api/ gets a bit confusing...

any tips very welcome!

Cool, Would be good to have a basic library in ruby that wraps civicrm api.
That's one in javascript for node.js for example
https://npmjs.org/package/civicrm


So right now, the rest interface design principles is that you have at most a handful of rest users (one per service that connects) and that you set up manually the api_key.

While discussing yesterday about ldap integration, was clear that something more advanced was needed, so the consumer would have a per civicrm user acl instead of the same one for everyone. Not super clear how, one suggestion was to have a drush command to make it easier to create the keys.

Might be better to switch to oAuth before we go too crazy on advanced implementations of authentications (I'm not smart enough to design a good one, but just smart enough to know it's better to use one that is battle tested for a long while ;)

Anyway, the api doesn't cover creating accounts and has limited features around authentication (as they both are more the area for the CMS civi integrates with).
X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Erich Schulz

  • I post frequently
  • ***
  • Posts: 142
  • Karma: 5
    • When no-one understands what you are going on about its time to start a blog
  • CiviCRM version: 4.4
  • CMS version: Drupal 7
  • MySQL version: 5.somthing
  • PHP version: 5.3.3
Re: help starting to write a phone api using the rest ap and drupal 6 backend
January 30, 2013, 07:09:32 pm
Hey thanks for that

sorry i put an "i" on "ap" just to confuse everybody

so yes to make a general purpose phone ap

need to have a log in per user - roughly 2% of our install's contacts already have drupal users, and I'd like leverage all the goodies that hang off that

I guess I can log in the user via their drupal permission, then access the civicrm v3 api around my own little wrapper ???

there are some complications for my environment which make me think that maybe best.. but i'd love to hear otherwise!!

does the api invoke the permission hooks? I already have a layer that does ACL filtering (legacy code that doesn't use the civicrm hook sadly)

its a pain that i'm on drupal 6 (and currently civicrm 3.4 - but if this is going to happen this maybe what i'm stuck with)
« Last Edit: January 30, 2013, 08:58:54 pm by Erich Schulz »

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: help starting to write a phone api using the rest ap and drupal 6 backend
January 30, 2013, 07:38:43 pm

I would strongly recommend not pursuing this with Civi 3.4.x (which is a few years old and obsolete)

Upgrade to 4.2.7. you can backport stuff done in 4.3. but i suspect it will increase the chance of u succeeding by 100x :)

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Erich Schulz

  • I post frequently
  • ***
  • Posts: 142
  • Karma: 5
    • When no-one understands what you are going on about its time to start a blog
  • CiviCRM version: 4.4
  • CMS version: Drupal 7
  • MySQL version: 5.somthing
  • PHP version: 5.3.3
Re: help starting to write a phone api using the rest ap and drupal 6 backend
January 30, 2013, 08:41:13 pm
thanks Lobo

that's a real fly in the ointment - unfortunately civicrm upgrades on my server are out of my control... and if this is going to fly I may have to a way to progress using what I have... but I understand I have a backport

if you can forgive the fact i'm not working on the current version it would be nice do this way so the rest service i develop is a similiar as possible in approach to what you are working on...

this means that even i end up writing a few hundred lines of disposable code its possible that some may be recyclable...

the other prosepect is using the drupal services module...

so is the reason http://book.civicrm.org/developer/current/techniques/api/ is silent on rest authentication that its a work in progress?

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: help starting to write a phone api using the rest ap and drupal 6 backend
January 30, 2013, 11:35:50 pm
Hi Erich,

updating the authentication in the developer guide is on my to do list, and I hope to start it next week. It is not work in progress because no one is working on getting it over to oAuth. On the other hand it is work in progress as Xavier and I have discussed OAuth as the best option (not reinventing etc...) a couple of times. I am about to embark on using OAuth on a project, and that will give me some experience. Hopefully that will give me an idea of what is required. Do you have any experience with OAuth?

P.S. Xavier's head is really small.................... ::)
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Erich Schulz

  • I post frequently
  • ***
  • Posts: 142
  • Karma: 5
    • When no-one understands what you are going on about its time to start a blog
  • CiviCRM version: 4.4
  • CMS version: Drupal 7
  • MySQL version: 5.somthing
  • PHP version: 5.3.3
Re: help starting to write a phone api using the rest ap and drupal 6 backend
February 24, 2013, 04:31:40 pm
just an update where I'm at...

I'm probably a bit unusual being stuck doing drupal 6 development this late in its lifecycle

but best approach in my circumstance seems to be the drupal services module and simple "session" authentication

noting that many of the "entities" in my organisational information model don't exist in civicrm - especially the ones i'm wanting to expose

for the curious, i've been trying to put all the pieces together in a diagram (clearly i'm a visual thinker)

https://docs.google.com/drawings/d/1XsTEr_aU4nquEyRQMBdcQvm4RcI4cqHhKl9YxqARtcE/edit?usp=sharing

let me know if you want edit rights

google docs are pretty good for knocking together this sytle of diagram - would be great to see some laying out the civi-architecture
« Last Edit: February 24, 2013, 04:35:42 pm by Erich Schulz »

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: help starting to write a phone api using the rest ap and drupal 6 backend
February 26, 2013, 03:22:40 am
Hi,

Why don't you leverage the api extension capabilities?
if you create (in your extension probably the best place) a api/v3/YourCustomEntity.php you can directly implement civicrm_api3_you_custom_entity_create|get|delete ($params)

and you can then directly use this api like any of the other core api.

there is a hook alterAPIPremission to let you define who can call these api from rest or ajax.

http://wiki.civicrm.org/confluence/display/CRMDOC42/hook_civicrm_alterAPIPermissions






-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

torenware

  • I post frequently
  • ***
  • Posts: 153
  • Karma: 4
Re: help starting to write a phone api using the rest ap and drupal 6 backend
February 27, 2013, 03:46:04 pm
Eric --

While I feel your pain over being stuck with an old version (I just upgraded Democrats Abroad from CiviCRM 1.9 to 4.1.5, and hope to get them in 4.3 in couple of months.  Hard technologically, harder for the organization from a budgetary perspective), yeah, life is just easier on a newer version.  And the API stuff, thanks to the efforts Xavier, Elaine and the rest of the gang, is vastly better in recent 4.x versions that it was the in 3.x branch.

That said, I'm pretty sure you can do _some_ of what you do, even in a version that old, using the SOAP support in CiviCRM.  Or, as I'm going to suggest below, you use Drupal Services to implement a REST server.

Since you're using Drupal 6, the Drupal Services module is a good way to do these things.  I just did a deployment (for a non-CiviCRM based Drupal 7 application) of an application that integrates the Twilio SMS API with Drupal's powerful Rules module.  While you're better off doing this kind of stuff in Drupal 7 -- Services 7.x-3.x is a lot better than Services 6.x-2.x -- you can do apps like this in your current environment.  I'm pretty sure that CiviCRM 3.4 has  reasonable CiviCRM API v3 support, although Xavier et al will have a better idea of the limitations than I do.

Writing a Services resource that calls into the CiviCRM API is not too bad to do, and is a good way of implementing a REST server.
« Last Edit: February 27, 2013, 03:49:31 pm by torenware »

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: help starting to write a phone api using the rest ap and drupal 6 backend
February 28, 2013, 12:50:09 am
Hi,

3.4 has already most of the api like the 4.0, so you could still do the api using native civi.

4.2 works on D6, might be easier for you to upgrade to that first. That's anyway easier to do regular small upgrades between version than waiting for a blue moon to do it.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Erich Schulz

  • I post frequently
  • ***
  • Posts: 142
  • Karma: 5
    • When no-one understands what you are going on about its time to start a blog
  • CiviCRM version: 4.4
  • CMS version: Drupal 7
  • MySQL version: 5.somthing
  • PHP version: 5.3.3
Re: help starting to write a phone api using the rest ap and drupal 6 backend
March 23, 2013, 06:08:42 am
thanks all... have poked a few people a civi guru is now upgrading us to 4.2... am waiting for dust to settle - thanks for the services module reassurance

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • help starting to write a phone api using the rest ap and drupal 6 backend

This forum was archived on 2017-11-26.