2

On CiviCRM 4.6.11. I need to get the source field of a contribution, but the api seems to fail. Testing the API on http://xxx//civicrm/api#explorer with entries giving the following PHP code :

$result = civicrm_api3('Contribution', 'get', array(
  'sequential' => 1,
  'return' => "source",
  'contact_id' => 4889,
));

gives as results :

{
    "is_error": 0,
    "version": 3,
    "count": 1,
    "id": 4676,
    "values": [
        {
            "contact_id": "4889",
            "contribution_id": "4676",
            "id": "4676"
        }
    ]
}

Although the contribution DO HAVE a source value, no source entry in the result. Is-it a knonw bug, or what wrong in the trequest ?

Thanks for help.

Jean-Pierre

  • Did you ever manage to work out how to return the source value? I'm having exactly the same problem. – Rich Smith Nov 30 '16 at 9:26
2

There is an issue with the contribution 'source' field being accessed through the API, due to there being a conflict between the 'source' field of a contribution and the 'source' field of a contact.

To get around this conflict, add the prefix 'contribution_'. So in the API call, change 'source' to 'contribution_source':

$result = civicrm_api3('Contribution', 'get', array(
  'sequential' => 1,
  'return' => "source",
  'id' => 1,
));

...becomes...

$result = civicrm_api3('Contribution', 'get', array(
  'sequential' => 1,
  'return' => "contribution_source",
  'id' => 1,
));

This worked for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.