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) »
  • The API stands and falls together
Pages: [1] 2

Author Topic: The API stands and falls together  (Read 2965 times)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
The API stands and falls together
April 16, 2012, 04:02:08 pm
One 4.2 change coming out of the sprint is that we added transactions & rollback to the API. This means that if a chained API call fails on a sub call then the entire transaction will be rolled back & an error message will show at the top level.

Also, I trialled a syntax for doing post-failure checking on api calls that fail due to a unique constraint - at the moment it requires the constraint to be added to the _spec function. I don't think querying the indexes is realistic but this definition could be pushed down to the XML - this is in place on Option Group api

- I trialled a fix for handling is_primary for phone (hoping someone will QA it before I try to push it to other location types)

- fixes for getfields & custom - wasn't coping with case correctly ie. entity = Contribution worked but not contribution.

- fix for export csv via cli - no field was being returned when empty - causing the rows not to line up in csv (thanks to Joe for logging bug which led to this & Noah Miller for picking it out of the queue & working with us to get it fixed - Noah was also the first to suggest the right fix but we had to figure out why & what it would impact before we agreed with him :-))
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

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: The API stands and falls together
April 16, 2012, 09:21:15 pm
Nice work Eileen.
See Joe, people do read your bug reports   ;D
Try asking your question on the new CiviCRM help site.

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: The API stands and falls together
April 16, 2012, 11:01:49 pm
Good stuff Eileen, have a coffee! And I will have a look at the phone is_primary fix if you like, where did you put it?
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: The API stands and falls together
April 16, 2012, 11:25:43 pm
Nice milky coffee mmmmm

Phone primary handling is on the BAO

http://svn.civicrm.org/civicrm/trunk/CRM/Core/BAO/Email.php

There was no Create function in this case so I added the one that is there & the primaryHandling function (& api calls the create now- it was previously calling 'add')

Eileen
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

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: The API stands and falls together
April 16, 2012, 11:27:55 pm
Am I missing something? The new phone handling is on the BAO, but you give me a link to Email.php? Too much milky coffee?
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: The API stands and falls together
April 16, 2012, 11:33:31 pm
Lots of good news & progress, well done.

As for the csv, would it be easy to add an options.return_empty=1 so for a php/rest it returns the field empty instead of nothing?

Would avoid to have lots of if value.first_name then ...

For the post failure, the sql error isn't good enough?

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: The API stands and falls together
April 16, 2012, 11:41:45 pm
Existing error doesn't tell you what field it failed on (or even really the nature of the failure).

We found that the API based get functions were using an API based store-as-array function but the Query object based ones were using one on the query object - that second one was dropping empty fields so we talked it into returning them
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

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: The API stands and falls together
April 17, 2012, 12:05:21 am
Quote from: Eileen on April 16, 2012, 11:41:45 pm
Existing error doesn't tell you what field it failed on (or even really the nature of the failure).


Ah, that one might be because we don't have a specific catch block for PEAR (or DB) exceptions. Pretty sure we can get a complete sql error (that would still need to be parsed, but I'm assuming there is already code somewhere that does it or that it isn't rocket science anyway

Quote

We found that the API based get functions were using an API based store-as-array function but the Query object based ones were using one on the query object - that second one was dropping empty fields so we talked it into returning them

You haven't enabled it by default? Plenty of my code is using the fact that no fields means an empty field (beside avoiding to bloat the ajax requests with non useful fields)
-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: The API stands and falls together
April 17, 2012, 02:53:55 pm
At the moment it's inconsistent across API - some will return an empty field & others will return no field. If you want empty fields stripped for ajax maybe that makes sense at the REST wrapper level?

One symptom of stripping is that you export cli wasn't lining up the fields correctly in some cases.
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

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: The API stands and falls together
April 22, 2012, 08:46:34 pm
So, the other thing I'm looking at is the checking of pseudoconstants which is inconsistent & crufty across the API.

I'm did a first attempt & it kind of looks OK & almost as a side effect supports either the id or the value for pseudoconstants (which is inconsistantly supported across the API).

What I'm thinking is that maybe I could resolve the pseudoconstants in the getfields request (which would make the available options visible) & then check against them. This potentially could cause some extra queries to resolve them but I think most of the pseudoconstants are resolved @ the BAO level anyway & there would only be additional overhead on the first api call since both pseudoconstants & the getfields response are cached.

On the other hand, being able to see in the api explorer an array of options accepted by the membership_type_id field (for example) would be kinda nice & would be useful for when we finally get the import to use the API (because the import does heavy checking).

Note that incorrect pseudoconstants are not handled @ the DB level - e.g an invalid gender_id will be written to the DB.
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

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: The API stands and falls together
April 22, 2012, 11:22:25 pm
Hmmm that definitely needs cleaning. Not sure I understand your solution, what do you want to do at the getfields level?

I would imagine a wrapper function to deal with pseudo constants in a consistent way, including validation?
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: The API stands and falls together
April 23, 2012, 12:10:45 am
Hi,

Not sure I like the "pseudoconstant" name. Here what matters is that we do a lookup from the name to the id, not that this id,name couple is stored as a pseudoconstant.

Ie. we can imagine we do the same in a future version with a api.contact.create ('eemail'=>xx,tag=array('name of tag A','name of tag B'),

Not sure the tag is a super example, but pretty sure we'll extend it to other things than the pseudo constants.

alias (already used for "real aliases")? alternate? lookup?

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: The API stands and falls together
April 24, 2012, 03:43:05 pm
OK - so this is what I was talking about

http://svn.civicrm.org/civicrm/trunk/api/v3/examples/ActivityGetFields.php

If you check the priority id it has interpreted the pseudoconstant & added the 'options' array (in the getfields function). The _civicrm_api3_validate_integer checks against the options array & does a swap out if relevant & throws an exception if it's a pseudoconstant, but not a valid key or string.

Code: [Select]
     
      'priority_id' => array(
          'name' => 'priority_id',
          'type' => 1,
          'pseudoconstant' => 'priority',
          'options' => array(
              '1' => 'Urgent',
              '2' => 'Normal',
              '3' => 'Low',
            ),
        ),
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

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: The API stands and falls together
April 25, 2012, 12:04:02 am
I think we are talking about the same thing. My point was that "pseudoconstant" highlights how that's implemented, and that I think the important part is that these two fields are "aliases" to each other.

Quote
      'priority_id' => array(
          'name' => 'priority_id',
          'type' => 1,
          'pseudoconstant' => 'priority',
          'options' => array(
              '1' => 'Urgent',
              '2' => 'Normal',
              '3' => 'Low',
            ),
        ),


Ah that's why we didn't understand each other, I thought it was a new field:


Quote
'priority_id' => array(
          'alternate' => 'priority', // still locking for a name for "alternate"
          'name' => 'priority_id',
          'type' => 1,
        ),
'priority' => array(
         'canonical' => 'priority_id', // and/or for "canonical"
         'name' => 'priority'
         'options' => array(
              '1' => 'Urgent',
              '2' => 'Normal',
              '3' => 'Low',
            ),


If you can use priority as a normal field, should be defined like a normal field in the getfields IMO
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: The API stands and falls together
April 25, 2012, 12:29:53 am
Actually - I think priority would just be an alias for priority_id - in that the way I've done it at the moment priority_id accepts '1' OR 'Urgent'. So, if priority was in the submission we'd just treat it as an alias of priority_id.

We probably wouldn't advertise priority but we'd support it because it's simpler to do so than not do so as we are committed to supporting 'membership_type' & a bunch of others.
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

Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • The API stands and falls together

This forum was archived on 2017-11-26.