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) »
  • Import via API v3: how to validate emails during import
Pages: [1]

Author Topic: Import via API v3: how to validate emails during import  (Read 761 times)

fen

  • I post frequently
  • ***
  • Posts: 216
  • Karma: 13
    • CivicActions
  • CiviCRM version: 3.3-4.3
  • CMS version: Drupal 6/7
  • MySQL version: 5.1/5.5
  • PHP version: 5.3/5.4
Import via API v3: how to validate emails during import
October 31, 2011, 10:31:50 am
We've discovered that the civicrm_api('Contact','create'...) and ('Email','create'...) APIs will both gladly accept poorly formatted emails such as 'foo@bar@baz.com' or multiple emails like 'foo@bar.com; baz@bar.com' - that is, $results['is_error'] will be zero and the poorly formed emails will create records in civicrm_email.

Is there a validation hook that can be called for these from the API?

I haven't checked yet, but I would also want to ensure web URLs are valid and even first_names (disallowing, e.g., "Fred & Wilma Flintstone" as a first name).

Of course, I can validate manually before importing the data, but a hook would be handy as we have several sources importing data using different mechanisms.

Thanks!

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Import via API v3: how to validate emails during import
October 31, 2011, 10:47:50 am
Hi,

I personally wouldn't like that the import would stop (or that the contact would be skipped) because there is a syntax error somewhere in the email, but would be good to have an option indeed (either as an error or as warning that the specific field/sub entity has been skipped).

Not quite sure what would be the best syntax for that.

As for the syntax on the first name, you should implement a pre hook (the normal interface would accept Fred & Wilma as first name too).

I've done something along that line to deal with the ALL UPPERCASE first and last name. works both for the UI & the api

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

fen

  • I post frequently
  • ***
  • Posts: 216
  • Karma: 13
    • CivicActions
  • CiviCRM version: 3.3-4.3
  • CMS version: Drupal 6/7
  • MySQL version: 5.1/5.5
  • PHP version: 5.3/5.4
Re: Import via API v3: how to validate emails during import
October 31, 2011, 11:38:07 am
A pre hook can be placed on an Individual - can one be placed on an Email object?  (I don't see that in the doc, but that doesn't mean it can't be done. ;)

I wouldn't want the import to stop on a badly formatted name/email either, but I would like the $results returned by the civicrm_api call to be non-zero with a useful error message.  Can a pre hook affect the API return value?  Are there any example code snippets I could look at for this?

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Import via API v3: how to validate emails during import
October 31, 2011, 03:05:57 pm
 The pre hooks can be used on (almost) every entity.

The pre hook can either silently fix, or throw an exception that will create an error for the api.

Check out the wiki for pre hook examples (don't think there is one for exceptions, but should give you a starting point).

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: Import via API v3: how to validate emails during import
November 02, 2011, 04:20:12 pm
I don't see pre-hooks being called in CRM_Core_BAO_Email::add.

However, I expect Lobo would be happy to add for 4.1
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) »
  • Import via API v3: how to validate emails during import

This forum was archived on 2017-11-26.