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 (Moderator: Dave Greenberg) »
  • API help needed for custom data update/create
Pages: [1]

Author Topic: API help needed for custom data update/create  (Read 511 times)

dflorence

  • I’m new here
  • *
  • Posts: 24
  • Karma: 0
  • CiviCRM version: 4.4.3
  • CMS version: joomla 2.5 and testing 3.2.1
  • MySQL version: 5.1.69
  • PHP version: 5.3.3
API help needed for custom data update/create
November 28, 2012, 09:17:04 am
API help needed

I am trying to write an API that updates or creates custom address data (it uses the postcode from the address data to do a postcode lookup against another database to find the local authority and stores the result in the custom data field I have created in civi). The first bit is fine. The problem is inserting this into the civi custom data.

(This will update a joomla installation)

The code I *think* I want is from the examples folder (CustomValueCreate):

Code: [Select]
require_once '/home/persorgu/public_html/administrator/components/com_civicrm/civicrm.settings.php';
require_once 'CRM/Core/Config.php';
$config = CRM_Core_Config::singleton( );

function custom_value_create_example(){
$params = array(
  'custom_1' => 'customString',
  'version' => 3,
  'entity_id' => 1,
);

  require_once 'api/api.php';
  $result = civicrm_api( 'custom_value','create',$params );

  return $result;
}


$updatecustomdata=function custom_value_create_example();




I'm confused cos I cannot figure out where to substitute my data in the code above to make it work:.

e.g the data I have is $local_authority which is the data I want to insert and $address_id which is the corresponding addressid from the addresses table in civi.

the id for my custom data set in civi (called data derived from postcode) is 6

the name of the table (according to phpmyadmin) is civicrm_value_data_derived_from_postcode__6

the name of the field I want to update in the above table is called local_authority_18,  (in civi it is called Local Authority, id=18)

Any help on how to update thee above code with the required values gratefully received.
« Last Edit: November 28, 2012, 11:01:29 am by dflorence »

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: API help needed for custom data update/create
November 29, 2012, 12:07:27 am
You would probably want something like this ( I am assuming you are using a CiviCRM 4.2 installation)
Code: [Select]

$params = array(
  'custom_18' => 'customString',
  'version' => 3,
  'entity_id' => $contact_id,
);

civicrm_initialize();
$result = civicrm_api( 'custom_value','create',$params );

return $result;
}

You can certainly play with the API explorer to make sure you have the right syntax? Check this chapter in the developer guide http://book.civicrm.org/developer/current/techniques/api/
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

dflorence

  • I’m new here
  • *
  • Posts: 24
  • Karma: 0
  • CiviCRM version: 4.4.3
  • CMS version: joomla 2.5 and testing 3.2.1
  • MySQL version: 5.1.69
  • PHP version: 5.3.3
Re: API help needed for custom data update/create
November 29, 2012, 04:51:53 am
Thank you for the pointers Erik, It's looking better now.

The resources you poit me to are great. I would like to play with the api explorer but cannot find it at the location mentioned at http://book.civicrm.org/developer/current/techniques/api/

Is the API explorer only for Drupal? - Mine is a Joomla install.

Dave


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: API help needed for custom data update/create
November 29, 2012, 05:47:24 am
I think it should work for Joomla too....let me check..
There is a forum post about the topic: http://forum.civicrm.org/index.php?topic=24711.0
hope that helps.
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM (Moderator: Dave Greenberg) »
  • API help needed for custom data update/create

This forum was archived on 2017-11-26.