Hot answers tagged

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
  • 11.4k
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 ...
  • 16.3k
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
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....
  • 18.8k
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.
  • 18.8k
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 ...
  • 3,688
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"}], ...
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 ...
  • 11.4k
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 ...
  • 1,139
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, '...
  • 11.4k
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 ...
  • 429
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?
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.
  • 35
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, ...
  • 18.8k
1 vote

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 ...
1 vote
Accepted

How to remove APIv4 extension

I would delete the extension folder from the extension directory. You may need to run the below query to delete the entry from the extension table or sometimes it should delete automatically when you ...
1 vote
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 ...
  • 18.8k
1 vote
Accepted

Using API4 to get contact based on email match

Unless you have a complex join, it's simply a matter of referencing contact_id (the literal string prefix contact_id., not a numeric contact id) in the select() or where() to create the join, e.g. $x =...
  • 18.8k
1 vote
Accepted

Is acl entity role available in Api4 explorer?

Works for me on CiviCRM 5.46. Are you using an older version of CiviCRM?
1 vote
Accepted

Group of unsolvable API and core errors

Turns out ot was a php function call outside class methods in an old extension which used to work before but now caused this weird behaviour.
  • 1,272
1 vote

How to see the SQL generated by Api4 calls?

You can do this via code by adding ->setDebug(TRUE) as a parametr to your call. Then, when you get the results (e.g. $results) examine $results['debug']['sql'][0].
  • 1,174
1 vote
Accepted

API V4 - Uncaught Exception: Authorization failed

The checkPermissions line should be outside the values array. You can use http://{your-site}/civicrm/api4 to use the explorer to construct the correct code. civicrm_api4('Contact', 'create', [ ...
  • 18.8k
1 vote

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

Following up on the EntityBridge part of the question, this is now documented in the APIv4 section of the developer guide. The fields of the EntityBridge are effectively merged into the main entity. ...
  • 11.4k
1 vote

Validating options in API4?

APIv3 does option-matching by default. APIv4 only does option-matching if you ask it to. The way to do that is by specifying what property of the option you are passing in. Typically :name for the ...
  • 16.3k
1 vote

Use complete address and full county name in mailings

This doesn't fix the larger issue (see e.g. https://lab.civicrm.org/dev/core/-/issues/1709) but you can update your database to put the full name in the abbreviation field: alter table ...
  • 18.8k
1 vote

Use complete address and full county name in mailings

It should be like below // Not returning anything, the tags are not interpreted at all // function mailhooks_civicrm_tokenValues( &$values, &$contactIDs ) { foreach($contactIDs as $id){ $...

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