Sunday, April 19, 2026
CiviCRM

APIv4 Query Builder

Build CiviCRM APIv4 calls with correct entity, action, and parameter syntax.

Configuration
Comma-separated field names. Leave blank to return all fields.
Generated API v4 Code
// Configure options on the left to generate CiviCRM APIv4 code

CiviCRM APIv4 Query Builder — How to Use

The CiviCRM APIv4 Query Builder helps developers construct accurate API calls for CiviCRM's modern APIv4 layer without needing to memorize syntax. Select your entity (Contact, Contribution, Event, etc.), choose an action (get, create, update, delete), define WHERE conditions to filter results, and pick which fields to return. The tool instantly generates ready-to-use code in three formats: PHP, REST URL, and JavaScript.

CiviCRM's APIv4 replaces the older APIv3 with a cleaner, object-oriented PHP interface and a more consistent query model. Many developers waste time debugging malformed API calls or looking up entity field names. This tool eliminates that friction by generating correct syntax every time.

Who Needs This Tool

CiviCRM extension developers, site administrators writing custom reports, and consultants migrating data between installations all rely on CiviCRM's API. Whether you're pulling a list of active memberships, creating contribution records programmatically, or syncing contacts with an external system, APIv4 is the right approach. This builder supports all major entities including Contact, Activity, Contribution, Event, Participant, Membership, Group, Relationship, Tag, Case, and more.

Understanding the Three Output Formats

  • PHP — Use in CiviCRM extensions, hooks, or standalone PHP scripts using the \Civi\Api4 namespace. Supports the full fluent interface with addSelect(), addWhere(), addOrderBy(), and execute().
  • REST URL — Useful for external integrations, Zapier webhooks, or testing in the browser. Send GET requests to /civicrm/ajax/api4/{Entity}/{action} with JSON-encoded params.
  • JavaScript (CRM.api4) — Used in CiviCRM's Shoreditch UI, Angular extensions, or custom JavaScript on CiviCRM pages. Returns a Promise-based response.

Common CiviCRM APIv4 Pain Points Solved

  • Forgetting to add (TRUE) for checkPermissions when calling get() in a secure context.
  • Mixing up field names between APIv3 and APIv4 (e.g., display_name vs sort_name).
  • Incorrectly formatting WHERE conditions as nested arrays instead of using addWhere().
  • Not setting a Limit, which causes performance issues on large datasets.