Action
Since 7.1
uncanny-automator
automator_api_call_via_client
Fires when an API call uses the new Api_Client path. Fires when an API call is made through the new Api_Client path, passing call parameters and the response object.
add_action( 'automator_api_call_via_client', $callback, 10, 2 );
Description
Fires after an API call completes successfully using the `ApiClient` path. Developers can use this hook to access and process the `$params` and `$response` objects for logging, further manipulation, or triggering other actions. This hook is part of the core integration for the newer API client.
Usage
add_action( 'automator_api_call_via_client', 'your_function_name', 10, 2 );
Parameters
-
$params(array) - The legacy params array.
-
$response(object) - The Api_Response object.
Examples
/**
* Log the details of an API call made via the new Api_Client path.
*
* This function hooks into the 'automator_api_call_via_client' action
* to log information about API requests that are routed through the
* new client implementation. It records the parameters sent and the
* response received for debugging and auditing purposes.
*
* @param array $params The legacy params array passed to the API call.
* @param object $response The Api_Response object representing the API call's result.
*/
function my_automator_log_api_call_details( $params, $response ) {
// Ensure WordPress is loaded and we are in a context where logging is appropriate.
if ( ! did_action( 'plugins_loaded' ) ) {
return;
}
// Log the parameters and response if they exist.
if ( ! empty( $params ) ) {
error_log( 'Automator API Call via Client - Params: ' . print_r( $params, true ) );
}
if ( ! empty( $response ) && is_object( $response ) ) {
error_log( 'Automator API Call via Client - Response Status: ' . $response->get_status() );
// You might want to log more details from the response object depending on its structure.
// For example, if $response has a get_data() method:
// error_log( 'Automator API Call via Client - Response Data: ' . print_r( $response->get_data(), true ) );
}
}
add_action( 'automator_api_call_via_client', 'my_automator_log_api_call_details', 10, 2 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/core/lib/app-integrations/abstract-api-caller.php:294
* Fires when an API call uses the new Api_Client path.
*
* @since 7.1
*
* @param array $params The legacy params array.
* @param object $response The Api_Response object.
*/
do_action( 'automator_api_call_via_client', $params, $response );
return $response->to_legacy_array();
}
// Legacy path — will be removed when all integrations use the new client.
return Api_Server::api_call( $params );
}