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) »
  • How do I specify date parameters in API calls?
Pages: [1]

Author Topic: How do I specify date parameters in API calls?  (Read 514 times)

denishow

  • I’m new here
  • *
  • Posts: 19
  • Karma: 2
  • CiviCRM version: 4.2
  • CMS version: WordPress 3.4.2
  • MySQL version: 5.4
  • PHP version: 5.3.15
How do I specify date parameters in API calls?
October 03, 2012, 05:37:34 am
Hi,

I've sorry, I've only been developing using CiviCRM for a couple of weeks but am stuck on how to specify a date parameter in an API call. I want to see if there's an existing contribution from a contact of a specific type and amount and date, but if I specify the date, I get a "Fatal error".

In the API Explorer if I try calling this:

$results=civicrm_api("Contribution","get",
  array (version => '3',
    'page' =>'CiviCRM',
    'q' =>'civicrm/ajax/rest',
    'sequential' =>'1',
    'contact_id' =>'29',
    'contribution_type_id' =>'2',
    'receive_date' =>'2011-05-23'));

I get this back:

{
   "is_error":1,
   "error_message":"A fatal error was triggered",
   "trace":"#0/CRM\/Utils\/Type.php(221): CRM_Core_Error::fatal('Cannot recogniz...')\n
[etc.]
}

I've tried the same in PHP giving the API an actual DateTime object with the same problem.

I'd be happy saying "return me all the transactions with this amount any time on this date" if that's a better way.

Any tips gratefully received.
Thanks

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: How do I specify date parameters in API calls?
October 03, 2012, 07:12:06 am

can u try with:

'receive_date' =>'20110523'

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: How do I specify date parameters in API calls?
October 07, 2012, 06:05:55 pm
By the time the api wrapper has passed your date through to the underlying function the date should be in the format '20110523000000' as long as you have provided a strtotime parsable time string - so changing what you pass in might not help.

The rest of the backtrace would though.
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]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • How do I specify date parameters in API calls?

This forum was archived on 2017-11-26.