Answers.Body: <p>We are experiencing a similar type error on staging site running 5.21</p>
  
  <p>-we have created a custom field in the civicrm profile used for site registration, e.g. that matches on a unique identifier (card Number)</p>
  
  <p>-The error we are getting looks likes this :</p>
  
  <p>TypeError: Argument 1 passed to civicrm_api3() must be of the type string, null given, called in /home/ibew90v2/master/sites/all/modules/civicrm/CRM/Dedupe/BAO/Rule.php on line 62 in civicrm_api3() (line 84 of /home/ibew90v2/master/sites/all/modules/civicrm/api/api.php).
  ERROR
  The website encountered an unexpected error. Please try again later.  </p>
  
  <p>The error appears to state that it is looking for null value (?) and cannot handle any input (alphanumeric or otherwise in the field)
  Placing nothing in the custom field it allows the profile submission and creates the account.</p>
  
  <p>The latest release notes here reference a change to the api <a href="https://github.com/civicrm/civicrm-core/blob/master/release-notes/5.21.0.md" rel="nofollow noreferrer">https://github.com/civicrm/civicrm-core/blob/master/release-notes/5.21.0.md</a>
  <a href="https://github.com/civicrm/civicrm-core/pull/15817" rel="nofollow noreferrer">https://github.com/civicrm/civicrm-core/pull/15817</a></p>
  
  <p>"Fixes a formatting issue in the api explorer output where IS NULL and IS NOT NULL clauses would output invalid code due to the missing value piece of the clause."
  it appears that the api did not update, somehow when doing the upgrade, that it is still referencing the apiv3 folder .</p>
  
  <p>Notes :</p>
  
  <p>first part of the error references line 66 in the rule.php file, e.g. /home/ibew90v2/master/sites/all/modules/civicrm/api/v3/Rule.php
  "This api exposes CiviCRM (dedupe) rules."</p>
  
  <p>The second part of the error references the api.php file at /home/ibew90v2/master/sites/all/modules/civicrm/api/api.php
  it is breaking down here, line 84 : 
   function civicrm_api3(string $entity, string $action, array $params = []) {  $params['version'] = 3;</p>
  
  <p>However 5.21 per release notes is using api v4 -- are these old files ? need to be replaced or updated?</p>
  
  <p>Possible fix here : <a href="https://github.com/civicrm/civicrm-core/pull/15817/files" rel="nofollow noreferrer">https://github.com/civicrm/civicrm-core/pull/15817/files</a>  </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-22T11:25:43.367Z
Answers.LastActivityDate: 2020-01-22T11:25:43.367Z
Answers.UserDisplayName: M K
Answers.Body: <p>Thanks mmk.  I also encountered this issue on CIVICRM5.21.2/Wordpress 5.4.2.  This phenomena appeared to me when I tried to find duplicates using a dedupe rule based on a custom field.  it would crash at WP end. I followed you instruction above and it works, only slight modification to your instruction that it the check should be inserted after line 61 where &quot;$entity = CRM_Core_DAO_AllCoreTables...&quot; is called.  thanks again.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-29T03:48:44.537Z
Answers.LastActivityDate: 2020-10-29T03:48:44.537Z
Answers.UserDisplayName: Clement Leong
Answers.Body: <p>On further debugging, I see that this function isn't returning anything
  CRM_Core_DAO_AllCoreTables::getClassForTable($this->rule_table). (Line 61 Dedupe/BAO/Rule.php)</p>
  
  <p>So, in getClassForTable, the list of tables doesn't include 'civicrm_view_members_1' and therefore </p>
  
  <p>$entity = CRM_Core_DAO_AllCoreTables::getBriefName(CRM_Core_DAO_AllCoreTables::getClassForTable($this->rule_table));</p>
  
  <p>$entity is set to null. which then gives the error Argument 1 passed to civicrm_api3() must be of the type string, null given.</p>
  
  <p>I will have to check if its related to the api version problem. </p>
  
  <p>Edit:
  Added this check here after line 62 in civicrm/CRM/Dedupe/BAO/Rule.php </p>
  
  <pre><code>// if $entity is not set, setting it to empty string because of type declarations 
  $entity = $entity ? $entity : '';
  </code></pre>
  
  <p>It seems to have fixed the issue and dedupe on the custom field also looks ok.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-23T09:49:10.287Z
Answers.Text: Hi mmk, welcome to Stackexchange, it is worth editing any current information with any new information rather than submitting a new answer that doesn't really answer the question as this is likely to get downvoted because of that :)
Answers.UserDisplayName: Jade
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-22T13:03:09.003Z
Answers.LastActivityDate: 2020-01-23T12:13:35.313Z
Answers.LastEditDate: 2020-01-23T12:13:35.313Z
Answers.UserDisplayName: mmk
Body: <p>After upgrading to civicrm version 5.21 we detected a problem in one of the fields of the form linked to a custom profile.</p>
  
  <p>For some reason, every time you try to insert that data from the form in the frontend it returns the error message:</p>
  
  <p>0 Argument 1 passed to civicrm_api3() must be of the type string, null given, called in /public_html/administrator/components/com_civicrm/civicrm/CRM/Dedupe/BAO/Rule.php on line 62</p>
  
  <p>It is an alphanumeric text field, the same as others that populate the form.
  Has anyone else come across this problem? What can it be caused by?</p>
  
  <p>EDIT - the field in question is used for DEDUPE RULE (for control of duplicate entries), looks like there is something broke with that</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-01-23T16:11:34.493Z
Comments.Text: This does look like a bug of some kind, but hard to guess exactly based on the limited information available. It might be a bug in CiviCRM (perhaps search at https://lab.civicrm.org/dev/core/issues to see if you can find an existing bug report), or it might lie within an extension. You could use process of elimination to find out if it's an extension,  by selectively disabling extensions on the site. Failing that, your best course of action may be to get hands-on help (probably for a fee) from a CiviCRM developer (see https://civicrm.org/partners-contributors as a starting point).
Comments.UserDisplayName: TwoMice
Tags: <custom-fields><profile><duplicate-contacts>
Title: Issue field DEDUPE "0 Argument 1 passed to"
ThreadText: # Issue field DEDUPE "0 Argument 1 passed to"
  
  (Asked by: username_0 on 2020-01-07)
  
  After upgrading to civicrm version 5.21 we detected a problem in one of the fields of the form linked to a custom profile.
  
  For some reason, every time you try to insert that data from the form in the frontend it returns the error message:
  
  0 Argument 1 passed to civicrm\_api3() must be of the type string, null given, called in /public\_html/administrator/components/com\_civicrm/civicrm/CRM/Dedupe/BAO/Rule.php on line 62
  
  It is an alphanumeric text field, the same as others that populate the form.
  Has anyone else come across this problem? What can it be caused by?
  
  EDIT - the field in question is used for DEDUPE RULE (for control of duplicate entries), looks like there is something broke with that
  
  **Tags:** custom-fields, profile, duplicate-contacts
  
  > **Comments:**
  > **username_1**: This does look like a bug of some kind, but hard to guess exactly based on the limited information available. It might be a bug in CiviCRM (perhaps search at https://lab.civicrm.org/dev/core/issues to see if you can find an existing bug report), or it might lie within an extension. You could use process of elimination to find out if it's an extension,  by selectively disabling extensions on the site. Failing that, your best course of action may be to get hands-on help (probably for a fee) from a CiviCRM developer (see https://civicrm.org/partners-contributors as a starting point).  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_2 on 2020-01-22. Score: 0
  
  We are experiencing a similar type error on staging site running 5.21
  
  -we have created a custom field in the civicrm profile used for site registration, e.g. that matches on a unique identifier (card Number)
  
  -The error we are getting looks likes this :
  
  TypeError: Argument 1 passed to civicrm\_api3() must be of the type string, null given, called in /home/ibew90v2/master/sites/all/modules/civicrm/CRM/Dedupe/BAO/Rule.php on line 62 in civicrm\_api3() (line 84 of /home/ibew90v2/master/sites/all/modules/civicrm/api/api.php).
  ERROR
  The website encountered an unexpected error. Please try again later.
  
  The error appears to state that it is looking for null value (?) and cannot handle any input (alphanumeric or otherwise in the field)
  Placing nothing in the custom field it allows the profile submission and creates the account.
  
  The latest release notes here reference a change to the api <https://github.com/civicrm/civicrm-core/blob/master/release-notes/5.21.0.md>
  <https://github.com/civicrm/civicrm-core/pull/15817>
  
  "Fixes a formatting issue in the api explorer output where IS NULL and IS NOT NULL clauses would output invalid code due to the missing value piece of the clause."
  it appears that the api did not update, somehow when doing the upgrade, that it is still referencing the apiv3 folder .
  
  Notes :
  
  first part of the error references line 66 in the rule.php file, e.g. /home/ibew90v2/master/sites/all/modules/civicrm/api/v3/Rule.php
  "This api exposes CiviCRM (dedupe) rules."
  
  The second part of the error references the api.php file at /home/ibew90v2/master/sites/all/modules/civicrm/api/api.php
  it is breaking down here, line 84 : 
   function civicrm\_api3(string $entity, string $action, array $params = []) {  $params['version'] = 3;
  
  However 5.21 per release notes is using api v4 -- are these old files ? need to be replaced or updated?
  
  Possible fix here : <https://github.com/civicrm/civicrm-core/pull/15817/files>
  
  
  ---
  
  ### Answer by username_3 on 2020-10-29. Score: 0
  
  Thanks mmk. I also encountered this issue on CIVICRM5.21.2/Wordpress 5.4.2. This phenomena appeared to me when I tried to find duplicates using a dedupe rule based on a custom field. it would crash at WP end. I followed you instruction above and it works, only slight modification to your instruction that it the check should be inserted after line 61 where "$entity = CRM\_Core\_DAO\_AllCoreTables..." is called. thanks again.
  
  
  ---
  
  ### Answer by username_4 on 2020-01-22. Score: 0
  
  On further debugging, I see that this function isn't returning anything
  CRM\_Core\_DAO\_AllCoreTables::getClassForTable($this->rule\_table). (Line 61 Dedupe/BAO/Rule.php)
  
  So, in getClassForTable, the list of tables doesn't include 'civicrm\_view\_members\_1' and therefore
  
  $entity = CRM\_Core\_DAO\_AllCoreTables::getBriefName(CRM\_Core\_DAO\_AllCoreTables::getClassForTable($this->rule\_table));
  
  $entity is set to null. which then gives the error Argument 1 passed to civicrm\_api3() must be of the type string, null given.
  
  I will have to check if its related to the api version problem.
  
  Edit:
  Added this check here after line 62 in civicrm/CRM/Dedupe/BAO/Rule.php
  
  ```
  // if $entity is not set, setting it to empty string because of type declarations 
  $entity = $entity ? $entity : '';
  
  ```
  
  It seems to have fixed the issue and dedupe on the custom field also looks ok.
  
  > **Comments:**
  > **username_5**: Hi mmk, welcome to Stackexchange, it is worth editing any current information with any new information rather than submitting a new answer that doesn't really answer the question as this is likely to get downvoted because of that :)  
  
  ---
  
  