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) »
  • Problem updating custom data with API
Pages: [1]

Author Topic: Problem updating custom data with API  (Read 1045 times)

stuart

  • I post occasionally
  • **
  • Posts: 41
  • Karma: 0
  • CiviCRM version: 4.2.7
  • CMS version: Drupal 6
  • MySQL version: 5.0.77
  • PHP version: 5.3
Problem updating custom data with API
January 07, 2013, 04:12:06 am
I'm trying to update some custom data with the API, but I think I'm doing something wrong as I keep getting errors when using the API explorer.

Parameters in the API explorer:
Code: [Select]
/civicrm/ajax/rest?json=1&debug=1&version=3&entity=CustomValue&action=update&id=2&entity_id=65843&custom_103=6

(which apparently generates)

$results=civicrm_api("CustomValue","update", array ('version' =>'3', 'id' =>'2', 'entity_id' =>'65843', 'custom_103' =>'6'));

When testing with the API explorer, I get the error message:

Code: [Select]
"error_message":"entityID needs to be set and of type Integer"
Since I'm already specifying the unique row ID, I'm not sure why I even need to give the entity ID in the first place (it gives a different error if I don't provide it). Any suggestions appreciated.


Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Problem updating custom data with API
January 07, 2013, 06:29:43 am
Looks like you need to use entityID rather than entity_id, altough this is inconsistent behaviour. If this does solve your problem I would invite you to fix the API if possible?
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

stuart

  • I post occasionally
  • **
  • Posts: 41
  • Karma: 0
  • CiviCRM version: 4.2.7
  • CMS version: Drupal 6
  • MySQL version: 5.0.77
  • PHP version: 5.3
Re: Problem updating custom data with API
January 07, 2013, 07:05:50 am
Quote from: Erik Hommel on January 07, 2013, 06:29:43 am
Looks like you need to use entityID rather than entity_id, altough this is inconsistent behaviour. If this does solve your problem I would invite you to fix the API if possible?

Should have mentioned that I've tried that, made no difference. I use "entity_id" as that's what examples seem to use.

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Problem updating custom data with API
January 07, 2013, 07:24:31 am
Hmm here is what I have done with a working script for 4.2.6:
Code: [Select]
$customColumn = "custom_".$customFieldID;
civicrm_api( 'CustomValue', 'create', array (
   'version'       =>  '3',
   'entity_id'     =>  $contactID,
   $customColumn   =>  $bsn ) );

and this works. Can you try the create function? Inside the API it will call the create with an ID anyway for an update action.
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

stuart

  • I post occasionally
  • **
  • Posts: 41
  • Karma: 0
  • CiviCRM version: 4.2.7
  • CMS version: Drupal 6
  • MySQL version: 5.0.77
  • PHP version: 5.3
Re: Problem updating custom data with API
January 07, 2013, 07:37:32 am
Thanks very much, it's working if I use 'create' instead. Seems the update API is broken.

Still requires an entity_id before it will run the method though, which seems a bit odd as I'm supplying a unique key. I can live with that though  :)

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Problem updating custom data with API
January 07, 2013, 07:49:27 am
Glad it works! Can you please raise a bug for your problem here: http://issues.civicrm.org/jira/secure/Dashboard.jspa
Thanks...
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

stuart

  • I post occasionally
  • **
  • Posts: 41
  • Karma: 0
  • CiviCRM version: 4.2.7
  • CMS version: Drupal 6
  • MySQL version: 5.0.77
  • PHP version: 5.3
Re: Problem updating custom data with API
January 07, 2013, 08:16:34 am
Quote from: Erik Hommel on January 07, 2013, 07:49:27 am
Glad it works! Can you please raise a bug for your problem here: http://issues.civicrm.org/jira/secure/Dashboard.jspa
Thanks...

Sure, just waiting for an email from Jira

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Problem updating custom data with API
January 07, 2013, 08:45:28 am
Great, thanks!
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Problem updating custom data with API

This forum was archived on 2017-11-26.