Serialization#

Request and response models.

APIRequest#

class civicrm_py.APIRequest[source]

Bases: Struct

Base structure for CiviCRM API v4 requests.

select

Fields to return (default: all).

Type:

list[str] | None

where

Filter conditions as list of [field, operator, value].

Type:

list[list[Any]] | None

orderBy

Sort order as dict of field: direction.

Type:

dict[str, str] | None

limit

Maximum number of records to return.

Type:

int | None

offset

Number of records to skip.

Type:

int | None

join

Related entities to join.

Type:

list[list[Any]] | None

groupBy

Fields to group by.

Type:

list[str] | None

having

Having clause for aggregations.

Type:

list[list[Any]] | None

select: list[str] | None
where: list[list[Any]] | None
orderBy: dict[str, str] | None
limit: int | None
offset: int | None
join: list[list[Any]] | None
groupBy: list[str] | None
having: list[list[Any]] | None
values: dict[str, Any] | None
chain: dict[str, Any] | None

APIResponse#

class civicrm_py.APIResponse[source]

Bases: Struct, Generic[T]

CiviCRM API v4 response structure.

values

List of returned entities.

Type:

list[civicrm_py.core.serialization.T] | None

count

Total count of matching records.

Type:

int | None

countFetched

Number of records actually returned.

Type:

int | None

error_code

Error code if request failed.

Type:

int | str | None

error_message

Error message if request failed.

Type:

str | None

values: list[T] | None
count: int | None
countFetched: int | None
error_code: int | str | None
error_message: str | None
property is_error: bool

Check if response indicates an error.

property first: T | None

Get first value from response or None.

APIv3Response#

class civicrm_py.APIv3Response[source]

Bases: Struct

CiviCRM API v3 response structure.

APIv3 reports errors in-band (HTTP 200 with is_error: 1), and values is keyed by entity ID unless the request set sequential: 1.

is_error

1 if the call failed, else 0.

Type:

int

error_message

Error message if the call failed.

Type:

str | None

error_code

Error code if the call failed.

Type:

int | str | None

version

API version (always 3).

Type:

int | None

count

Number of returned records.

Type:

int | None

id

ID of the created/affected record, when there is exactly one.

Type:

int | str | None

values

Records, as an ID-keyed object or (sequential) a list.

Type:

dict[str, Any] | list[Any] | None

is_error: int
error_message: str | None
error_code: int | str | None
version: int | None
count: int | None
id: int | str | None
values: dict[str, Any] | list[Any] | None
property records: list[Any]

Get values as a list regardless of sequential mode.

property first: Any

Get first record or None.