0

in my Civicrm 5.31 on Wordpress 5.5 I'm trying to retrieve contribution data via Rest API, using the apiExplorer I get the code:

wp-content/plugins/civicrm/civicrm/extern/rest.php?entity=Contribution&action=get&api_key=userkey&key=sitekey&json={"sequential":1,"return":"contact_id,contribution_source,total_amount,fee_amount,trxn_id,invoice_number","receive_date":{">":"01/01/2021"}}

but if I try to add the display_name it doesn't work. I try: contact_id.display_name and display_name

1

You're in a bit of a tough spot, I'm afraid.

  • The display name is attached to the contact, not the contribution.
  • You would typically use an API join to handle this. However, joining to the Contact entity isn't supported in APIv3. It is supported in APIv4 (and in fact is one of the main reasons behind API4).
  • However, API4 doesn't have a REST interface at present.

So you have two options:

  • Make 2 REST calls;
  • Try to use APIv3 chaining. This will let you make a single REST call, but does NOT reduce the number of API calls made internally. I've always found it to be more trouble than it's worth though, and I shudder to think about what that would look like over REST.
2
  • Now it is more clear and I finally understand why it doesn't work.
    – pk825
    Jan 7 at 20:43
  • It is strange that is I choose some fields it give me these, but if I choose a not existing field it give me more fields with the display_name (it is possible to check it also in the api explorer). I trying the chaing mode, but I have to study because I don't know how it works (the documentation is not showing how to pass a variable to the chain)
    – pk825
    Jan 7 at 20:49

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.