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 for activities?
Pages: [1]

Author Topic: API for activities?  (Read 641 times)

david.a.king

  • I’m new here
  • *
  • Posts: 25
  • Karma: 0
  • CiviCRM version: 3.4.5
  • CMS version: drupal 6.22
  • MySQL version: 5.2
  • PHP version: 5.3
API for activities?
August 19, 2011, 05:44:26 am
Hi, i've been using the api with smarty to try to get a list of a contact's activities - i can get the subject and the activity_type_id with
Code: [Select]
{crmAPI var="ActivityS" entity="Activity" action="get" version="3" contact_id="1" }
and if i use the api explorer i can see that
Code: [Select]
{crmAPI var="ActivityTypeS" entity="ActivityType" action="get" version="3" }will get me a list of the types which correspond to the activity_type_id, but i can't work out how to display the right one - for everything else it's {$Something.field} but the format of ActivityType seems different..

I assume this is reasonably simple but trial and error are getting me nowhere and i don't really know enough about what is happening to search through smarty documentation. any help appreciated! thanks

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: API for activities?
August 19, 2011, 05:51:04 am
Use the api explorer to see the structure (in json in the grey box), probably

{foreach $ActivityTypeS.values ...}

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

david.a.king

  • I’m new here
  • *
  • Posts: 25
  • Karma: 0
  • CiviCRM version: 3.4.5
  • CMS version: drupal 6.22
  • MySQL version: 5.2
  • PHP version: 5.3
Re: API for activities?
August 19, 2011, 06:43:12 am
ok so if i use:

Code: [Select]
{crmAPI var="ActivityTypeS" entity="ActivityType" action="get" version="3" }

{foreach from=$ActivityTypeS.values item=ActivityType}
<li>{$ActivityType}</li>
{/foreach}

that gives me each of the activity types - how do i specify that i only want entry # from the $ActivityTypeS array? so i suppose i don't want "foreach" but rather "for just this one number".. ;)

thanks!

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: API for activities?
August 19, 2011, 12:00:09 pm
Code: [Select]
{crmAPI var="ActivityTypeS" entity="ActivityType" action="get" version="3" id="42" }

If you want only one (not sure I understood you), you can use getsingle instead of get (check out with the exporer.

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

david.a.king

  • I’m new here
  • *
  • Posts: 25
  • Karma: 0
  • CiviCRM version: 3.4.5
  • CMS version: drupal 6.22
  • MySQL version: 5.2
  • PHP version: 5.3
Re: API for activities?
August 19, 2011, 12:37:39 pm
Code: [Select]
{crmAPI var="ActivityTypeS" entity="ActivityType" action="get" version="3" id="42" }
hmm but there is no "id" for ActivityTypeS.. the following returns all of them:

http://drupal.demo.civicrm.org/civicrm/api/doc#/civicrm/ajax/rest?json=1&debug=1&version=3&entity=ActivityType&action=get&id=5

Code: [Select]
{
"is_error":0,
"version":3,
"count":40,
"values":{
"45":"Volunteer Inquiry",
"3":"Email",
"33":"Interview",
"1":"Meeting",
...
"40":"Income and benefits stabilization",
"42":"Long-term housing plan",
"44":"ADC referral"
}
}

what i want:
i can use Activity get to return activities associated with a contact. for each of those i can get the activity_type_id. I can see from the list that the above gives that this activity_type_id matches the relevant activity type (i.e. "5":"Event Registration", ) but i don't know how to actually print that!

My desired result is:
Event Registration: Activity Subject
Event Registration: Activity Subject 2
Meeting: Activity Subject 3
etc

not really sure how getsingle works either, though i see it wouldn't be with smarty anyway.

sorry if i'm still not making sense.
thanks
david

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM (Moderator: Dave Greenberg) »
  • API for activities?

This forum was archived on 2017-11-26.