0

Whats wrong with this code? After submitting my form, I want to create a new contact in CRM via PHP, but it returned 500

$result = civicrm_api4('Contact', 'Create', [
    'where' => [
        ['first_name', '=', $_POST['first-name']],
        ['last_name', '=', $_POST['last-name']],
        ['email', '=', $_POST['email']],
      ]
    ]);
0

Did you use api4 explorer (http://{site}/civicrm/api4) to generate that? You probably mean values instead of where.

And to do Email you'll need to chain: https://docs.civicrm.org/dev/en/latest/api/v4/chaining/

3
  • No, I'm created it by myself, When I try to follow this link it goes to 404 (http://{site}/civicrm/api4) and (http://{site}/wp-admin/civicrm/api4). Where I can see the name of the fields and everything connected with them, such as e-mail chaining?
    – Rustam
    Jun 17 at 8:05
  • And when I replace "where" to "values" and drop the "email", returns all the same 500. $result = civicrm_api4('Contact', 'Create', [ 'values' => [ ['first_name', '=', $_POST['first-name']], ['last_name', '=', $_POST['last-name']], ], ]);
    – Rustam
    Jun 17 at 8:10
  • I found worked URL - {my_site}/wp-admin/admin.php?page=CiviCRM&q=civicrm%2Fapi4#/explorer/Contact/
    – Rustam
    Jun 17 at 9:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.