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) »
  • Changing the Activity API and creating a function to create targets or assignees
Pages: [1] 2

Author Topic: Changing the Activity API and creating a function to create targets or assignees  (Read 2680 times)

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
Changing the Activity API and creating a function to create targets or assignees
October 04, 2010, 07:51:58 am
Just wanted to get your opinions....I am digging into bug CRM-6895 which was reported on the Relationship API, and created a fix for that. But there was also unexpected behaviour on the Activity API: the target_contact_id was gone after an update. And now it turns into a little bowl of spaghetti:
  • the activity_get function did not retrieve any targets or assignees. So I changed that, the get now includes an array targets, containing the contact_ids of the targets, and the same for the assignees
  • next issue is that currently the API only expects one target_contact_id, whilst we have many in CiviCRM
Now this is the point where I can make a fix for the update that merges the retrieved targets/assignees with the parameter targets/assignees whilst also taking care of the situation where only one is entered. But I feel this is then getting kind of messy.
The solution I would prefer is:
  • the activity_create/update is only used for the entity Activity, and only updates or creates fields in that entity (so I remove target and assignee processing from the
    current one)
  • we have additional functions activity_target_create/update and activitiy_assignee_create/update that take care of the entities ActivityTarget and ActivityAssignee
  • we change the documentation to reflect this
To me this is a more structured approach? Let me know what you think and if I am missing anything obvious (and let me tell you I am good at that :-))
Erik
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Changing the Activity API and creating a function to create targets or assignees
October 04, 2010, 12:45:42 pm
Hi Erik,

From a code point of view what you are saying makes sense. From a user of the API point of view it makes sense to be able to pass in that param as an array. However, if the documentation is adequate the user will get past that. Anyone who uses the API will wind up writing wrappers to around things like that (I know I am starting to have a library of wrappers for the API) which starts to raise even more questions....
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

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: Changing the Activity API and creating a function to create targets or assignees
October 04, 2010, 01:46:19 pm
Hi Eileen,
so what you are saying is that from a API user point of view, having one that takes care of all the possibilities would be your preference as you would otherwise be creating wrappers around it?
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Changing the Activity API and creating a function to create targets or assignees
October 04, 2010, 02:23:08 pm
Yeah - I would creating something through an API what achieve the same thing as doing it through a form. Events is another area where I have realised the API does a lot less than I expected (prices sets, profiles) and yes, if the API doesn't do it then I'll basically build it into CiviMigrate which is my wrapper for interacting with the API (CiviMigrate is a plug in for Migrate which takes a View as a source and manages importing it into a Drupal destination - it tracks the import, allows you to do updates & deletes, drush jobs and to specify how many you want to import / source IDs or whatever)
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

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: Changing the Activity API and creating a function to create targets or assignees
October 04, 2010, 02:49:12 pm
I see what you mean. On the other hand, if we are trying to keep the API's as a standardized set of fairly easy maintainable things then having them a little simpler would be a great benefit. For example, if we would split location API into one for location, one for adress, one for phone and one for email I would create a wrapper that would call them all in one go but have a predictable behaviour on the API's. I guess I would prefer that to having one that does a lot but I actually have to get into the code to find out how, why and what?
Erik
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Changing the Activity API and creating a function to create targets or assignees
October 04, 2010, 03:07:10 pm
As always a simple question raises many others about the goal of the API. I have always imagined that ideally it would be able to use the API as a if it were an interface into a black box - with the ability to 'discover' it using an API call & no requirement to know about CiviCRM internals - not necessarily even needing to understand the table structure. Once we break the API down to being effectively an API per table we are saying that people must understand the underlying table structure - which is fine for people like us - since we pretty much do - I don't know if that applies to everyone.

We are almost making a case for bringing back 'add' but as a fully featured wrapper which calls more than one underlying API for the 'significant' objects

Whichever way we go having up-to-date documentation is the key - one reason I'd like to see the 'explain' option we're been talking about.
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

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: Changing the Activity API and creating a function to create targets or assignees
October 04, 2010, 03:13:17 pm
I agree with you on bringing back the add. My point would be that it would not be based on a table but on an entity. In that way the behaviour would be so much more predictable I would have to know less about the CiviCRM internal stuff. For me as a relative newbie to API's my greatest suffering what the inconsistent behaviour, not the understanding the entities. Having predictable behaviour would also mean the documentation is easier to keep up to date. I think we are both trying to achieve the same thing: consistent and predictable API's that mean we do not have to know the details of CiviCRM. Let's see what Xavier has to say about this :-) Apparenty the three of us are on the API team anyway :-)
Erik
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Changing the Activity API and creating a function to create targets or assignees
October 04, 2010, 03:16:36 pm
Yeah - predictability is good. And it's easier to keep up-do-date.

I would note - I'm not actually disagreeing with you - I'm just not sure the best approach at the moment but having to reverse engineer the API just to use it is not where we want to be!
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

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: Changing the Activity API and creating a function to create targets or assignees
October 04, 2010, 03:24:04 pm
It is a tough one.....I will throw some questions on this level on the location API tomorrow when I dig into it. We can then try to get a best approach for that based on the actual issues. I am off to bed now, early morning and English breakfast tomorrow  ;D
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Changing the Activity API and creating a function to create targets or assignees
October 04, 2010, 03:29:36 pm
Glad you're enjoying the delights of pommy-land. Did you get your warm beer?
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

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Changing the Activity API and creating a function to create targets or assignees
October 04, 2010, 11:48:07 pm
Hi,

1) Having to call apis in a specific order to get an "atomic" result is not a good rest api
2) Having zillions of test cases and still not covering all the options of how to populate the params is not a good api

Pick your poison, you can have one of the two it seems ;)

From a user pov of this api, I would find logical to have to call a second api if I want to assign it to a group of contacts. However, if there is only one contact to assign, I would find illogical to have the owner as a regular param, but having to call a second api just to add the assigned.

What about "flatening"  the api, and consider that you can set the assigned contact directly only if there is one:

It takes 0 or 1 assign, if there is one, it replaces the existing one. If you want more, call the specific api

In general, what about that convention? if it's one, (eg one phone, one email..), you can set it from the contact api, if not, use the specific api.

You have covered 80% of the cases in one call, and by leaving out the 20%, we can keep the api code managable?

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

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Changing the Activity API and creating a function to create targets or assignees
October 04, 2010, 11:58:58 pm
Eileen,

Would this have avoided you to create your wrapper apis?

http://forum.civicrm.org/index.php/topic,15769.0.html

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: Changing the Activity API and creating a function to create targets or assignees
October 05, 2010, 12:03:26 am
Probably not because I would still wind up writing a wrapper to pass into that chain since the chain is still pretty complex. I would still write a wrapper converting a single multi-dimensional array into that chain of functions.
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

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: Changing the Activity API and creating a function to create targets or assignees
October 05, 2010, 01:54:32 am
I think it is a good compromise, but what will happen in the following situation:
Currently I have 3 targets on an Activity in the database, entered with the UI. Then the API comes along, and passes one target contact id. What do I do, add one? Update the first one? Report an error back because I do not know which one to update?
Erik
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Changing the Activity API and creating a function to create targets or assignees
October 05, 2010, 02:11:52 am
That's not really disimilar to the location api at all is it?

I had always imagined the address API should work like

phone =array(array('phone_type' =>1, 'phone' => 123,'add'=1),array('phone_type'=>2,'phone'=>234)));

ie add the first phone number in the array but for the second you should only add it if one doesn't already exist.

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

Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Changing the Activity API and creating a function to create targets or assignees

This forum was archived on 2017-11-26.