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) »
  • Event Location (loc_block) via API?
Pages: [1]

Author Topic: Event Location (loc_block) via API?  (Read 3934 times)

DerekL

  • I post frequently
  • ***
  • Posts: 132
  • Karma: 1
  • CiviCRM version: 4.5.5
  • CMS version: Drupal 7.34
  • MySQL version: 5.1.54
  • PHP version: 5.2.17
Event Location (loc_block) via API?
March 25, 2012, 04:35:19 pm
Hi Guys and Gals,

I'm in the process of importing  historical events but I can't seem to find any documentation on how to import Event locations via the API?

From entity 'event', action 'getfields':

      "loc_block_id":{
         "name":"loc_block_id",
         "type":1,
         "FKClassName":"CRM_Core_DAO_LocBlock"
      },

The 'Location' entity returns the following for action 'create':

{
   "is_error":1,
   "error_message":"API (Location,Create) does not exist, use the Address\/Phone\/Email\/Website API instead",
   "obsoleted":true
}

I can't seem to find anything in the API explorer under Address/Phone/Email/Website entities that gives me any clues...

I can see that the `civicrm_loc_block` table holds a simple relationship between eventids and address,phone, and website id's but I can't seem to find any documentation on the "proper" API method to populate this table.

Any ideas, perchance?



xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Event Location (loc_block) via API?
March 26, 2012, 01:45:05 am
Hi,

We don't have a LocBlock api yet. You could implement it rather easily with a few lines of code.

Take api/v3/Email.php as an example to write api/V3/LocBlock

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

DerekL

  • I post frequently
  • ***
  • Posts: 132
  • Karma: 1
  • CiviCRM version: 4.5.5
  • CMS version: Drupal 7.34
  • MySQL version: 5.1.54
  • PHP version: 5.2.17
Re: Event Location (loc_block) via API?
March 26, 2012, 07:43:34 pm
Thanks for the tip Xavier,

I created LocBlock.php based on Email.php and I now have 'LocBlock' in the API explorer and can successfully run a "getfields" action.
(I'm using "require_once 'CRM/Core/BAO/Location.php';" instead of Email.php)

Whenever I try much else though, I get :

Code: [Select]
{
"is_error":1,
"error_message":"API (LocBlock,create) does not exist (join the API team and implement it!)"
}

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: Event Location (loc_block) via API?
March 26, 2012, 11:23:55 pm
The message  tells you it can not find the create function in the LocBlock API you created. Can you see the function in the code?
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Event Location (loc_block) via API?
March 27, 2012, 12:30:41 am
Hi,

Likely you didn't create the functions with the right names

http://civicrm.org/API_version_3

http://wiki.civicrm.org/confluence/display/CRMDOC/How+to+migrate+or+write+an+api

Would be super useful you update the wiki once you have figured it out
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

DerekL

  • I post frequently
  • ***
  • Posts: 132
  • Karma: 1
  • CiviCRM version: 4.5.5
  • CMS version: Drupal 7.34
  • MySQL version: 5.1.54
  • PHP version: 5.2.17
Re: Event Location (loc_block) via API?
March 27, 2012, 01:52:37 am
I hadn't planned on having this be a tussle!

I ended up setting up wamp + netbeans on this machine  to debug just this sucker.

Turns out the function name that api.php was looking for was "civicrm_api3_loc_block_create" NOT "civicrm_api3_locblock_create".

Its sorta mentioned in the link you provided, Xavier : http://wiki.civicrm.org/confluence/display/CRMDOC41/How+to+migrate+or+write+an+api
There's whole set of functions in there that splits camelCase with '_'  then rebuilds it.

I'm currently up against the next error:

Code: [Select]
{
"is_error":1,
"error_message":"Entity not created, missing create or add method for CRM_Core_BAO_LocBlock",
"xdebug":{
"peakMemory":107868752,
"memory":107737928,
"timeIndex":234.95346093178
}
}



xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Event Location (loc_block) via API?
March 27, 2012, 02:08:07 am
Hi,

@DerekL
Damn, you hit one of the "not complete, can't use in a generic way BAOs" ;(
That's one of the issue discussed there.
http://forum.civicrm.org/index.php/topic,23974.msg100896.html#msg100896

btw, would have it be useful to have the name of the function that we are looking for in the civicrm_api as part of the error message?

@eileen,

Should we default (if no add or create)
$dao = new _DAO();
copy attributes
$dao->save();

or better decide if we go add or create and stick it in the CRM_Core_DAO so we know if works ;)

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Event Location (loc_block) via API?
March 27, 2012, 02:13:15 am
Argh - we hit this on pledge payment - where the table name & DAO were mismatched. We got it fixed but it meant that it's hard to backport the latest API onto 4.0 installs now.

Anyway - I think you should call the API Location not loc_block - that's what the BAO is called & it's the capital B which is causing it to look for an underscore in the function name

Re generic functions - last time we discussed it was seen as a security risk
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

DerekL

  • I post frequently
  • ***
  • Posts: 132
  • Karma: 1
  • CiviCRM version: 4.5.5
  • CMS version: Drupal 7.34
  • MySQL version: 5.1.54
  • PHP version: 5.2.17
Re: Event Location (loc_block) via API?
March 27, 2012, 02:38:39 am
I'm flailing here.

I don't quite know how to point locblock create to the Location BAO.

I'm trying something like this :

Code: [Select]
function civicrm_api3_loc_block_create( $params )
{
    return _civicrm_api3_basic_create(CRM_Core_BAO_Location::Create($params));
}

And getting this back:
Code: [Select]
{
"is_error":1,
"error_message":"Entity not created, missing create or add method for Array",
"xdebug":{
"peakMemory":107776848,
"memory":107630256,
"timeIndex":5.9020569324493
}
}

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Event Location (loc_block) via API?
March 27, 2012, 02:46:10 am
Hi Derek,

We are on IRC now, might want to join us and sort that out?

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Event Location (loc_block) via API?
March 27, 2012, 02:47:51 am

    return _civicrm_api3_basic_create('CRM_Core_BAO_Location',($params));
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

jimcraner

  • I’m new here
  • *
  • Posts: 20
  • Karma: 0
Re: Event Location (loc_block) via API?
January 26, 2013, 07:33:47 pm
@DerekL did you ever get this figured out?  Is there a patch or code somewhere?  I'm trying to import Event Locations as well and I'm hitting the inability to do this without the contact_id. 

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Event Location (loc_block) via API?
February 23, 2013, 04:26:04 pm
See http://issues.civicrm.org/jira/browse/CRM-11961
Try asking your question on the new CiviCRM help site.

Erich Schulz

  • I post frequently
  • ***
  • Posts: 142
  • Karma: 5
    • When no-one understands what you are going on about its time to start a blog
  • CiviCRM version: 4.4
  • CMS version: Drupal 7
  • MySQL version: 5.somthing
  • PHP version: 5.3.3
Re: Event Location (loc_block) via API?
March 02, 2015, 01:57:47 am
looks like the solution (for others who like me hit this on a google) now looks like this:

Code: [Select]
$params = array(
  'address_id' => 2,
  'phone_id' => 2,
  'email_id' => 3,
);
$result = civicrm_api3('loc_block', 'create', $params);


Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Event Location (loc_block) via API?

This forum was archived on 2017-11-26.