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) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Very odd problem using API to create contacts & register for events
Pages: [1]

Author Topic: Very odd problem using API to create contacts & register for events  (Read 814 times)

trevorwood

  • I post occasionally
  • **
  • Posts: 119
  • Karma: 4
  • CiviCRM version: 4.0.2
  • CMS version: Joomla 1.6
  • MySQL version: 5.0.51a
  • PHP version: 5.2.6-1+lenny8
Very odd problem using API to create contacts & register for events
January 12, 2012, 02:49:01 am
I've got a very odd problem - it's probably somethign to do with protections but I don't understand why one bit works and the other doesn't

I've got some code to create a new organization and a new individual in the contacts tabel

To create the organization, the code is

$params = array(
   'contact_type' => 'Organization',
   'organization_name' => $company,
   $custom_nature_of_business => $natureofbusiness,
   'version' => 3,
);
$result = civicrm_api ('contact', 'create', $params);

and this creates the organization record file

to create the individual, the code is

$params = array(
   'first_name' => $firstname,
   'last_name' => $lastname,
   'contact_type' => 'Individual',
   'current_employer' => $company,
   'email' => $email_address,
   'api.phone.create' => array (
      'phone_type_id' => 1,
      'phone' => $phonenumber,
      'is_primary' => 1,
      'location_type_id' => 3,
   ),
   'version' => 3,
);
$result = civicrm_api( 'contact','create',$params );

and it fails with Array ( [is_error] => 1 [error_message] => DB Error: no such table ) - although it does create a record with the first & last names

If I take out the 'current_employer' the call works.

Finally I get something similar when trying to add them to an event

code is

$params = array(
   'contact_id' => $contact_id,
   'event_id' => $event_id,
   'status_id' => $status_id,
   'role_id' => $booked_attendee,
   'register_date' => $today,
   'source' => $source,
   'version' => 3,
);
$result = civicrm_api( 'participant','create',$params );

and again I get Array ( [is_error] => 1 [error_message] => DB Error: no such table )

The person doing the creation has 'public' access (i.e. the lowest of the low). If I try it with someone who has some additional privs it works. I'm particularly concerned about the 'employer' bit

trevorwood

  • I post occasionally
  • **
  • Posts: 119
  • Karma: 4
  • CiviCRM version: 4.0.2
  • CMS version: Joomla 1.6
  • MySQL version: 5.0.51a
  • PHP version: 5.2.6-1+lenny8
Re: Very odd problem using API to create contacts & register for events
January 12, 2012, 03:14:39 am
Quote from: trevorwood on January 12, 2012, 02:49:01 am
Finally I get something similar when trying to add them to an event

code is

$params = array(
   'contact_id' => $contact_id,
   'event_id' => $event_id,
   'status_id' => $status_id,
   'role_id' => $booked_attendee,
   'register_date' => $today,
   'source' => $source,
   'version' => 3,
);
$result = civicrm_api( 'participant','create',$params );

and again I get Array ( [is_error] => 1 [error_message] => DB Error: no such table )

The person doing the creation has 'public' access (i.e. the lowest of the low). If I try it with someone who has some additional privs it works. I'm particularly concerned about the 'employer' bit

Further to this - although there's this error message, the participant has been registered for the event. It's working as I need it to work and - fortunately - on the live server no error messages are displayed, so I can live with it, but there must be an underlying problem. If I give the user "edit event participands" and "edit all events" access control the error message goes away

With the ecurrent_employer, if I grant "add contacts" access control, it all works OK. I'm relatively happy to do this, but it is a bit odd.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Very odd problem using API to create contacts & register for events
January 12, 2012, 03:41:13 am
Hi,

Which version of civi are you using? This error seems a bit weird, and what is even weirder is that the api (when used from php and by default) doesn't take into account the permissions.

Do you have extra modules & hooks?

Anyway, to debug further, you might want to try the api explorer (on your site /civicrm/api/explorer) and try to reproduce your calls and see what you get
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

trevorwood

  • I post occasionally
  • **
  • Posts: 119
  • Karma: 4
  • CiviCRM version: 4.0.2
  • CMS version: Joomla 1.6
  • MySQL version: 5.0.51a
  • PHP version: 5.2.6-1+lenny8
Re: Very odd problem using API to create contacts & register for events
January 12, 2012, 04:00:10 am
I'm on civicrm 4.0.7 (i think) - haven't upgraded to the latest release yet as I had a problem first time and haven't had time to try again.

On further inspection I needed to set Edit Contacts not add contacts to the ACL

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Very odd problem using API to create contacts & register for events

This forum was archived on 2017-11-26.