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) »
  • Reducing API transaction
Pages: [1]

Author Topic: Reducing API transaction  (Read 758 times)

DerekL

  • I post frequently
  • ***
  • Posts: 132
  • Karma: 1
  • CiviCRM version: 4.5.5
  • CMS version: Drupal 7.34
  • MySQL version: 5.1.54
  • PHP version: 5.2.17
Reducing API transaction
October 17, 2011, 03:52:47 pm
Hi All,

I'm currently using nested API calls (Thanks Eileen!) to pull contact and membership data in the Register Participant page.
It all works, but I'm wondering if there is a more "lightweight" way to pull this data.

For Example, I use membership get to find membership info from a contact_id, then nest another membership get to find the membership's direct member.  My return array is huuuuuge, and 90% of the data is of no use to my current application.

When this happens, I get a few second delay, and this is on my local machine, I'm not very excited to see this perform on a remote box.

Now, I know that it was my choice to use ajax, and that delays are to be expected; but is there no way to pass through a custom query, as with ContactListQuery, but returning more than two fields? 


Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Reducing API transaction
October 17, 2011, 03:55:49 pm
You can reduce the return array of any call (& we recommend it).

Unfortunately the syntax is a little inconsistent - in some cases 'return' => 'id, display_name' works but in others I think you need 'return.id' => 1, 'return.display_name' => 1

It is also possible to define your own api - Tim blogged about it recently so check the blogs.
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

DerekL

  • I post frequently
  • ***
  • Posts: 132
  • Karma: 1
  • CiviCRM version: 4.5.5
  • CMS version: Drupal 7.34
  • MySQL version: 5.1.54
  • PHP version: 5.2.17
Re: Reducing API transaction
October 17, 2011, 04:38:44 pm
Thanks Eileen, I'll dig into this and report back.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Reducing API transaction
October 17, 2011, 10:33:45 pm
Quote from: DerekL on October 17, 2011, 03:52:47 pm

Now, I know that it was my choice to use ajax, and that delays are to be expected; but is there no way to pass through a custom query, as with ContactListQuery, but returning more than two fields? 


If you need the data returned by the api all the time, I'd suggest to fetch it directly in the template.extra.tpl (check out Dave's blog about it) using the smarty {crmAPI}

It saves you a round trip, will be faster than the ajax way. Obviously you should set the return as well in that case.

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

DerekL

  • I post frequently
  • ***
  • Posts: 132
  • Karma: 1
  • CiviCRM version: 4.5.5
  • CMS version: Drupal 7.34
  • MySQL version: 5.1.54
  • PHP version: 5.2.17
Re: Reducing API transaction
October 19, 2011, 02:30:42 pm
Hi Xavier,

I can't seem to find the blog posting you mention. I'd definitely love to check it out if you have a link handy.


xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Reducing API transaction
October 20, 2011, 03:44:41 am
http://civicrm.org/blogs/dave-greenberg/now-its-easier-add-custom-behaviors-templates
-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) »
  • Reducing API transaction

This forum was archived on 2017-11-26.