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) »
  • Need an overview of functions available in API
Pages: [1]

Author Topic: Need an overview of functions available in API  (Read 1351 times)

Erik Stainsby

  • I’m new here
  • *
  • Posts: 28
  • Karma: 1
  • Web+Db Programmer
  • CiviCRM version: 4.4.3 WP plugin
  • CMS version: WP 3.7.1
  • MySQL version: 5.5.34
  • PHP version: 5.3.10-1ubuntu3.8
Need an overview of functions available in API
January 29, 2013, 07:51:16 pm
I am developing a WP site with CiviCRM plugin, and have discovered only a couple of examples of how to invoke civicrm in a WP context.

One sample was copied and modified from the demo WP site:

[civicrm component="event" id="3" mode="test" action="info"]

Unfortunately beyond recognizing the id is the event's id and that the effect is to dump the ciciv-formatted event into the WP post body, I have no reference for what the syntax & options are for such a command(?)/macro(?).

The other example I have is the WP Integration page, which touts plugin or template placement for PHP code to interoperate with CiviCRM.  Fine, I write WP plugins.  Where do I find documention of the features exposed ?

Our site is a membership hub for librarians, conference and training registration and mentorship programs. Some for-fee services, some open information resources online. Where can I start learning the basics of interacting with the finance system, events, adn registration -type features?

Any feedback gratefully appreciated.
~ Erik

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: Need an overview of functions available in API
January 29, 2013, 11:54:37 pm
Hi Erik,

check this chapter for the API documentation: http://book.civicrm.org/developer/current/techniques/api/

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: Need an overview of functions available in API
January 30, 2013, 05:10:04 am
Hi Erik's (nice names btw)

I agree with Erik1 that there must be a stack of really nifty function buried in civicrm that it would be great to access... the V3 api is really a database crud api pretty much right - but there is much more to life... than crud - there's all thoughs bits underneath and inbetween and on top...

would be great to have some doco on them

andrewhunt

  • I post occasionally
  • **
  • Posts: 80
  • Karma: 13
    • AGH Strategies
  • CiviCRM version: all of 'em
  • CMS version: Drupal, Joomla, and WordPress
Re: Need an overview of functions available in API
January 30, 2013, 05:31:01 am
I know I'm an outsider with a name like Andrew, but here's a tip.  Go to:
http://yoursite.org/wp-admin/admin.php?page=CiviCRM&q=civicrm/ajax/doc&reset=1

It's an interface where you'll be able to experiment with the API and see actual results.  The only warning is that you're running live--so the contributions you create are actually created and the contacts you delete are actually deleted.
You can find me at AGH Strategies.
Need help now?  Civi911 is your go-to for CiviCRM support.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Need an overview of functions available in API
January 30, 2013, 05:33:51 am
Quote from: Erik Stainsby on January 29, 2013, 07:51:16 pm
I am developing a WP site with CiviCRM plugin, and have discovered only a couple of examples of how to invoke civicrm in a WP context.

[civicrm component="event" id="3" mode="test" action="info"]


I'm not familar with these WP magic. the "api way" from the content is to use the smarty filter, use {crmAPI ...} to fetch the data, assign it to a var and format it the way you want.

This is more high level and seems to generate directly the html. Might be in interesting to detail and extend so that's accessible to smarty too (eg. for sending an event invitation by email without having to copy paste the details).

The API per se is CRUD and doesn't deal with presentation, just manipulating data.

@andrew, use civicrm/api/explorer it's the one we find easier to remember ;) and on 4.3 it will be more integrated with civi (eg. with the navigation menu)
-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: Need an overview of functions available in API
January 30, 2013, 08:44:00 pm
I guess what I'm trying to say is that these other function could also be considerred and API and would make making with Civicrm even more pleasurable if there was some kind of documentation available on all the great and robust functions buried in the machinery

come you know the ones I mean... the ones the core developers sneak into their own homegrown modules...

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: Need an overview of functions available in API
January 30, 2013, 11:28:15 pm
Hi Erich,

I would like to invite you to the next sprint where we will happily explain to you how to update the developer manual on the API?  ;D
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: Need an overview of functions available in API
January 31, 2013, 12:55:28 am
Oh Erik...

two problems...

1 - am very far away

2 - i am extraordinarily ignorant

is it worth starting a wiki page, (or is there one there buried somewhere?) entitled "Really useful Civicrm functions you can use and love"... obviously the page would want to link to the V3 Crud Api

is there a version of civcrm run throught php doc somewhere?

