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 (Moderator: Donald Lobo) »
  • Civicrm api : chaining
Pages: [1]

Author Topic: Civicrm api : chaining  (Read 1237 times)

valfr35

  • I’m new here
  • *
  • Posts: 6
  • Karma: 0
  • CiviCRM version: 4.x
  • CMS version: Drupal
  • MySQL version: 5.1
  • PHP version: 5.3
Civicrm api : chaining
March 28, 2014, 02:58:03 am
Hello everybody,

I'm using civicrm api v3 and i search to use a single "chained" request to create a contact with :

->a new membership : i'm using api.membership.create[...data...] it's OK
->a new contribution : i'm using api.contribution.create[...data...] it's OK

->and a new membershipPayment with api.membershipPayment.create[?]
But i don't know how to link the required params : contribution and membership Id ?

Currently, i create contact, membership, contribution, membershipPayment separately.
I guess it's less efficient...

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Civicrm api : chaining
March 28, 2014, 06:56:23 am
Well api chaining really doesn't give any performance gains. Under the hood doing a chained api request is exactly the same as calling the api multiple times.
The only performance gain is when you are doing it via rest/js and then it really does help to have only one ajax request instead of several.
Try asking your question on the new CiviCRM help site.

orubel

  • I’m new here
  • *
  • Posts: 1
  • Karma: 0
  • CiviCRM version: 1.0
  • CMS version: 1.0
  • MySQL version: 5.0
  • PHP version: 5.0
Re: Civicrm api : chaining
May 13, 2014, 10:19:54 pm
Actually 'api chaining' in the TRUE sense where there is one request and response and the api calls are chained from one to another through their relationship is HIGHLY efficient especially in the fact that you reduce code (both client side and server side), handle checks at the response/request, uri's associated with api object rather than MODEL data through controller, etc etc

It requires proper abstraction of the api layer. Once properly abstracted, the uris can be associated with api objects which then can be related to one another through client side calls by chaining associated api uri's and passing output key identifier to next uri api call in chain
for example person/show=dept_id&dept/show=company_id&company/show=return

this would be called a 'blank chain' as it is GET > GET > GET and has no unsafe method

For more on api chaining see the Grails API Toolkit

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Civicrm api : chaining
May 14, 2014, 02:01:45 am
That's what Coleman was referring too.

It saves a few lines of code when you call the api locally indeed, but no speed gain if you call the api from php. Where it shines is in client server requests.

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

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Civicrm api : chaining
May 14, 2014, 03:16:31 am
It's also worth nothing that if you include create or delete requests in your api chain & they fail any calls in that chain will be rolled back - this can be useful if you use it correctly
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

Jeremy Proffitt

  • I post occasionally
  • **
  • Posts: 63
  • Karma: 2
    • Mobius New Media
  • CiviCRM version: 4.4.x
  • CMS version: Joomla 2.5.x/3.x / D7
  • MySQL version: 5.1.x
  • PHP version: 5.3.10+, 5.4.x
Re: Civicrm api : chaining
May 14, 2014, 05:09:52 am
To actually answer the question, see:
https://github.com/civicrm/civicrm-core/blob/4.4/api/v3/examples/Contact/APIChainedArrayValuesFromSiblingFunction.php

To get membership id, you'd use 'membership_id' => '$value.api.membership.create', and likewise for contribution.
Jeremy Proffitt
Mobius New Media
IRC: JP_EzoD

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Civicrm api : chaining

This forum was archived on 2017-11-26.