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) »
  • 'id' field in api v3
Pages: [1]

Author Topic: 'id' field in api v3  (Read 889 times)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
'id' field in api v3
March 26, 2011, 03:16:23 am
Just been struggling with some code using api v3 that was failing because it was passing in 'id' => '' & I'm thinking that per

http://issues.civicrm.org/jira/browse/CRM-7831

we should accept id in verify_mandatory but we should probably also check it's valid? which is something verify_mandatory can't do without more information (entity)

In the case I had the suggested patch would have solved the problem in that I would have gotten and error realised why my code was failing quicker.


UPDATE
Hmm - just hit another one - the code was passing '0' in the id field to delete & getting a graceless error so we need to ensure that id is > 0 (or preferably that it is valid!)
« Last Edit: March 26, 2011, 03:29:42 am by 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

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: 'id' field in api v3
March 26, 2011, 09:47:59 am

for update a good check would be:

1. id is numeric and > 0
2. there is an object with that id. Note that 0 or null will match all objects and hence a delete will be destructive

since there is a a DAO name sent to the verify_mandatory function, doing the above check is possible

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

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: 'id' field in api v3
March 26, 2011, 11:37:42 am
Or we can do that in the civicrm_api function.

Yeap, something that got skipped is the type verification of the params, on the todo for 4.1 ? Can be fairly automated (with ->fields )

Might also be something to share between the api & form (eg. in adding a method  in the DAO ?)

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: 'id' field in api v3
March 26, 2011, 11:53:48 am
Quote
since there is a a DAO name sent to the verify_mandatory function, doing the above check is possible

Most api don't send this through because the field check is often inappropriate. ie. fields that are given defaults in the BAO are mandatory here. I think it will take some time to work through this issue as we'd need to look at whether the right fields are mandatory and which fields are set along the way fairly carefully. It may be that we should remove the DAO check for now & pass DAO in for all functions & check id.

I suspect checking id here would be more useful than the benefit we currently get from the DAO fields check
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]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • 'id' field in api v3

This forum was archived on 2017-11-26.