4 * Test Generated API Example.
5 * See bottom of this file for more detail.
9 * Test Generated example of using contact GetFields API.
11 * Demonstrate retrieving metadata with custom field options
16 function contact_getfields_example() {
19 'get_options' => 'custom_1',
25 $result = civicrm_api3('contact', 'GetFields', $params);
27 catch (CiviCRM_API3_Exception
$e) {
29 $errorMessage = $e->getMessage();
30 $errorCode = $e->getErrorCode();
31 $errorData = $e->getExtraParams();
33 'error' => $errorMessage,
34 'error_code' => $errorCode,
35 'error_data' => $errorData,
43 * Function returns array of result expected from previous function.
48 function contact_getfields_expectedresult() {
50 $expectedResult = array(
58 'title' => 'Internal Contact ID',
61 'where' => 'civicrm_contact.id',
62 'headerPattern' => '/internal|contact?|id$/i',
64 'api.aliases' => array(
68 'contact_type' => array(
69 'name' => 'contact_type',
71 'title' => 'Contact Type',
75 'where' => 'civicrm_contact.contact_type',
79 'pseudoconstant' => array(
80 'table' => 'civicrm_contact_type',
81 'keyColumn' => 'name',
82 'labelColumn' => 'label',
83 'condition' => 'parent_id IS NULL',
87 'contact_sub_type' => array(
88 'name' => 'contact_sub_type',
90 'title' => 'Contact Subtype',
94 'where' => 'civicrm_contact.contact_sub_type',
95 'headerPattern' => '/C(ontact )?(subtype|sub-type|sub type)/i',
98 'type' => 'Multi-Select',
100 'pseudoconstant' => array(
101 'table' => 'civicrm_contact_type',
102 'keyColumn' => 'name',
103 'labelColumn' => 'label',
104 'condition' => 'parent_id IS NOT NULL',
107 'do_not_email' => array(
108 'name' => 'do_not_email',
110 'title' => 'Do Not Email',
112 'where' => 'civicrm_contact.do_not_email',
113 'headerPattern' => '/d(o )?(not )?(email)/i',
114 'dataPattern' => '/^\\d{1,}$/',
117 'type' => 'CheckBox',
120 'do_not_phone' => array(
121 'name' => 'do_not_phone',
123 'title' => 'Do Not Phone',
125 'where' => 'civicrm_contact.do_not_phone',
126 'headerPattern' => '/d(o )?(not )?(call|phone)/i',
127 'dataPattern' => '/^\\d{1,}$/',
130 'type' => 'CheckBox',
133 'do_not_mail' => array(
134 'name' => 'do_not_mail',
136 'title' => 'Do Not Mail',
138 'where' => 'civicrm_contact.do_not_mail',
139 'headerPattern' => '/^(d(o\\s)?n(ot\\s)?mail)|(\\w*)?bulk\\s?(\\w*)$/i',
140 'dataPattern' => '/^\\d{1,}$/',
143 'type' => 'CheckBox',
146 'do_not_sms' => array(
147 'name' => 'do_not_sms',
149 'title' => 'Do Not Sms',
151 'where' => 'civicrm_contact.do_not_sms',
152 'headerPattern' => '/d(o )?(not )?(sms)/i',
153 'dataPattern' => '/^\\d{1,}$/',
156 'type' => 'CheckBox',
159 'do_not_trade' => array(
160 'name' => 'do_not_trade',
162 'title' => 'Do Not Trade',
164 'where' => 'civicrm_contact.do_not_trade',
165 'headerPattern' => '/d(o )?(not )?(trade)/i',
166 'dataPattern' => '/^\\d{1,}$/',
169 'type' => 'CheckBox',
172 'is_opt_out' => array(
173 'name' => 'is_opt_out',
175 'title' => 'No Bulk Emails (User Opt Out)',
178 'where' => 'civicrm_contact.is_opt_out',
181 'type' => 'CheckBox',
184 'legal_identifier' => array(
185 'name' => 'legal_identifier',
187 'title' => 'Legal Identifier',
191 'where' => 'civicrm_contact.legal_identifier',
192 'headerPattern' => '/legal\\s?id/i',
193 'dataPattern' => '/\\w+?\\d{5,}/',
199 'external_identifier' => array(
200 'name' => 'external_identifier',
202 'title' => 'External Identifier',
206 'where' => 'civicrm_contact.external_identifier',
207 'headerPattern' => '/external\\s?id/i',
208 'dataPattern' => '/^\\d{11,}$/',
214 'sort_name' => array(
215 'name' => 'sort_name',
217 'title' => 'Sort Name',
221 'where' => 'civicrm_contact.sort_name',
226 'display_name' => array(
227 'name' => 'display_name',
229 'title' => 'Display Name',
233 'where' => 'civicrm_contact.display_name',
238 'nick_name' => array(
239 'name' => 'nick_name',
241 'title' => 'Nickname',
245 'where' => 'civicrm_contact.nick_name',
246 'headerPattern' => '/n(ick\\s)name|nick$/i',
247 'dataPattern' => '/^\\w+$/',
253 'legal_name' => array(
254 'name' => 'legal_name',
256 'title' => 'Legal Name',
260 'where' => 'civicrm_contact.legal_name',
261 'headerPattern' => '/^legal|(l(egal\\s)?name)$/i',
267 'image_URL' => array(
268 'name' => 'image_URL',
270 'title' => 'Image Url',
274 'where' => 'civicrm_contact.image_URL',
280 'preferred_communication_method' => array(
281 'name' => 'preferred_communication_method',
283 'title' => 'Preferred Communication Method',
287 'where' => 'civicrm_contact.preferred_communication_method',
288 'headerPattern' => '/^p(ref\\w*\\s)?c(omm\\w*)|( meth\\w*)$/i',
289 'dataPattern' => '/^\\w+$/',
294 'pseudoconstant' => array(
295 'optionGroupName' => 'preferred_communication_method',
298 'preferred_language' => array(
299 'name' => 'preferred_language',
301 'title' => 'Preferred Language',
305 'where' => 'civicrm_contact.preferred_language',
306 'headerPattern' => '/^lang/i',
311 'pseudoconstant' => array(
312 'optionGroupName' => 'languages',
313 'keyColumn' => 'name',
316 'preferred_mail_format' => array(
317 'name' => 'preferred_mail_format',
319 'title' => 'Preferred Mail Format',
323 'where' => 'civicrm_contact.preferred_mail_format',
324 'headerPattern' => '/^p(ref\\w*\\s)?m(ail\\s)?f(orm\\w*)$/i',
330 'pseudoconstant' => array(
331 'callback' => 'CRM_Core_SelectValues::pmf',
337 'title' => 'Contact Hash',
341 'where' => 'civicrm_contact.hash',
346 'title' => 'Api Key',
350 'first_name' => array(
351 'name' => 'first_name',
353 'title' => 'First Name',
357 'where' => 'civicrm_contact.first_name',
358 'headerPattern' => '/^first|(f(irst\\s)?name)$/i',
359 'dataPattern' => '/^\\w+$/',
365 'middle_name' => array(
366 'name' => 'middle_name',
368 'title' => 'Middle Name',
372 'where' => 'civicrm_contact.middle_name',
373 'headerPattern' => '/^middle|(m(iddle\\s)?name)$/i',
374 'dataPattern' => '/^\\w+$/',
380 'last_name' => array(
381 'name' => 'last_name',
383 'title' => 'Last Name',
387 'where' => 'civicrm_contact.last_name',
388 'headerPattern' => '/^last|(l(ast\\s)?name)$/i',
389 'dataPattern' => '/^\\w+(\\s\\w+)?+$/',
395 'prefix_id' => array(
396 'name' => 'prefix_id',
398 'title' => 'Individual Prefix',
400 'where' => 'civicrm_contact.prefix_id',
401 'headerPattern' => '/^(prefix|title)/i',
402 'dataPattern' => '/^(mr|ms|mrs|sir|dr)\\.?$/i',
407 'pseudoconstant' => array(
408 'optionGroupName' => 'individual_prefix',
410 'api.aliases' => array(
411 '0' => 'individual_prefix',
412 '1' => 'individual_prefix_id',
415 'suffix_id' => array(
416 'name' => 'suffix_id',
418 'title' => 'Individual Suffix',
420 'where' => 'civicrm_contact.suffix_id',
421 'headerPattern' => '/^suffix$/i',
422 'dataPattern' => '/^(sr|jr)\\.?|i{2,}$/',
427 'pseudoconstant' => array(
428 'optionGroupName' => 'individual_suffix',
430 'api.aliases' => array(
431 '0' => 'individual_suffix',
432 '1' => 'individual_suffix_id',
435 'formal_title' => array(
436 'name' => 'formal_title',
438 'title' => 'Formal Title',
442 'where' => 'civicrm_contact.formal_title',
443 'headerPattern' => '/^title/i',
446 'communication_style_id' => array(
447 'name' => 'communication_style_id',
449 'title' => 'Communication Style',
451 'where' => 'civicrm_contact.communication_style_id',
452 'pseudoconstant' => array(
453 'optionGroupName' => 'communication_style',
456 'email_greeting_id' => array(
457 'name' => 'email_greeting_id',
459 'title' => 'Email Greeting ID',
461 'email_greeting_custom' => array(
462 'name' => 'email_greeting_custom',
464 'title' => 'Email Greeting Custom',
468 'where' => 'civicrm_contact.email_greeting_custom',
473 'email_greeting_display' => array(
474 'name' => 'email_greeting_display',
476 'title' => 'Email Greeting',
483 'postal_greeting_id' => array(
484 'name' => 'postal_greeting_id',
486 'title' => 'Postal Greeting ID',
491 'postal_greeting_custom' => array(
492 'name' => 'postal_greeting_custom',
494 'title' => 'Postal Greeting Custom',
498 'where' => 'civicrm_contact.postal_greeting_custom',
503 'postal_greeting_display' => array(
504 'name' => 'postal_greeting_display',
506 'title' => 'Postal Greeting',
513 'addressee_id' => array(
514 'name' => 'addressee_id',
516 'title' => 'Addressee ID',
518 'addressee_custom' => array(
519 'name' => 'addressee_custom',
521 'title' => 'Addressee Custom',
525 'where' => 'civicrm_contact.addressee_custom',
530 'addressee_display' => array(
531 'name' => 'addressee_display',
533 'title' => 'Addressee',
540 'job_title' => array(
541 'name' => 'job_title',
543 'title' => 'Job Title',
547 'where' => 'civicrm_contact.job_title',
548 'headerPattern' => '/^job|(j(ob\\s)?title)$/i',
549 'dataPattern' => '//',
555 'gender_id' => array(
556 'name' => 'gender_id',
560 'where' => 'civicrm_contact.gender_id',
561 'headerPattern' => '/^gender$/i',
566 'pseudoconstant' => array(
567 'optionGroupName' => 'gender',
570 'birth_date' => array(
571 'name' => 'birth_date',
573 'title' => 'Birth Date',
575 'where' => 'civicrm_contact.birth_date',
576 'headerPattern' => '/^birth|(b(irth\\s)?date)|D(\\W*)O(\\W*)B(\\W*)$/i',
577 'dataPattern' => '/\\d{4}-?\\d{2}-?\\d{2}/',
580 'type' => 'Select Date',
583 'is_deceased' => array(
584 'name' => 'is_deceased',
586 'title' => 'Is Deceased',
588 'where' => 'civicrm_contact.is_deceased',
589 'headerPattern' => '/i(s\\s)?d(eceased)$/i',
592 'type' => 'CheckBox',
595 'deceased_date' => array(
596 'name' => 'deceased_date',
598 'title' => 'Deceased Date',
600 'where' => 'civicrm_contact.deceased_date',
601 'headerPattern' => '/^deceased|(d(eceased\\s)?date)$/i',
604 'type' => 'Select Date',
607 'household_name' => array(
608 'name' => 'household_name',
610 'title' => 'Household Name',
614 'where' => 'civicrm_contact.household_name',
615 'headerPattern' => '/^household|(h(ousehold\\s)?name)$/i',
616 'dataPattern' => '/^\\w+$/',
622 'primary_contact_id' => array(
623 'name' => 'primary_contact_id',
625 'title' => 'Household Primary Contact ID',
626 'FKClassName' => 'CRM_Contact_DAO_Contact',
630 'FKApiName' => 'Contact',
632 'organization_name' => array(
633 'name' => 'organization_name',
635 'title' => 'Organization Name',
639 'where' => 'civicrm_contact.organization_name',
640 'headerPattern' => '/^organization|(o(rganization\\s)?name)$/i',
641 'dataPattern' => '/^\\w+$/',
648 'name' => 'sic_code',
650 'title' => 'Sic Code',
654 'where' => 'civicrm_contact.sic_code',
655 'headerPattern' => '/^sic|(s(ic\\s)?code)$/i',
661 'user_unique_id' => array(
662 'name' => 'user_unique_id',
664 'title' => 'Unique ID (OpenID)',
668 'where' => 'civicrm_contact.user_unique_id',
669 'headerPattern' => '/^Open\\s?ID|u(niq\\w*)?\\s?ID/i',
670 'dataPattern' => '/^[\\w\\/\\:\\.]+$/',
677 'created_date' => array(
678 'name' => 'created_date',
680 'title' => 'Created Date',
683 'where' => 'civicrm_contact.created_date',
686 'modified_date' => array(
687 'name' => 'modified_date',
689 'title' => 'Modified Date',
692 'where' => 'civicrm_contact.modified_date',
693 'default' => 'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',
698 'title' => 'Source of Contact Data',
702 'where' => 'civicrm_contact.source',
703 'headerPattern' => '/(S(ource\\s)?o(f\\s)?C(ontact\\s)?Data)$/i',
708 'uniqueName' => 'contact_source',
710 'employer_id' => array(
711 'name' => 'employer_id',
713 'title' => 'Current Employer ID',
715 'where' => 'civicrm_contact.employer_id',
716 'FKClassName' => 'CRM_Contact_DAO_Contact',
718 'type' => 'Autocomplete-Select',
720 'uniqueName' => 'current_employer_id',
721 'FKApiName' => 'Contact',
723 'is_deleted' => array(
724 'name' => 'is_deleted',
726 'title' => 'Contact is in Trash',
729 'where' => 'civicrm_contact.is_deleted',
731 'type' => 'CheckBox',
733 'uniqueName' => 'contact_is_deleted',
736 'label' => 'Our special field',
737 'groupTitle' => 'select_test_g',
738 'data_type' => 'String',
739 'html_type' => 'Select',
740 'default_value' => '',
742 'options_per_line' => '',
743 'custom_group_id' => '1',
744 'extends' => 'Contact',
745 'is_search_range' => 0,
746 'extends_entity_column_value' => '',
747 'extends_entity_column_id' => '',
750 'option_group_id' => '105',
753 'is_required' => '1',
754 'name' => 'custom_1',
755 'title' => 'Our special field',
762 'current_employer' => array(
763 'title' => 'Current Employer',
764 'description' => 'Name of Current Employer',
767 'dupe_check' => array(
768 'title' => 'Check for Duplicates',
769 'description' => 'Throw error if contact create matches dedupe rule',
774 return $expectedResult;
778 * This example has been generated from the API test suite.
779 * The test that created it is called
780 * testCustomFieldCreateWithOptionValues
781 * and can be found in
782 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php
784 * You can see the outcome of the API tests at
785 * https://test.civicrm.org/job/CiviCRM-master-git/
787 * To Learn about the API read
788 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
790 * Browse the api on your own site with the api explorer
791 * http://MYSITE.ORG/path/to/civicrm/api/explorer
793 * Read more about testing here
794 * http://wiki.civicrm.org/confluence/display/CRM/Testing
796 * API Standards documentation:
797 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards