Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more
4 votes

How to see the SQL generated by Api4 calls?

Alternatively ... fire up api4 explorer and prepare your query. Make sure to ✔ the debug option execute the query click the 'Debug' tab next to the 'Result' tab
Aidan's user avatar
  • 13.5k
4 votes
Accepted

Finding contacts without relationships (API)

Yes you can! I fiddled with the APIv4 Explorer a bit and came up with this: The trick is to join onto RelationshipCache with the relationship type(s) you are wanting to exclude (note that the double ...
Coleman's user avatar
  • 18.7k
4 votes
Accepted

Do strings used in API version 4 need to be escaped?

Yes, all strings will be escaped automatically by the CiviCRM code.
Pradeep Nayak's user avatar
3 votes
Accepted

Delete On_Hold emails and reassign Primary Email

Civi will set another address as Primary if you use its tools to delete but it can't do that if you rip data out from under its feet. Deleting things directly from the database is usually a bad idea! ...
Aidan's user avatar
  • 13.5k
3 votes
Accepted

Recurring Contributions count not match: "Find Contributions" vs API4 Contribution::get

Can you also add same filters in api4 as Find Contribution is_template = 0 contribution_status_id = Completed
Pradeep Nayak's user avatar
3 votes
Accepted

Is the use of API4 already recommended?

See https://lab.civicrm.org/dev/core/-/issues/2486 but I believe all of those things are deprecated anyway (or on the way to being deprecated) and the idea is to use Order and Payment: https://docs....
Demerit's user avatar
  • 23.1k
3 votes
Accepted

API4 PHP Fatal error Uncaught API_Exception Authorization failed

Because you're using a manual way to bootstrap civi (as opposed to e.g. running your script with cv scr --user=admin), you need to either add code in there to also "log in" as a user, or you ...
Demerit's user avatar
  • 23.1k
3 votes

api4: get(FALSE) vs get()->setCheckPermissions(FALSE): which is preferred?

Core tends to use the short form but both are equally valid. The short form was introduced later just because it comes up so often that you want to set it to false.
Demerit's user avatar
  • 23.1k
3 votes
Accepted

Invalid field 'contact_id.is_deceased' Apiv4

That backtrace seems to point to this change as the culprit, however after several attempts I've been unable to reproduce that error. We can continue discussion on this issue: https://lab.civicrm.org/...
Coleman's user avatar
  • 18.7k
3 votes

Creating extensions for custom tables

It sounds like what you are asking about are Custom Field Groups. A Custom Field Group is generally not accessible from the API as an entity. Instead, you access the Custom Fields within the Custom ...
Lars SG's user avatar
  • 4,073
3 votes

Api get all option within sub entity

The best way to learn how to use the API is the Api Explorer which is built into CiviCRM (find it in the Support -> Developer menu. It will write the following code for you: $optionValues = \Civi\...
Pradeep Nayak's user avatar
3 votes
Accepted

Retrieving Contact information with API4 Inside the module

Try changing \Civi\Api4\Contact::get(TRUE) to \Civi\Api4\Contact::get(FALSE) The TRUE/FALSE parameter is a short-hand for checkPermissions. The default in Api4 is that permissions are checked but you ...
Aidan's user avatar
  • 13.5k
3 votes
Accepted

Can rename(AS) a column/field from SELECT using APIv4

There was a long discussion about this at https://lab.civicrm.org/dev/core/-/issues/3738 which resulted in a new $result->rekey() method added to the next beta (5.74). See https://github.com/...
Coleman's user avatar
  • 18.7k
2 votes

How to see the SQL generated by Api4 calls?

You can do this from the API explorer if you use your browser's dev tools. fire up api4 explorer and prepare your query. Make sure to ✔ the debug option, and un-✔ the check permissions box. open your ...
artfulrobot's user avatar
  • 3,932
2 votes
Accepted

Best (api4) way to chain save a contact so that the email updates, without creating a new one?

I got what I needed by including the email id ("id":2) in the records chain property: crmApi4('Contact', 'save', { records: [{"id":2, "first_name":"Mike"}], ...
MikeSteigerwald's user avatar
2 votes
Accepted

How to get Target Contacts from Api4 Activity.get call?

For joining explicitly by adding an ActivityContact join then a Contact join instead of just a Contact join with "Using ActivityContact" in the explorer, I think it's just the Contact join ...
Aidan's user avatar
  • 13.5k
2 votes

Searchkit Buttons not working

Problem a result of using Shoreditch as Civi theme. Same problem exhibited when using API Explorer UI. SearchKit and API Explorer both use bootstrap theme which seems to have conflict with ...
Dave T's user avatar
  • 1,239
2 votes
Accepted

Make API queries - two methods failing

For your cv call either turn off the permission check or specify a user to run with. So either: <?php $result = civicrm_api4('Contact', 'get', [ 'checkPermissions' => FALSE, '...
Aidan's user avatar
  • 13.5k
2 votes

Using API4 to get contact based on email match

So @Demerit's answer above was exactly what I needed to understand how to connect the two tables together (email table and contact info table). I am posting my answer for other noobs that are trying ...
jsherk's user avatar
  • 583
2 votes

Odd REST API result

Can you try with a LIKE 'CLC' rather than '='? This might help as the contact_sub_types are stored with the weird CRM_Core_DAO::VALUE_SEPARATOR around the values?
ErikH - CiviCooP's user avatar
2 votes

How to get Price Sets related to a Contribution Page using API 4

Unfortunately, there isn't a way to get the price set used for the contribution or event page. The link is stored in civicrm_price_set_entity, with entity_table set as civicrm_contribution_page or ...
Pradeep Nayak's user avatar
2 votes

APIv4 Base URL for external applications

How about http://192.168.100.168:8166/?civiwp=CiviCRM&q=civicrm/ajax/api4/Relationship/get You can check the REST tab in API4 explorer for correct url
Pradeep Nayak's user avatar
2 votes
Accepted

Get uploaded file full URL via API v4

With the help of Lars SG's links. I created a, PHP 8, helper function to get a URL based on a file ID provided by the API. function se_45209_get_entity_image_url( int $entity_id, int $file_id ): ...
Michael Bragg's user avatar
2 votes
Accepted

Use Order API or use APIv4?

The advice to use Order API is still sound and should be followed. As of this post it has not yet been ported to APIv4 so you'll have to use v3 until that work is complete. Progress on the port can be ...
Coleman's user avatar
  • 18.7k
2 votes

Get Phone or Email with API4 not possible?

This looks like a 2-parter so I'll just answer your first question about how to fetch all emails & phones for a contact. Please start a new post for your curl question. APIv4 does fetch all fields ...
Coleman's user avatar
  • 18.7k
2 votes

civicrm_api4: How do I create a Contact with Tags (EntityTag)?

Apply this patch Jeremy -> this is fixed in the D10 version of CiviCRM Entity, but the D9 version requires this backport by Pradeep: root@46c1218044c0:/var/www/drupal/web/sites/default/modules/...
KarinG - Semper IT's user avatar
1 vote
Accepted

retrieve event registration link with api v4

There isn't any option in the API to generate registration link, the code you are using should create the correct link $id = $event['id']; $reglink = CRM_Utils_System::url('civicrm/event/register', &...
Pradeep Nayak's user avatar
1 vote

How to leverage Authentication Guard for APIv4 calls

While the documentation can be confusing, I wouldn't say it's lacking. I want to make sure you found this particular page, particularly the "Guards" section. In APIv3, you use a site key ...
Jon G - Megaphone Tech's user avatar
1 vote

Php Standalone Skript doesnt Query Database, APIv4 Simple Example

In Combination out of Demerits posts i can solve the problem via cv scr --user=some_wordpress_username skriptname.php Thanks for the support.
gzwg's user avatar
  • 37
1 vote
Accepted

Php Standalone Skript doesnt Query Database, APIv4 Simple Example

I wouldn't do it that way. I'd remove those first two lines and install cv - if you are using buildkit you already have it - and then run it with cv scr myscript.php. That way it runs on all cmses, ...
Demerit's user avatar
  • 23.1k

Only top scored, non community-wiki answers of a minimum length are eligible