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) »
  • custom data in API v2
Pages: [1]

Author Topic: custom data in API v2  (Read 4300 times)

dalin

  • I post occasionally
  • **
  • Posts: 89
  • Karma: 8
  • CiviCRM version: many
  • CMS version: Drupal 6
  • MySQL version: 5.0
  • PHP version: 5.2
custom data in API v2
April 03, 2008, 03:02:27 am
I can't seem to find any documentation or examples (in the wiki or the simpletests) of how to get custom data for contacts.  Does this functionality still exist?  If so I can add it to the wiki.
--
Dave Hansen-Lange
Web Developer
Advomatic LLC
http://advomatic.com
Hong Kong office

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: custom data in API v2
April 03, 2008, 11:14:00 am
Dave - we're working on adding some example(s) for this to SVN. Will post back here when they're up there - and then will take u up on your offer to add to the wiki doc :-)
Protect your investment in CiviCRM by  becoming a Member!

dalin

  • I post occasionally
  • **
  • Posts: 89
  • Karma: 8
  • CiviCRM version: many
  • CMS version: Drupal 6
  • MySQL version: 5.0
  • PHP version: 5.2
Re: custom data in API v2
April 03, 2008, 07:01:29 pm
I don't necessarily need examples.  Just point me in the right direction and I'll figure it out.  Here's my guess though which I'll try this morning:

$params = array(
  'country' => 'US',
  'state_province' => 'CA',
  'return.display_name' => 1
  'return.custom_mycustomfield' => 1,
);
$result = civicrm_contact_search( $params );
--
Dave Hansen-Lange
Web Developer
Advomatic LLC
http://advomatic.com
Hong Kong office

dalin

  • I post occasionally
  • **
  • Posts: 89
  • Karma: 8
  • CiviCRM version: many
  • CMS version: Drupal 6
  • MySQL version: 5.0
  • PHP version: 5.2
Re: custom data in API v2
April 03, 2008, 07:47:33 pm
Nope I tried several variations on that theme with no luck. 
--
Dave Hansen-Lange
Web Developer
Advomatic LLC
http://advomatic.com
Hong Kong office

dalin

  • I post occasionally
  • **
  • Posts: 89
  • Karma: 8
  • CiviCRM version: many
  • CMS version: Drupal 6
  • MySQL version: 5.0
  • PHP version: 5.2
Re: custom data in API v2
April 04, 2008, 01:04:01 am
Got it:

    require_once('api/v2/Contact.php');
    $params = array(
      'contact_id' => $cid,
      'return.first_name' => 1,
      'return.last_name' => 1,
      'return.state_province' => 1,
      'return.custom_2' => 1,
    );
    $contact = civicrm_contact_search($params);
--
Dave Hansen-Lange
Web Developer
Advomatic LLC
http://advomatic.com
Hong Kong office

Manish Zope

  • I’m new here
  • *
  • Posts: 18
  • Karma: 4
Re: custom data in API v2
April 04, 2008, 07:20:24 am
Sorry for the delayed reply..

Here is the test case using Contact v2 API (which sets/gets custom data)

http://svn.civicrm.org/civicrm/branches/v2.0/test-new/SimpleTest/api-v2/ContactAddWithCustomData.php

Manish

dalin

  • I post occasionally
  • **
  • Posts: 89
  • Karma: 8
  • CiviCRM version: many
  • CMS version: Drupal 6
  • MySQL version: 5.0
  • PHP version: 5.2
Re: custom data in API v2
April 06, 2008, 05:47:07 pm
Hey Manish,
Thanks for the example code.  I'm looking through your unit test and I see two issues:

Code: [Select]
$this->assertEqual( $getContact['custom_5'],   $params['custom_5']   );
custom_5 was never defined, so you're asserting that null == null

Also you haven't created the custom fields before the test and destoroyed them afterward, you're assuming that they're already there.  This makes the test easily breakable. 

--
Dave Hansen-Lange
Web Developer
Advomatic LLC
http://advomatic.com
Hong Kong office

Chris Burgess

  • Ask me questions
  • ****
  • Posts: 675
  • Karma: 59
Re: custom data in API v2
April 08, 2008, 03:43:06 am
Reading Manish's code, I had figured that NULL = NULL assertion was intentional, to demonstrate that a custom value which was never set will be equal to an uninitialised variable.

However, I did have trouble using the same example code to UPDATE (not INSERT) custom data. I posted about this in a separate thread.

Dave, as you're working on making your code work with 2.x, please add any notes that might be useful to others migrating either to this forum thread:

http://forum.civicrm.org/index.php/topic,3008.msg13156.html

Or this wiki page:

http://wiki.civicrm.org/confluence/display/CRMDOC/Migrating+from+1.x+API+to+2.x+API
@xurizaemon ● www.fuzion.co.nz

Manish Zope

  • I’m new here
  • *
  • Posts: 18
  • Karma: 4
Re: custom data in API v2
April 09, 2008, 12:06:25 am
Check the modified test case
http://fisheye.civicrm.org/browse/CiviCRM/branches/v2.0/test-new/SimpleTest/api-v2/ContactAddWithCustomData.php?r=13903

Quote from: dalin on April 06, 2008, 05:47:07 pm
Code: [Select]
$this->assertEqual( $getContact['custom_5'],   $params['custom_5']   );custom_5 was never defined, so you're asserting that null == null

ijames

  • Guest
Re: custom data in API v2
April 09, 2008, 01:05:40 am
I'm running into the same problem with trying to set custom data. 

How does one run the test code provided?

Thanks!

James

Chris Burgess

  • Ask me questions
  • ****
  • Posts: 675
  • Karma: 59
Re: custom data in API v2
May 29, 2008, 09:52:21 pm
Hi ljames

If you want to run the SimpleTest api-v2/LocationGet.php, then you'd use this URL.

http://localhost/drupal/sites/all/modules/civicrm/test-new/SimpleTest/OneTest.php?q=api-v2/LocationGet

My dev server is "localhost" and the path to the CiviCRM code is "/drupal/sites/all/modules/civicrm/" - those values may be different for you. Also, don't forget to remove the ".php" from the end of the ?q= parameter.

Docs: http://wiki.civicrm.org/confluence/display/CRM/Writing+SimpleTest+unit+tests
@xurizaemon ● www.fuzion.co.nz

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • custom data in API v2

This forum was archived on 2017-11-26.