Skip to Main

Task-oriented walkthrough: Use Template Functions in Your Theme.

All functions are global, loaded on every request. Source: src/Frontend/TemplateFunctions.php (all signatures verified against source). The short huxx_api* names are the recommended forms; the long huxx_connect_* originals are permanent equivalents.

huxx_api()

huxx_api( string $api_id, string $endpoint_id, array $args = array() )

The return type is mixed (documented; the source declares no return type).

Executes a configured endpoint and returns the response.

Parameters

NameTypeDefaultSinceDescription
$api_idstring—0.1.0The API slug id.
$endpoint_idstring—0.1.0The endpoint slug id.
$argsarrayarray()0.1.0Runtime arguments; see below.

$args keys

All optional. Runtime values merge over the saved endpoint configuration; runtime wins.

KeyTypeDefaultSinceDescription
debugboolfalse0.1.0When true, a failure of the actual HTTP request returns the error as an array (see error shape below) instead of an ErrorResponse object. Lookup/configuration failures (unknown API or endpoint id, deactivated API, execution blocked by filter) return ErrorResponse objects regardless of debug. huxx_api_is_error() covers both.
endpoint_variablesarray—0.1.0Values for path variables. Indexed array maps by position to {0}, {1} (or positionally onto named variables); associative array maps by name to {post_id} etc. Values are URL-encoded on substitution.
query_variablesarray—0.1.0Query parameters merged over API- and endpoint-level parameters.
header_variablesarray—0.1.0Headers merged over the configured headers.
body_variablesarray—0.1.0Body parameters merged over the configured body. For multipart endpoints, a value may be a structured array with value, filename, type, is_file to override file metadata; unset fields fall back to the endpoint configuration.
cache`intfalse`endpoint cache duration0.1.0
keys`stringarray`—0.9.0
trigger_typestring'php_function'0.9.0Label stored in the request log for this call (sanitized with sanitize_key()).

The response format (decoded array vs. JSON string vs. raw body) is controlled by the endpoint’s Results Format setting, not by a runtime argument. (The source docblock for huxx_connect_api() advertises a results_format runtime argument, but the executor never reads it — the endpoint setting is the only control.)

Return value

mixed:

  • Decoded array (Results Format PHP Array), string (JSON String / Raw), extracted value(s) when keys is set.
  • HuxxConnectCoreErrorResponse on failure. With debug => true, failures of the actual HTTP request are returned as the error array instead; lookup/configuration failures always return the ErrorResponse object.
  • false when $api_id or $endpoint_id is an empty string (no lookup is attempted).

Example

<?php
$titles = huxx_api( 'demo_api', 'get_products', array(
    'query_variables' => array( 'limit' => 2 ),
    'keys'            => 'products.[].title',
) );
print_r( $titles );

Output:

Array
(
    [0] => Essence Mascara Lash Princess
    [1] => Eyeshadow Palette with Mirror
)

huxx_api_is_error()

huxx_api_is_error( $response ): bool

The $response parameter accepts any value (mixed, documented; the source declares no parameter type).

Returns true when $response is a failure — either an ErrorResponse object or an array whose _huxx_connect_error key is true. Returns false for everything else, including false itself.

NameTypeDescription
$responsemixedAny value returned by huxx_api().

Example

<?php
$data = huxx_api( 'demo_api', 'get_products' );
var_dump( huxx_api_is_error( $data ) );

Output on success:

bool(false)

huxx_api_get_error()

huxx_api_get_error( $response ): ?array

The $response parameter accepts any value (mixed, documented; the source declares no parameter type).

Returns the error details as an array, or null when $response is not an error.

NameTypeDescription
$responsemixedAny value returned by huxx_api().

Error array shape

Matches HuxxConnectCoreErrorResponse::to_array():

KeyTypeDescription
_huxx_connect_errorboolAlways true. Marker key.
codeintHTTP status code, or 0 for transport/configuration errors (408 timeout and 503 connection-refused are mapped from cURL errors).
messagestringHuman-readable message, extracted from common API error fields when available.
original_responsemixedThe raw underlying response or WP_Error, when available.
contextarrayAdditional context such as api_id, endpoint_id, url.

Example

<?php
$data = huxx_api( 'demo_api', 'no_such_endpoint' );
$error = huxx_api_get_error( $data );
echo esc_html( $error['message'] );

Output:

Endpoint "no_such_endpoint" not found for API "demo_api".

Long-form equivalents

Identical behavior, kept permanently for backward compatibility:

Short formLong form
huxx_api()huxx_connect_api()
huxx_api_is_error()huxx_connect_is_error()
huxx_api_get_error()huxx_connect_get_error()
huxx_connect_api( string $api_id, string $endpoint_id, array $args = array() )
huxx_connect_is_error( $response ): bool
huxx_connect_get_error( $response ): ?array

Notes