half the battle is just knowing that these functions exist - and that it is ok to use them

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: Need an overview of functions available in API
January 31, 2013, 04:55:37 am
Hi Erich,

I am very far away too and even more ignorant :-)

All really useful functions will be in api/v3/utils.php. Personally I would not want a wiki page because I have trouble enough keeping the book up to date :P

Seriously, having a wiki page does help if we are sure we as a community keep it up to date and make it part of every change we make. Personally I tend to just fix things and forget about testscripts and documentation. Documentation that is out of date or incorrect does not help, it adds to the confusion. What we are aiming at is a book that is up to date and reflects the recommended practises. If we as a community can make sure at every sprint that it is maintained we do a good job. Besides that I am happy to have a wiki as a scratchboard, would advise against a second source of semi-official documentation.
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Need an overview of functions available in API
January 31, 2013, 05:25:27 am
Quote from: Erich Schulz on January 30, 2013, 08:44:00 pm
I guess what I'm trying to say is that these other function could also be considerred and API and would make making with Civicrm even more pleasurable if there was some kind of documentation available on all the great and robust functions buried in the machinery

Do you have some examples of these hidden gems? The one from Erik (the Stainsby not the Hommel, way too many Eric|k|ch in this community ;) is nice, but isn't really something that belong to the api. Not sure I completely understand what's missing.
-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: Need an overview of functions available in API
February 04, 2013, 07:16:41 pm
hey Xavier

sorry for name confusion - we are a bit thick around here :-)

ok 5 examples extracted randomly from code i've stumbled on:

  • CRM_Utils_Mail::send($email)
  • CRM_Contact_BAO_Contact_Utils::generateChecksum($contact['contact_id'], time(), 24);
  • CRM_Utils_System::url('civicrm/profile/edit', $query, true, null, false);


* CRM_Core_OptionGroup::values('event_type');

* civicrm_initialize(TRUE);



Should these be part of the "V3 API" - well maybe not - but they are still handy well tested utilities that shouldn't be reinvented no?

It could be as simple as an index page into the phpdoc html output - whereever that is?? does anyone have it online

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Need an overview of functions available in API
February 05, 2013, 04:02:21 am
Just to clarify, the examples you give aren't what we put under the api name, now it's getting clearer what you mean, thanks.

Quote from: Erich Schulz on February 04, 2013, 07:16:41 pm

ok 5 examples extracted randomly from code i've stumbled on:

  • CRM_Utils_Mail::send($email)

Being able to send an email via the api would be super handy indeed.
Until recently, we focused on the CRUD, but as now you can create a mailing, add target and trigger the sending job, not sure anymore what's the reason not to add it. Want to try a new thread about creating a real send email api?
eg something like.
civicrm_api ("activity","create", array (type+contact_id+body+..., "option.sendmail"=>true)
Quote

  • CRM_Contact_BAO_Contact_Utils::generateChecksum($contact['contact_id'], time(), 24);


civicrm_api ("contact","generatechecksum",...) ?
Security implication? might be good to start another thread about it too

Quote

  • CRM_Utils_System::url('civicrm/profile/edit', $query, true, null, false);


You mean generating an url in the right format? we have it now on the javascript side too. Not sure I see the use case for this one.

Quote
* CRM_Core_OptionGroup::values('event_type');

exists already:

$results=civicrm_api("OptionValue","get", array (version => '3','sequential' =>'1', 'option_group_id' =>'1'));


Quote
* civicrm_initialize(TRUE);

Should these be part of the "V3 API" - well maybe not - but they are still handy well tested utilities that shouldn't be reinvented no?

It could be as simple as an index page into the phpdoc html output - whereever that is?? does anyone have it online

They are plenty of classes with useful methods and functions & they probably aren't documented enough indeed. However, I'd make a strong distinction between these and the "official API"

1) the core classes can change between version (and will). The api strives to keep compatible
2) the core methods might require to be called in a specific order. the api should be atomic and each call should stand on its own
3) the core is only callable from php, the api should work the same from php, rest, ajax, smarty or command line (drush)

http://doc.civicrm.org/v3/ contains a phpdoc for the api only, I'm not sure there is something similar for the rest of civicrm code.

Anyway, what you are describing are nice civi functions that I use, but I know that this part of my custom code is more likely to fail in an upgrade and that theses function can be changed between versions. In my experience, it's safer to use the api, and probably worthwhile trying to add more high level apis if needed (patch welcome and all that).

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

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Need an overview of functions available in API

This forum was archived on 2017-11-26.