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 »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • civicrm_event_create() not working for editing an event
Pages: [1]

Author Topic: civicrm_event_create() not working for editing an event  (Read 1282 times)

apotropaic

  • I post occasionally
  • **
  • Posts: 34
  • Karma: 1
  • CiviCRM version: 4.4.4
  • CMS version: Wordpress 1.8
  • MySQL version: 5.5.32
  • PHP version: 5.3.10
civicrm_event_create() not working for editing an event
March 24, 2011, 02:48:51 pm
Hi! I'm trying to modify some custom fields tied to an event. I used the following code on a civi 3.3.5 build:
Code: [Select]
$params = array('event_id' => 2, 'custom_5_1' => 'Testing');
$result = civicrm_event_create( $params );
print_r($result);

// RESULT BELOW
// Array ( [is_error] => 1 [error_message] => Mandatory param missing: start_date )

It says in the api Docs that if you pass the 'event_id' with your params that it will update the event rather then try to create a new one.

I tried just changing the title of the event, just seeing if the custom field was the issue. Also I tried specifying the fields that it is saying are mandatory and it created a new event. The rest of the APIs are working well.

Anybody have any issues editing events?

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: civicrm_event_create() not working for editing an event
March 24, 2011, 03:42:57 pm

can u try 'id' instead of 'event_id'

thanx

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: civicrm_event_create() not working for editing an event
March 24, 2011, 04:35:03 pm
Hi,

My recollection is that api v2 event api doesn't allow you to create custom fields anyway but that v3 (which you can backport ) does

I added a test to event update to check how it works & generated an example here

http://svn.civicrm.org/civicrm/trunk/api/v3/examples/EventUpdate.php

but it doesn't check custom fields work in v3 - I'm just going off memory on that one

Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

apotropaic

  • I post occasionally
  • **
  • Posts: 34
  • Karma: 1
  • CiviCRM version: 4.4.4
  • CMS version: Wordpress 1.8
  • MySQL version: 5.5.32
  • PHP version: 5.3.10
Re: civicrm_event_create() not working for editing an event
March 24, 2011, 05:03:06 pm
Thanks for response guys. I'm even trying to change just the title like this, but get the same errors being returned:

Code: [Select]
$params = array('id' => 2, 'title' => 'Test Event');
$result = civicrm_event_create( $params );

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: civicrm_event_create() not working for editing an event
March 24, 2011, 05:10:37 pm
I suspect that if you are using v2 you just need to do a get first & get the start date & feed it in.

At some point I will introduce a test in v3 to verify that adding custom fields bit DOES work
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

apotropaic

  • I post occasionally
  • **
  • Posts: 34
  • Karma: 1
  • CiviCRM version: 4.4.4
  • CMS version: Wordpress 1.8
  • MySQL version: 5.5.32
  • PHP version: 5.3.10
Re: civicrm_event_create() not working for editing an event
March 25, 2011, 10:55:03 am
Thanks eileen and lobo for pointing me in the right direction. It was a combination of needing to use 'id' vs 'event_id', like the api docs say and need to pull a get request before to get the current 'title', 'start_date', 'event_type_id', which are all requirements apparently.

Code: [Select]
$getEvent = array('id' => 2);
$getResult = civicrm_event_get( $getEvent );

$date = date('YmdHis', strtotime($getResult['start_date']));

$setEvent = array('id' => 2, 'custom_5_1' => 39, 'title' => $getResult['title'] , 'start_date' => $date, 'event_type_id' => $getResult['event_type_id']);
$setResult = civicrm_event_create( $setEvent );

maybe I will update the wiki with this example?

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: civicrm_event_create() not working for editing an event
March 25, 2011, 11:10:32 am

IMO, this is a bug and we should fix it (for 3.4)

can you please file an issue, so we can clean this up.

In general, update should not require sending in the "required" fields

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

apotropaic

  • I post occasionally
  • **
  • Posts: 34
  • Karma: 1
  • CiviCRM version: 4.4.4
  • CMS version: Wordpress 1.8
  • MySQL version: 5.5.32
  • PHP version: 5.3.10
Re: civicrm_event_create() not working for editing an event
March 25, 2011, 02:45:55 pm
OK, I filed the issue today. Hope its ok that I just linked to this post. Thanks again for you help!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • civicrm_event_create() not working for editing an event

This forum was archived on 2017-11-26.