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) »
  • Custom API Works! Need help with civicrm_api3_create_success()
Pages: [1]

Author Topic: Custom API Works! Need help with civicrm_api3_create_success()  (Read 761 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
Custom API Works! Need help with civicrm_api3_create_success()
October 19, 2011, 03:29:14 pm
I've created a custom api function : civicrm_api3_lookup_event( )

It takes two params:

Code: [Select]
$eventid   = CRM_Utils_Array::value( 'eid', $_GET, $eventid );
$membershipid   = CRM_Utils_Array::value( 'mid', $_GET, $membershipid );

and after a

Code: [Select]
  $dao = CRM_Core_DAO::executeQuery( $query );
I do one of these :
Code: [Select]
while ( $dao->fetch( ) ) {
           // echo $contactList = "$dao->count\n";
            $lookupValues[$eventid]['count']    = $dao->count;
        }

to feed :

Code: [Select]
return civicrm_api3_create_success($lookupValues);
This works, but the response I get is formatted differently than the API examples, or getContactList (which I used as a model).  I get the following as a response to my function:

Code: [Select]
<?xml version="1.0"?>
      <ResultSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <Result>
</Result>
<Result>
</Result>
<Result>
</Result>
<Result>
</Result>
<Result>
    <3>
        <count>3</count>
    </3>
</Result>
</ResultSet>

I'm currently racking my brain trying to figure out where I am hitting the XML fork in the road, or how to properly build the result array...I would really appreciate any pointers!

Thank You!

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: Custom API Works! Need help with civicrm_api3_create_success()
October 19, 2011, 03:52:41 pm
One step closer:

Must pass json : 1 parameter in jquery call.

Now I get :

Code: [Select]
{"is_error":0,"version":3,"count":0,"values":[]}

How to get my $dao data in a format that  civicrm_api3_create_success() will like?

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: Custom API Works! Need help with civicrm_api3_create_success()
October 19, 2011, 04:08:53 pm
And thank the great spaghetti monster for debuggers!

I ended up manually creating a $lookupvalues array and passing it to the create_success function until it looked right.

Code: [Select]
$dao = CRM_Core_DAO::executeQuery( $query );


        while ( $dao->fetch( ) ) {

            $lookupValues[$eventid]  = $dao->count;
        }

   
    return civicrm_api3_create_success($lookupValues,$params, 'Lookup','event',$dao);

Output: Its a simple count of how many people from a given membership_id have registered for a given event_id.

Code: [Select]
{"is_error":0,"version":3,"count":1,"id":3,"values":{"3":"3"}}

Its a leeeeeedol bit redundant right now, but this query will grow.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Custom API Works! Need help with civicrm_api3_create_success()

This forum was archived on 2017-11-26.